1 / 22

Memory Management

Memory Management. Exercise. At this point, J4 arrives requiring a block of 100K. Can J4 accommodated? Why or why not? If relocation is used, what are the contents of the relocation register for J1, J2, and J3 after compaction?

wenzel
Download Presentation

Memory Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Memory Management

  2. Exercise • At this point, J4 arrives requiring a block of 100K. • Can J4 accommodated? Why or why not? • If relocation is used, what are the contents of the relocation register for J1, J2, and J3 after compaction? • What are the contents of the relocation register for J4 after it has been loaded into memory? • The instruction ADDI 4, 10 is part for J1 and was originally loaded into memory location 22K. What is its new location after compaction? • The instruction Mull 4, number is part for J2 and was originally loaded into memory location 55K. What is its new location after compaction? 20K 30K 50K 65K 75K 120K 200K

  3. MM: Recent Systems • In earliest MM systems, contiguous memory blocks are needed to load the entire job. • The disadvantage will be eliminated in this chapter. • Paged memory allocation. • Demand paging memory allocation. • Segmented memory allocation. • Segmented/demand paged allocation.

  4. Paged Memory Allocation • Each job is divided into pages of equal size. • Disks are divided to sectors. • Memory is divided to page frames. • Page size = Sector size = Frame size • This means, one sector will hold one page of a job which fits into one frame of memory.

  5. Paged Memory Allocation • To execute a program: • Determining the number of program pages. • Locating enough memory frames in memory. • Loading ALL of the pages into frames. • Pages do not have to be loaded in adjacent memory blocks. i.e., each page can be stored in any available frame anywhere in memory.

  6. Paged Memory Allocation • Advantages: • Memory is used more efficiently (any frame can be used by any page of any job). • Compaction process is eliminated because there is no external fragmentation between page frame. • Disadvantages: • MM needs to keep track of frames, this will add more complexity to the OS. • Internal fragmentation is still a problem (but only in the last page of a job).

  7. Example Frame no. 0 Page 0 1 2 Page 1 3 4 Page 2 5 6 Page 3 7 8 Job1 9 10 11 Main memory

  8. Paged memory allocation • How the MM keeps track of frames? • MM uses 3 tables: • Job Table (JT). • Page Map Table (PMT). • Memory Map Table (MMT). • JT: contains the size of each job and the location of the PMT of that job. • PMT: contains the page number and the corresponding frame address. • MMT: contains the location of each memory frame and its free/busy status.

  9. Example Frame no. 0 1 2 3 4 JT 5 6 7 8 9 MMT 10 PMT 11 Main memory

  10. Paged memory allocation PAGE 0 • How to determine the location of a certain line? • Calculate the page #. • Calculate the displacement (offset) of the line. • The offset can be defined as how far a line is from the beginning of its page. PAGE 1 PAGE 2

  11. Paged memory allocation • To find the address of a given line: • The line number is divided by the page size. • Keeping the remainder as an integer. • The resulting quotient is the page number. • The remainder is the displacement in that page. • Ex: If you know that the page size is 100, find the location of line 523. • Solution: 523/100 = 5(quotient), 23(remainder). Then the line is located in page number 5 and 23 lines away from the beginning of that page.

  12. Paged memory allocation • This algorithm needs to be extended to find the exact location of the line in main memory. • This can be achieved by knowing the frame number that is corresponding to the requested page number via the PMT. • To know the beginning address of the frame in memory, the frame number is multiplied by the frame size.

  13. EX: Given that, the page size is 512 bytes, find the exact location in memory of line 518. • Solution: 518/512= 1 (page #), 6 (offset). From the table, frame# = 3 Starting address of frame3 = 3 * 512 = 1536 The exact address of line 518 in memory = 1536 + 6 = 1542 PMT

  14. Page # Frame size Offset Frame starting address Frame # Physical address PMT Address resolution process The process of translating the job address into its physical address in called address resolution.

  15. Advantages & Disadvantages • Advantages: • Jobs are allocated in noncontiguous memory locations. • More efficient use of memory, more jobs can fit in it. • Compaction process is eliminated. • Disadvantages: • Overhead is increased due to address resolution. • Internal fragmentation is still a problem (in last page only).

  16. Demand Paging • Jobs are still divided into pages. • Only a part of the program can be loaded into memory for processing. • Pages are brought into memory only as they are needed. • Virtual memory is used. • The process of moving pages from secondary storage to memory or to the opposite direction is called “page swapping”

  17. Demand Paging • Same tables (JT, PMT, MMT) are used. • 3 new fields in PMT: • Is page in memory? (show where is the page) • Is it Modified? (rewriting the page or not) • Is the page referenced recently? (active or inactive page)

  18. Example Status (valid - invalid) Modified Referenced Job1 Job1 PMT Job2 Job2 PMT

  19. Page Interrupt Handler • If a page is requested from the secondary storage: • The page interrupt handler determines if there are enough empty frames in memory. • If all frames are busy, the page interrupt handler decides which page will be swapped out (depends on the used page removal policy).

  20. After Swapping, three tables must be updated: • The PMT for the swapped out job. • The PMT for the swapped in job. • The MMT. • A failure to find a page in memory is often called a PAGE FAULT.

  21. Thrashing Problem • The phenomenon when there is an excessive amount of page swapping back and forth between main memory and secondary storage is called THRASHING. • Thrashing is caused when a page is removed from memory but is called back shortly.

  22. Example • Suppose there is only one empty frame in memory. Do I = 1, 100 K = I * I Page 0 M = A * I Write I, M End Do Page 1 100 page faults will happen

More Related