Segmentation

An alternative approach to virtual memory is the use of segmentation. The biggest disadvantage of paging is that all the pages are the same size. If the page size is large this can lead to a waste of (physical) memory, as small process may not use a complete page. However, if page sizes are small, then we will need a large number of pages which may need to be swapped in and out frequently.

Segmentation allows memory to be divided up into variable sized blocks. The amount of memory required by a process is defined by the programmer when it is written and this is the size of the segment which will be allocated to the process by the MMU when it runs. Details of the segments allocated to various processes are stored in a segment table.

However, there is still a possibility that there is insufficient memory available to load a segment. This can be overcome by a combination of segmentation and paging, whereby each variable-length segment is composed of a number of fixed-length pages and has its own page table.

Segments are also used to implement protection schemes. The segment table contains details of the memory allocated to each program, so when a program tries to access a memory location, the MMU can check that it is within the allocated space before allowing it to do so. Each entry in the segment table contains protection bits, indicating whether that segment can be read or written to by other processes. This allows for the sharing of data between processes

You can find out everything you ever wanted to know about memory management at: http://www.memorymanagement.org.  The “Beginner’s Guide” is particularly useful.

Next: The Kernel