Chapter 3 • Memory Management II • In this chapter we continue our study of memory management techniques.
I. Paged Memory Allocation • this technique still requires the entire program to load into memory, • but, not into contiguous memory. • secondary storage and primary memory are divided into equal size units • these are called page frames , for example, 512 bytes per page frame
Paged Memory Allocation, continued • The Jobs to be executed are divided into the same sized units called pages • the operating system loads pages of a job into free page frames in memory
Paged Memory Allocation, continued • to keep track of what's where the operating system uses tables: • The PMT= Page Memory Table lists ]ocation of each page of a job • i.e. each job has a PMT which tells what page frames its pages occupy
Paged Memory Allocation, continued • The Job Table lists each job and location of its Page Memory Table • The Memory Map Table lists every memory page frame and its status • i.e. free or busy.
How the OS locates a page: • To find any particular location within a program: • the operating system must use an address reference to compute a page number and offset
For Example, consider this instruction Load x, 0214 • (This is an instuction which says load the contents of register X into memory location 0214.)
Suppose one page = 100 bytes 214 div100 = 2 214 mod 100 = 14 • The operating system then consults the Page Memory Table to see which physical page frame page 2 is loaded at.
Thus, the desired location is at location 14 relative to the beginning of that page. • Suppose, for example, page 2 is loaded at page frame 5 in memory. 5 x 100 + 14 will be the location
Internal fragmentation is still a problem but only on the last page of a job. • tasks are often subdivided at physical subdivisions which don't correspond to any logical program subdivisions.
II. Demand Paging • A newer variation of paging is “demand paging” which no longer requires all pages of a job to be loaded into memory at execution. • Demand Paging facilitated development of Virtual Memory
Jobs are still divided into equal sized pages, • consequently, one logical module of a job may often cover one or more pages.
Demand Paging continued • In Demand Paging the operating system keeps same tables except that three new fields are added to PMT: • a "page in memory” Boolean field • a "contents modified” Boolean field
Demand Paging continued • a “referenced recently” Boolean field or • this may be a time-stamp field if a Boolean field is set to "t" when page is accessed - • Look at figure 3.5, p54
As a job processes ……... • if a location is referenced the operating system needs to determine its page # • and it must check the Page Memory Table to see if that page is resident, • i.e., loaded in some page frame.
If the page is resident then, OK, otherwise the needed page must be loaded into memory. • This implies "swapping” the page into an availab]e page frame.
If none are available it must swap one out using some algorithm to decide which. • This is known as a "page fault" and • dealing with it is the responsibility of the Page Interrupt Handler.
As the page swap is done the operating system must update its tables, • i.e.. Update the PMT for both affected pages and Memory Map Table.
Thrashing • Frequent page swapping is called " Thrashing" . • This is a very poor use of processor's Time. • See figure 3.6 Pg. 56
III. Page Replacement Policies • Page Replacement Policies have been studied extensively. Several in common use: • Longest Time Resident is a "first in first out" (FIFO) policy in which • resident pages are tracked by a queue arranged by residency time.
Least Recently Used is another FIFO po]icy in which • pages are tracked by a queue arranged by the time a page was last accessed.
Most Recently Used • a LIFO policy which, as its name suggests, • results in the operating system swapping the page most recently accessed,
Least Frequently Used • a policy which is often very effective. • The queue is arranged by frequency of use • See Tables 3.3, 3.4, 3.5 Pages 58 - 61.
IV. The Working Set Concept • As a job processes often it uses a certain set of its pages most often. • If there is enough room in memory the OS tries to keep this "working set" of pages resident • thus page faults are minimal and swapping for this job is greatly reduced.
V. Segmented Memory Allocation • This method is somewhat like paging, but the units are not all of same size. • This method is based on idea that a structured program consists of (semi) independent modules which may be of varying sizes.
Memory is not divided into pages as before, rather, • The operating system allocates memory in various segment sizes dynamically, as needed. • Like demand paging, jobs are not required to load totally or into contiguous memory.
As a job is compiled or assembled code segments are created and numbered sequentially. • The operating system still keeps a Job Table and Memory Map table, but • It now keeps a segment table...
The Segment Table for each job contains • segment numbers, • segment sizes, • memory load address, and • fields for "segment recently referenced" and "access rights", • (see figures p65).
each segment is indivisible but • not all are loaded at once or in contiguous memory.
As with the Dynamic Partition method • External Fragmentation can be a problem so periodic Compaction is needed. • There is no internal fragmentation since segment size is dynamic.
VI. Segmented/Demand Paging • This method combines the ideas of the last two. • It tries to reduce external fragmentation by subdividing segments into pages. • In this methcd jobs are divided into segments but • pages and page frames also exist.
When a segment is loaded all of its pages load into memory • but not necessarily contiguously.
the operating system uses Four Tables to manage all of this information: • a Job Table, • a Memory Map Table, • a Segment Map Table for each job and • a Page Map Table for each segment. (pages of a segment are not necessarily contiguous) • See figure 3.11, page 68.
This method manages memory efficiently, but it has a lot of overhead. • It eliminates external fragmentation and most internal fragmentation.
VI. Virtual Memory Management • Invented by IBM, • this technique evolved from the technique of Demand Paging
Virtual Memory Management gives users the impression that their jobs are loading totally and • that memory is virtually unlimited.
Before Virtual Memory programmers often worked hard to squeeze code into precious memory • Programmers developed an overlay technique in which some sections of code would replace others.
Virtual Memory works very well in multitasking environments. • It takes advantage of speed disparity between processor and users. • Entire jobs are sometimes swapped out between execution slices! • See pp. 71, 72 for other adventages.