Segmentation
- divide processes' data into logical units, each called a segment
- better for error checking because all the data in one segment is of the same type
- e.g. instructions - cannot be changed (read-only)
- e.g. array (not in UNIX, but in VAX) - checking bounds on an array[ 1 ... 100 ]
- make a segment large enough to hold exactly 100 entries
- then an array reference of array[101] gives a segmentation fault
- internal fragmentation - none - each segment can be defined to be the proper size
e.g. word address segment boundary, say divide by 256
- external fragmentation can be a serious problem
- table overhead and transportation costs are similar to paging
Stage 2 - want B2 in main memory
remove A1 to fit B2
now have 400 kb for B2, but not contiguous
so now remove A2 as well, but still no room for B2
choice: remove B1, then we can put in B2, or
compaction: move all the free space to the end, or used space to the beginning
Segmentation Placement
placement: where to locate (place) a segment
- best fit: smallest hole (contiguous space) the segment can fit in
- first fit: first hole (contiguous space) the segment can fit in
- worst fit: largest hole (contiguous space) the segment can fit in
- this idea is perhaps good, but simulation experiments show
that after a while, it tends to eliminate all large holes and only
be able to satisfy requests for small holes
List of Free Spaces (free list)
- contains a starting address and a size managed as a linked list
- sort by address for first fit
- so you can later combine adjacent holes together easily
to form larger holes
- sort by size for best fit and worst fit
- disadvantage of best fit: many small spaces
- advantage of best fit: minimal external fragmentation
- advantages of first fit: quite fast, good for recombining holes
- disadvantage of first fit: small holes tend to accumulate at the beginning of memory
because each time you go until you find the first ``large enough'' hole
- first fit with a roving pointer, start search from where we left off
-
even better than first fit
-
faster
-
holes aren't accumulated at beginning
- best utilization of memory because of the few small spaces externally
Other points:
- initialization for segmentation is easy - one big segment equal in size to all of
unused physical memory
- when the free list gets long, perform compaction
Replacement
- replacement: which segment to choose for removal when there is inadequate space available
- compaction is an alternative action (no disk operations and relatively fast)
- segment of a terminated process
- segment of a blocked process
- segment of a ready process
- could design LRU, FIFO, NRU, etc. algorithms
paging is the winning approach, wastes little space with little management overhead
- paged segmentation is most common in current Operating Systems
- first divide process into relatively large segments -- read/write/etc
- now divide segments into pages
- wastes part of a page at the end of every segment
- acts like a paging algorithm
Table of Contents