Presentation is loading. Please wait.

Presentation is loading. Please wait.

MSJ-1 Relocation of an Admitted Process Requires Execution Time Binding memory management unit (MMU) main memory LA PA + + base address CPU The problem.

Similar presentations


Presentation on theme: "MSJ-1 Relocation of an Admitted Process Requires Execution Time Binding memory management unit (MMU) main memory LA PA + + base address CPU The problem."— Presentation transcript:

1 MSJ-1 Relocation of an Admitted Process Requires Execution Time Binding memory management unit (MMU) main memory LA PA + + base address CPU The problem with contiguous memory management, of course, is external fragmentation, whose severity can be delayed by various means but cant ultimately be fixed without compaction – unless you consider rebooting the system to be an acceptable fix, which most users and OS designers dont And compaction: 1. Is time consuming 2. Requires the execution time relocation of already loaded processes, which means that load time binding is out, the hardware will have to have an MMU capable of execution time binding The problem with contiguous memory management, of course, is external fragmentation, whose severity can be delayed by various means but cant ultimately be fixed without compaction – unless you consider rebooting the system to be an acceptable fix, which most users and OS designers dont And compaction: 1. Is time consuming 2. Requires the execution time relocation of already loaded processes, which means that load time binding is out, the hardware will have to have an MMU capable of execution time binding The second problem – an MMU that does execution time binding of a contiguous process – is not all that difficult or expensive to solve: All thats necessary is a single base (or relocation) register in an MMU so that for the running process, every logical address emitted by the CPU is added to the base register to produce a physical address But the time involved in moving everybody around to compact the holes/fragments remains an issue for real- time systems The second problem – an MMU that does execution time binding of a contiguous process – is not all that difficult or expensive to solve: All thats necessary is a single base (or relocation) register in an MMU so that for the running process, every logical address emitted by the CPU is added to the base register to produce a physical address But the time involved in moving everybody around to compact the holes/fragments remains an issue for real- time systems The Base Address Register, sometimes known, for obvious reasons, as the Relocation Register, is part of the context of the running process

2 MSJ-2 A Limit Register is Usually Added to Provide Increased Security memory management unit (MMU) main memory LA PA + + base address LA < limit ? size limit yes no address violation trap A limit register, containing the size limit established when the process is admitted, can be used to prevent a process from accessing memory beyond its limit CPU

3 MSJ-3 Roadmap Contiguous memory management and its limitations Paged memory management Motivation and overview Binding, the page table, and the MMU Segmented memory management Motivation and overview The segment table

4 MSJ-4 Pages are real enough, the loader does indeed chop the load modules logical address space up into pages as it loads it from disk into memory Frames are a fiction, however, merely a consequence of the way the OS allocates physical memory – the memory itself knows nothing about frames and there are no changes to the memory hardware itself The loader just makes sure that whenever it loads a page, it loads it starting at a base address that is some multiple of the page/frame size i.e., the base address of frame #k is k * f, where f is the page/frame size, so the frame number is in fact nothing more than the most significant bits of its base address Pages are real enough, the loader does indeed chop the load modules logical address space up into pages as it loads it from disk into memory Frames are a fiction, however, merely a consequence of the way the OS allocates physical memory – the memory itself knows nothing about frames and there are no changes to the memory hardware itself The loader just makes sure that whenever it loads a page, it loads it starting at a base address that is some multiple of the page/frame size i.e., the base address of frame #k is k * f, where f is the page/frame size, so the frame number is in fact nothing more than the most significant bits of its base address Introduction to Paged Memory Management main memory page0 page1 page2 page3 frame # 0x0000 0x1000 0x2000 0x3000 0x4000 0x5000 0x6000 0x7000 0x8000 0x9000 0xa000 0xb000 address 0123456789ab0123456789ab load module Here, for example, we see the OS view of memory for a page/frame size of 2 12 = 16 3 bytes The physical memory doesnt see any of this; it just continues its boring life of receiving a physical address plus a control bit which tells it whether to read or write that address Its up to the loader to load pages into the correct physical addresses and its up to the MMU to properly bind a logical address to a physical address before its sent to the memory (well see how shortly) The physical memory doesnt see any of this; it just continues its boring life of receiving a physical address plus a control bit which tells it whether to read or write that address Its up to the loader to load pages into the correct physical addresses and its up to the MMU to properly bind a logical address to a physical address before its sent to the memory (well see how shortly) By dividing the logical address space of the load module up into fixed length chunks called pages, paged memory management drops the need for managing variable length holes in memory, which is what leads to external fragmentation Pages are independently loading them into frames defined by evenly spaced main memory addresses that appear to divide memory into fixed length chunks exactly the same size as pages Any page can go to any frame By dividing the logical address space of the load module up into fixed length chunks called pages, paged memory management drops the need for managing variable length holes in memory, which is what leads to external fragmentation Pages are independently loading them into frames defined by evenly spaced main memory addresses that appear to divide memory into fixed length chunks exactly the same size as pages Any page can go to any frame

5 MSJ-5 The long term scheduler (in charge of admission) asks the memory manager if there are enough free frames on the free frame list for the new process If so, the requisite number of frames are removed from the FFL and inserted into the new processs page table The long term scheduler (in charge of admission) asks the memory manager if there are enough free frames on the free frame list for the new process If so, the requisite number of frames are removed from the FFL and inserted into the new processs page table Page Table (PT) The Long Term Scheduler, Admission, the Free Frame List, and the Page Table FFL 220 3e8 99 a2 2f5 aa5 678 27 27b For paged memory management, the free space list is simplified to a free frame list (FFL) whose management is much simpler than the older free space list: It doesnt need to be ordered Since theyre fixed length, any frame is as good as any other for any use whatsoever For paged memory management, the free space list is simplified to a free frame list (FFL) whose management is much simpler than the older free space list: It doesnt need to be ordered Since theyre fixed length, any frame is as good as any other for any use whatsoever The page table (PT) is a data structure used for the execution time binding of paged memory management Each process must have its own page table A PT contains the frame numbers assigned to (containing) the process A processs page table is created when it (a new process) is admitted and loaded The page table (PT) is a data structure used for the execution time binding of paged memory management Each process must have its own page table A PT contains the frame numbers assigned to (containing) the process A processs page table is created when it (a new process) is admitted and loaded Remember: All this number means in the FFL is that the physical memory from address 220*(pageSize) to address 221*(pageSize) is currently not used so its free for assignment to any page of any process that needs it

6 MSJ-6 PA Execution Time Binding for Paged Memory Management main memory LA memory management unit (MMU) CPU d fpfp p The MMU then appends the displacement from the logical address to the frame number and the result is the physical address to be sent to main memory p d p is used as an offset into the page table The MMU circuitry splits up the logical address into a page number, p, and the displacement from the beginning of that page, d page table (PT) f0f0 f1f1 f2f2 fpfp The memory management unit (MMU) uses the page table to bind each logical address emitted by the CPU to the correct physical address in main memory The frame number the MMU finds there, in PT[p], is the frame in main memory that the OS assigned to hold page p of the processs logical address space page p frame f p d PA=f p *(pageFrameSize)+d

7 MSJ-7 Page Table in the MMU So Where is the Page Table? page registers main memory PALA memory management unit (MMU) p d CPU page table (PT) dpdp fpfp fpfp v v v v v i i i Each page register also needs an extra bit to indicate whether or not it is valid So, for example, for a process whose logical address space was only 5 pages, only the first 5 page registers would be marked valid A CPU reference to an invalid page would cause the MMU to generate a hardware trap and the OS would terminate the process Each page register also needs an extra bit to indicate whether or not it is valid So, for example, for a process whose logical address space was only 5 pages, only the first 5 page registers would be marked valid A CPU reference to an invalid page would cause the MMU to generate a hardware trap and the OS would terminate the process n bits 2 n page registers If the page table for the running process is going to be in the MMU, it must be read in to what are called the MMU page registers as part of the context switch whenever the process is dispatched The bigger the page table, the longer the context switch time If the page table for the running process is going to be in the MMU, it must be read in to what are called the MMU page registers as part of the context switch whenever the process is dispatched The bigger the page table, the longer the context switch time When a process is not running, its page table is kept in memory There are two possibilities for how the MMU will access the page table for a currently running process: Copy it into the MMU as part of the context switch Use the one in main memory There are advantages and disadvantages to each choice When a process is not running, its page table is kept in memory There are two possibilities for how the MMU will access the page table for a currently running process: Copy it into the MMU as part of the context switch Use the one in main memory There are advantages and disadvantages to each choice Since the total number of bits in a logical address is fixed, fewer bits for the page number, p, meaning a smaller maximum size for a page table, means faster context switch times, but it also means more bits for the displacement, d, which increases the page size As the page size grows larger, internal fragmentation becomes more of a concern Since the total number of bits in a logical address is fixed, fewer bits for the page number, p, meaning a smaller maximum size for a page table, means faster context switch times, but it also means more bits for the displacement, d, which increases the page size As the page size grows larger, internal fragmentation becomes more of a concern

8 MSJ-8 Page Table memory management unit (MMU) main memory p d LAPA d fpfp CPU PTBR p + Page Table Only in Main Memory fpfp yes no trap to OS ? p PTLR PTLR To find the physical address in memory of the desired entry in the page table, the page number is simply added to the PTBR n bits Note that using p as an offset in main memory means that the page table must be contiguous in memory If the largest possible page table fits into a single frame, thats guaranteed, of course, since memory within a frame is contiguous Otherwise, it will be necessary to page the page table! Note that using p as an offset in main memory means that the page table must be contiguous in memory If the largest possible page table fits into a single frame, thats guaranteed, of course, since memory within a frame is contiguous Otherwise, it will be necessary to page the page table! p max size 2 n entries Note also that now every memory request by the CPU results in two physical memory references, the first into the page table to obtain f p for binding, and the second to actually satisfy the CPUs request The result is to effectively double the time it takes to satisfy the CPUs memory request Note also that now every memory request by the CPU results in two physical memory references, the first into the page table to obtain f p for binding, and the second to actually satisfy the CPUs request The result is to effectively double the time it takes to satisfy the CPUs memory request A page table limit register (PTLR) in the MMU can be used to avoid (fairly obvious) problems with keeping a valid/invalid bit with each page table entry in memory The PTLR and the PTBR are both part of a processs context A page table limit register (PTLR) in the MMU can be used to avoid (fairly obvious) problems with keeping a valid/invalid bit with each page table entry in memory The PTLR and the PTBR are both part of a processs context If the MMU doesnt have page registers, it will need to access the page table in memory and so will need a special purpose register called the page table base register to contain the base address of the page table for the running process (each process has its own page table, remember) One PTBR is faster to context switch than a whole bunch of page registers If the MMU doesnt have page registers, it will need to access the page table in memory and so will need a special purpose register called the page table base register to contain the base address of the page table for the running process (each process has its own page table, remember) One PTBR is faster to context switch than a whole bunch of page registers The frame number there in PT[p] is then read into the MMU and concatenated with the displacement to complete the binding

9 MSJ-9 memory management unit (MMU) main memory p dpdp LA dpdp CPU Translation Look Aside Buffer (TLAB) page table PTBR p + fpfp TLAB miss page # frame # TLAB TLAB hit fpfp PA yes no trap to OS ? p PTLR PTLR In the event the page number is not found (TLAB miss), the required frame number is retrieved from the page table in memory as before The TLAB is an associative cache of recently referenced page numbers and their corresponding frame numbers When a page number is presented to the TLAB, it is searched associatively and if theres a hit (the presented page number is found), its frame number is available for binding without the necessity of retrieving it from memory The TLAB is an associative cache of recently referenced page numbers and their corresponding frame numbers When a page number is presented to the TLAB, it is searched associatively and if theres a hit (the presented page number is found), its frame number is available for binding without the necessity of retrieving it from memory A translation look aside buffer (TLAB) in the MMU can speed things up by eliminating the binding access(es) to physical memory most of the time

10 MSJ-10 From an MMU design standpoint, its easy enough: just add protection bits to each entry in the page table But the programs logical address space as produced by the compiler is contiguous and the boundaries between the various code and data structures usually wont fall neatly on page boundaries that the compiler doesnt know anything about A Problem With Paging: Protection Bits Cannot Really be Applied to Pages read write execute 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 1 0 0 PT The page table, can, in theory, help an OS to enforce a security policy so that, for example, users dont try to overwrite code in library files that they in fact have a right to execute (but not to change) Data stored here can be both read and written by this process code data pages in the contiguous logical address space read write execute 0 0 1 ? ? ? 1 1 0 What protection should be applied to this page? This page looks like it contains code; the CPU can fetch instructions from here for execution, but other accesses are not permitted The CPU can read data from here, but cant write to it this might be a frame shared by some other process that owns the data, wants to share it, but doesnt want it altered by this process Remember, each process has its own page table, so to share memory, the same frame number can appear in the page table of multiple processes and will usually be in different pages in the different processes, each with its own protection bits The CPU can read data from here, but cant write to it this might be a frame shared by some other process that owns the data, wants to share it, but doesnt want it altered by this process Remember, each process has its own page table, so to share memory, the same frame number can appear in the page table of multiple processes and will usually be in different pages in the different processes, each with its own protection bits

11 MSJ-11 Roadmap Contiguous memory management and its limitations Paged memory management Segmented memory management Motivation and overview The segment table

12 MSJ-12 Segmented Memory Management Segments are logically distinct chunks of the overall logical address space of a process Each segment is logically contiguous and is assigned (bound) to physical memory by the OS and the MMU independently of other segments user code library code shared memory stack global data heap process

13 MSJ-13 main memory memory management unit (MMU) CPU LA segment table r w e segment base protection size address bits The Segment Table s dsds d s < limit ? no segmentation error, core dumped yes + dsds PA dsds The segment table is the key data structure used by segmented memory management, analogous to the page table for paged memory managmement It is where the protection bits applicable to each segment are stored – in fact, thats one indicator of a segment: Something that is coherent in terms of its protection requirements and independent of other segments protection requirements n bits The displacement within the segment, d s, is then checked against the size limit of the segment from the segment table To complete the binding, the displacement is added to the base address of the segment ??? Note that this binding mechanism means that a segment must be stored contiguously in main memory! Thats not progress; were back to contiguous memory management and external fragmentation again! Note that this binding mechanism means that a segment must be stored contiguously in main memory! Thats not progress; were back to contiguous memory management and external fragmentation again! The MMU splits up the logical address it receives from the CPU into two fields: a segment number and a displacement within that segment For a valid segment, the protection bits are then checked to determine if the operation requested by the CPU is legal for that segment If not, the MMU raises a protection violation trap For a valid segment, the protection bits are then checked to determine if the operation requested by the CPU is legal for that segment If not, the MMU raises a protection violation trap The segment number, s, is used as an offset into the segment table Depending on where the segment table is stored (same choices as for a page table), the MMU can use either a valid/invalid bit for each segment register or a segment table limit register (STLR) to determine if the segment number from a logical address is valid, just as was done for the page number by a paging MMU If the segment number is invalid, the MMU raises a segmentation error trap to OS The segment number, s, is used as an offset into the segment table Depending on where the segment table is stored (same choices as for a page table), the MMU can use either a valid/invalid bit for each segment register or a segment table limit register (STLR) to determine if the segment number from a logical address is valid, just as was done for the page number by a paging MMU If the segment number is invalid, the MMU raises a segmentation error trap to OS Each entry in the segment table records the protection bits, size, and base address for a segment We didnt need to do this check when paging, since all pages were the same size and all possible values of d p were always legal, but segments are variable length so a given segment may, and in general will, be less than the maximum possible segment size of 2 n bytes, where n is the number of bits for the d s field of the logical address

14 MSJ-14 segment table protection segment page table bits size base address Paging Within a Segment Gets the Best of Both Worlds main memory memory management unit (MMU) LA CPU s d s < limit ? no segmentation error, core dumped yes dsds p dpdp The only change to the segment table is that the base address is now for the segments page table, not for the segment itself PT s Each segment has its own page table PA The MMU checks for protection and segment size violations as before paging using p, d p, and the segments page table, PT s Once the legality of the logical address and the CPUs requested operation are determined, the displacement within segment, d s, is then split into two fields, a page number within the segment and a displacement within the page Binding is then completed via the segments page table Once the legality of the logical address and the CPUs requested operation are determined, the displacement within segment, d s, is then split into two fields, a page number within the segment and a displacement within the page Binding is then completed via the segments page table If the segment table were stored in memory – as opposed to segment registers in the MMU – the CPUs requested memory operation would take 3 accesses to physical memory: One to retrieve the segment table entry for segment #s One to retrieve the page table entry for page p of segment s The access to the final, bound physical address A TLAB would be essentially mandatory here If the segment table were stored in memory – as opposed to segment registers in the MMU – the CPUs requested memory operation would take 3 accesses to physical memory: One to retrieve the segment table entry for segment #s One to retrieve the page table entry for page p of segment s The access to the final, bound physical address A TLAB would be essentially mandatory here


Download ppt "MSJ-1 Relocation of an Admitted Process Requires Execution Time Binding memory management unit (MMU) main memory LA PA + + base address CPU The problem."

Similar presentations


Ads by Google