Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.

Similar presentations


Presentation on theme: "COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address."— Presentation transcript:

1 COMP091 – Operating Systems 1 Memory Management

2 Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address known to program Relocatable –Program image uses relative addresses and can run from any place in memory Relative address –Address is relative to some base address = base + offset –Calculated or use hardware relative addressing

3 Memory Management Terms Static addresses –Addresses either don't change, or appear not to change Dynamic –Program knows addresses change at runtime –Uses pointer or handles to cope with dynamic addresses –Stack frames are dynamic –Dynamically allocated memory

4 More Memory Management Terms Base | segment | page pointer –Contains the base address that relative addresses are relative to –Addresses can be expressed relative to these hardware registers

5 More Memory Management Terms Pointer –A data item –Address of some other object Handles –A pointer managed externally –Process is provided address of the handle This address is a pointer to the pointer –Might be ased in heaps where address of the resource might be changed externally

6 More Memory Management Terms Binding –Provides a value for the base address of a relative address –Loading binds relative addresses to base of a memory segment –Addresses may be rebound if program moves around

7 More Memory Management Terms Partition –Early multi-programming systems allocated a memory partition to each batch job –Relied on jobs to stay in their own space –One base address for entire partition Segment –Like partition but a job may have more than one for different purposes –OS keeps track of memory use to keep processes within their own segments

8 More Memory Management Terms Absolute address –Constant actual physical address Some low memory addresses are constant –Boot routines in low memory –Traps, exceptions and interrupts are handled by routines at absolute addresses, or pointed to by a pointer at an absolute address –In virtual memory systems, areas like low memory that are accessed using absolute addresses are located in their real address which equals their virtual address

9 More Memory Management Terms Low memory –Systems, both hardware and OS usually reserve some low memory addresses for specific fixed uses –Particularly important during boot process Contiguous allocation –Programs expect the memory in any given segment to occupy contiguous memory locations –OS would have to find free memory large enough for entire allocation –In virtual memory systems this doesn't matter –Which is good because garbage collection is hard

10 Virtual Memory Systems Physical memory divided into frames Virtual memory divided into pages –Many more pages then frames Loading (binding) means associating an (active) page with a frame Frames don't need to be contiguous Page table keeps track of pages Divide address by size of page (2**n for some n) Quotient is page number Remainder is offset into page

11

12

13 Virtual Memory Systems Shared pages A frame address can be inserted into the page tables of many different processes –Enabling the processes to share the data on the pages that point to the shared frame –Useful for intra-process communication Inverted page table –One entry per frame –Enables OS to find process that owns a frame –Useful if you have to move the frame

14 Segmentation Logical memory is composed of segments –Many contiguous pages in a segment Segment table has the base address of each segment and its size, referred to as its limit –Limit because that is the largest offset that its process can use without generating a segmentation fault Some segments are marked sharable –Common OS code

15 Segmentation and Virtual Memory Each segment has its own page table Addresses resolved in the usual way Calculate the page table offset to find page number –Offset = address / page size Add to the segment's page table base to find the entry with the frame # –Then add remainder to frame base Notice in the following diagram that there are a lot more pages in page tables than there are frames in physical memory –Some pages aren't mapped to memory frames

16

17 Working Set At any point in time, a logical page may or may not be mapped to a physical frame The set of pages that are currently mapped to a physical frame and are pageable is called the working set Note: Windows allows applications to make large allocations that are permanently resident in physical memory and non-pageable so not part of working set –Address Windowing Extensions (AWE) or large page allocations

18 Backing Store Location of pages not currently in the working set Either a page file or a memory mapped file Processes can access data in a file by mapping some virtual addresses to the file on disk This is how executables are loaded Can be used to access other files And to share data among processes

19 File Mapping

20 Memory Management Functions

21 Demand Paging Program attempts memory access Processor (with hardware virtual memory support) attempts to find frame Page table doesn't contain a frame address if the page is not in memory Processor generates page fault User process is put in wait state

22 Demand Paging (cont.) OS checks to see if address is valid If not, process is terminated with memory violation If valid, page is retrieved from backing store, stored in a frame, page table updated with frame # Process is restarted This time, processor will find frame in page table and address can be accessed

23 Soft Page Fault A page fault generated for a page that doesn't have to be retrieved from backing store –Currently or recently in some other process's working set Maybe the OS –A new page never yet accessed (demand zero fault) –A pre-fetched page System just has to add frame to process's page table

24 Memory Map Describes relationship between pages of logical memory and physical memory frames –Or other locations of a logical memory pages Another memory map data structure describes all of the physical frames –User count –Age (for swap eligibility) –Frame number

25 Memory Mapping When loading an executable image into memory, only first page of image is loaded into virtual memory This allows construction of the page table for the entire image Image is not copied from disk file to virtual memory Instead memory map data structures are altered so the area of disk containing the image becomes a part of the virtual memory As image executes, page faults bring image into real memory

26 Swapping When physical memory is full, some pages have to be removed, or swapped, into swap file Usually the least most recently used page is swapped out Different OS's could use different algorithms Efficiency of algorithm is very important to performance Pages have “dirty bit” set if they have been changed since loading If dirty bit is not set page is discarded instead of being swapped (no need to save it)

27 Addressing Modes Hardware supports physical and virtual addressing modes OS itself resides in area of physical address space where physical addressing is employed –Processor doesn't have to resolve virtual addresses for the OS itself Processes that manipulate large amounts of memory can acquire large physically resident allocations –But still accessed through memory map

28 Access Control Segment tables contain access control information: –Read only for executables –Read allowed only for kernel mode processes –Read allowed for user mode processes –Write allowed only for kernel mode processes –Write allowed for user mode processes –Page dirty –Page has been accessed –etc

29 Page Allocation Programs asking for memory allocations are requesting virtual memory –Since the memory isn't real, they are actually asking for control over some virtual memory addresses A free area vector lists the blocks of free page numbers, smallest block first –There are other ways Allocation algorithm tries to allocate a request in minimum number of blocks Might break a too large block into smaller blocks to get right size

30 Deallocation When a block of memory is deallocated, attempt is made to combine the block with adjacent blocks to create a larger free block This is to counter the fragmentation that can occur as allocation breaks blocks up into smaller ones

31 Virtual Memory The memory space for a process may, and normally would, consist of more than one segment Each segment has a page table describing the virtual memory of that segment The virtual memory associated with the process consists of the collection of memory spaces described by all of the process's segments

32 Where is Virtual Memory? In a newly allocated data segment the memory doesn't exist until a page fault –After that it is in a physical frame or swap file If the segment points to a shared OS segment, then the virtual memory may be permanently stored in low memory If the segment “contains” an executable, or is mapped to some other file, the virtual memory will be mapped to the area of disk containing the executable –Will be loaded to memory via page faults only when needed

33 References MSDN: –http://msdn.microsoft.com/en- us/library/windows/desktop/aa366525%28v=vs.8 5%29.aspxhttp://msdn.microsoft.com/en- us/library/windows/desktop/aa366525%28v=vs.8 5%29.aspx tldp –http://www.tldp.org/LDP/tlk/mm/memory.htmlhttp://www.tldp.org/LDP/tlk/mm/memory.html

34 Next Week Test in first 50 minutes –Lectures and labs No new lab this week or next –Students can have additional week for lab 5 if they need it. –May redo a past lab with permission


Download ppt "COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address."

Similar presentations


Ads by Google