1 / 52

Memory management

Memory management . Ref: Stallings G.Anuradha. What is memory management?. The task of subdivision of user portion of memory to accommodate multiple processes is carried out dynamically by the operating system and is known as memory management Memory management terms.

ppoe
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 Ref: Stallings G.Anuradha

  2. What is memory management? • The task of subdivision of user portion of memory to accommodate multiple processes is carried out dynamically by the operating system and is known as memory management • Memory management terms

  3. Memory management requirements

  4. Memory management requirements – Contd… • Relocation • Users generally don’t know where they will be placed in main memory • May want to swap in at a different place • Must deal with user pointers • Generally handled by hardware • Protection • Prevent processes from interfering with the O.S. or other processes • Often integrated with relocation

  5. Memory management requirements – Contd… • Sharing • Allow processes to share data/programs • Logical Organization • Main memory and secondary memory are organized into linear/1D address space of segments and words. • Secondary memory is also similarly organized • Most programs are modularized • Advantages of modular approach • Written and compiled independently • Can have different degrees of protection • Module level of sharing • Physical Organization • Transferring data in and out of main memory to secondary memory can’t be assigned to programmers • Manage memory « disk transfers (System responsibility) Segmentation

  6. Memory Partitioning • Fixed partitioning • Dynamic partitioning • Simple Paging • Simple segmentation • Virtual memory paging • Virtual memory segmentation

  7. Fixed partitioning

  8. Difficulties in equal size fixed partitions • A program may be too big to fit into a partition. In such cases overlays can be used • Main memory utilization is extremely inefficient. • Leads to internal fragmentation • BLOCK OF DATA LOADED IS SMALLER THAN THE PARTITION

  9. Placement algorithm • With equal size partition a process can be loaded into a partition as long as there is an available partition • With unequal size partitions there are two possible ways to assign processes to partitions • One process queue per partition • Single partition

  10. Memory assignment for fixed partitioning

  11. Advantages and disadvantages of each of the approaches • One process queue per partition • Advantages: • Internal fragmentation is reduced • Disadvantages • Not optimal from the system point of view • Single queue • Advantages • Degree of flexibility, simple, requires minimal OS S/w and processing overhead • Disadvantages • Limits the number of active processes in the system • Small jobs will not utilize partition space efficiently IBM Mainframe OS. OS/MFT

  12. Dynamic partitioning • Create partitions as programs loaded • Avoids internal fragmentation, but must deal with external fragmentation

  13. Effect of dynamic partitioning

  14. Dynamic partitioning • External fragmentation:-As time goes on more and more fragments are added and the effective utilization declines • External fragmentation can be overcome using compaction • Compaction • Time consuming

  15. Placement algorithm • Best-fit:- Chooses the block that is closest in size to the request • First-fit:- scans memory from the beginning and chooses the first available block that is large enough • Next-fit:-Scan memory from the location of the last placement and chooses the next available block that is large enough

  16. Which amongst them is the best? • First fit:- • Simple, best and fastest • Next fit:- • Next to first fit. Requires compaction in this case • Best fit:- • Worst performer. Memory compaction should be done as frequently as possible

  17. Buddy system • Overcomes the drawbacks of both fixed and dynamic partitioning schemes

  18. Algorithm of buddy system • The entire space available for allocation is treated as a single block of size 2U • If a request of size s ST is made then the entire block is allocated • Otherwise the block is split into two of size 2U-1 • This process continues until the smallest block greater than or equal to s is generated and allocated to the request

  19. Example of a buddy system

  20. Free representation of buddy system Modified version used in UNIX kernel memory allocation

  21. Relocation • Not a major problem with fixed-sized partitions • Easy to load process back into the same partition • Otherwise need to deal with a process loaded into a new location • Memory addresses may change • When loaded into a new partition • If compaction is used • To solve this problem a distinction is made among several types of addresses.

  22. Relocation • Different types of address • Logical address:- reference to a memory location independent of the current assignment of data to memory • Relative address:- example of logical address in which the address is expressed as a location relative to some known point • Physical address:- actual location in main memory A hardware mechanism is needed for translating the relative addresses to physical main memory addresses at the time of execution of the instruction that contain the reference

  23. Hardware support for relocation

  24. Base/Bounds Relocation • Base Register • Holds beginning physical address • Add to all program addresses • Bounds Register • Used to detect accesses beyond the end of the allocated memory • Provides protection to system • Easy to move programs in memory • Change base/bounds registers • Largely replaced by paging

  25. Paging • Problems with unequal fixed-size and variable-size partitions are external and internal fragmentations respectively. • If the process is also divided into chunks of same size - pages • Memory is divided into chunks called frames • Then a page can be framed into a page frame • Then there will be only internal fragmentation especially in the last page of the process

  26. Assignment of Process pages to free frames

  27. Page tables • When a new process D is brought in, it can still be loaded even though there is no contiguous memory location to store the process. • For this the OS maintains a page table for each process • The page table shows the frame location for each page of the process • Within the program, each logical address consists of a page number and an offset within the page

  28. Page table contd… • In a simple partition, a logical address is the location of a word relative to the beginning of the program • The processor translates it into physical address. • With paging the logical-physical address translation is done by hardware Logical address {page number, offset} Physical address {Frame number, offset} processor

  29. Data structures when process D is stored in main memory Paging similar to fixed size partitioning Difference:- 1. partitions are small 2. Program may occupy more than one partition 3. Partitions need not be contiguous

  30. Computation of logical and physical addresses • Page size typically a power of 2 to simplify the paging hardware • Example (16-bit address, 1K pages) • Relative address of 1502 is • Top 6 bits (000001)= page # {Page number is 1} • Bottom 10 bits (0111011110) = {offset within page, in this case 478} • Thus a program can consist of a maximum of 26 = 64 pages of 1K bytes each.

  31. Why page size is in multiples of 2? • The logical addressing scheme is transparent to programmer, assembler, linker. • Easy to implement a function in hardware to perform dynamic address translation at runtime. • Steps in address translation

  32. Logical to physical address translation using paging

  33. Hardware support • OS has its own method for storing page tables. Pointer to page table is stored with the other register values in the PCB, which is reloaded whenever the process is loaded. • Page table may be stored in special registers if the number of pages is small. • Page table may be stored in physical memory, and a special register, page-table base register, points to the page table.(Problem is time taken for accessing)

  34. Implementation of Page Table • Page table is kept in main memory • Page-table base register (PTBR) points to the page table • Page-table length register (PRLR) indicates size of the page table • In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction. • The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs) • Some TLBs store address-space identifiers (ASIDs) in each TLB entry – uniquely identifies each process to provide address-space protection for that process

  35. Hardware support contd… • Use translation look-aside buffer (TLB). TLB stores recently used pairs (page #, frame #). • It compares the input page # against the stored ones. If a match is found, the corresponding frame # is the output. Thus, no physical memory access is required. • The comparison is carried out in parallel and is fast. • TLB normally has 64 to 1,024 entries.

  36. Paging Hardware With TLB

  37. Memory Protection • Memory protection implemented by associating protection bit with each frame • Valid-invalid bit attached to each entry in the page table: • “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal page • “invalid” indicates that the page is not in the process’ logical address space

  38. Valid (v) or Invalid (i) Bit In A Page Table

  39. Shared pages • Possibility of sharing common code • This happens in the case if the code is re-entrant code(pure code). • Re-entrant code is non-self modifying code: it never changes during execution. Two or more processes can simultaneously utilize the same code.

  40. Shared Pages Example

  41. Summary • Main memory is divided into equal sized frames • Each process is divided into frame-sized pages • When a process is brought in all of its pages are loaded into available frames and a page table is set up • This approach solves the problems in partitioning

  42. Segmentation • Segmentation is a memory management scheme that supports user view of memory • Logical address space is a collection of segments • Each segment has a name and length • Each address has a segment and a offset within a segment

  43. User’s View of a Program

  44. 1 4 2 3 Logical View of Segmentation 1 2 3 4 user space physical memory space

  45. Segmentation Hardware

  46. Example of Segmentation Segment 2 , ref to byte 53=4300+53=4353 Segment 3, ref to byte 852=3200+852=4052 Segment 0, ref to byte 1222= 6300+1222

  47. Implementation of Segment Tables • Just like page tables the segment tables can be kept in registers and accessed • When the program contains a large number of segments a segment table base register and segment table limit register is kept in the memory and checks are performed

More Related