1 / 50

Chapter 7 Memory Management

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management. Seventh Edition William Stallings. Operating Systems: Internals and Design Principles.

peony
Download Presentation

Chapter 7 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. Operating Systems:Internals and Design Principles Chapter 7Memory Management Seventh Edition William Stallings

  2. Operating Systems:Internals and Design Principles I cannot guarantee that I carry all the facts in my mind. Intense mental concentration has a curious way of blotting out what has passed. Each of my cases displaces the last, and Mlle. Carère has blurred my recollection of Baskerville Hall. Tomorrow some other little problem may be submitted to my notice which will in turn dispossess the fair French lady and the infamous Upwood. — THE HOUND OF THE BASKERVILLES, Arthur Conan Doyle

  3. Definition • Memory management is the process of • allocating primary memory to user programs • reclaiming that memory when it is no longer needed • protecting each user’s memory area from other user programs; i.e., ensuring that each program only references memory locations that it has the right to access.

  4. Requirements • In order to manage memory effectively the OS must have • Memory allocation policies • Methods to track the status of memory locations (free or allocated) • Policies for preempting memory from one process to allocate to another

  5. Memory Management Terms

  6. Memory Management Requirements • Memory management is intended to satisfy the following requirements: • Relocation • Protection • Sharing • Logical organization • Physical organization

  7. Relocation • Relocation is the process of adjusting program addresses to match the actual physical addresses where the program resides when it executes • Why is relocation needed? • Programmer/translator don’t know which other programs will be memory resident when the program executes

  8. Relocation • Why is relocation needed? (continued) • Active processes need to be able to be swapped in and out of main memory in order to maximize processor utilization • Specifying that a process must be placed in the same memory region when it is swapped backin would be limiting • Consequently it must be possible to adjust addresses whenever a programis loaded.

  9. Addressing Requirements Simplified Process Image

  10. Protection Processes need to acquire permission to reference memory locations for reading or writing purposes Location of a program in main memory is unpredictable & some addresses (array indices, for example) are not known until runtime, so memory references generated by a process must be checked at run time Mechanisms that support relocation also support protection

  11. Sharing Advantageous to allow each process access to the same copy of the program rather than have their own separate copy Memory management must allow controlled access to shared areas of memory without compromising protection Shared memory may be read-only (e.g., programs) or read-write (e.g., shared data structures). Different access controls for each. Mechanisms used to support relocation support sharing capabilities

  12. Logical Organization Main memory is organized as a linear (1-D) address space consisting of a sequence of bytes or words. Programs aren’t necessarily organized this way

  13. Physical Organization • Two-level memory for program storage: • Disk (slow and cheap) & RAM (fast and more expensive) • Main memory is volatile, disk isn’t • User should not have to be responsible for organizing movement of code/data between the two levels.

  14. Physical Organization

  15. Memory Partitioning • Virtual memory management brings processes into main memory for execution in pieces - • involves swapping of portions of the program • based on segmentation and paging • Partitioned memory management • used in several variations in some now-obsolete operating systems • does not involve virtual memory

  16. Table 7.2Memory ManagementTechniques

  17. Fixed Partitioning • Equal-size partitions • any process whose size is less than or equal to the partition size can be loaded into an available partition • The operating system can swap out a process if all partitions are full and no process is in the Ready or Running state

  18. Disadvantages • A program may be too big to fit in a partition • program needs to be designed with the use of overlays • Main memory utilization is inefficient • any program, regardless of size, occupies an entire partition • internal fragmentation • wasted space due to the block of data loaded being smaller than the partition

  19. Unequal Size Partitions • Using unequal size partitions helps lessen the problems • programs up to 16M can be accommodated without overlays • partitions smaller than 8M allow smaller programs to be accommodated with less internal fragmentation

  20. Memory Assignment Fixed Partitioning

  21. Disadvantages The number of partitions specified at system generation time limits the number of active processes in the system Small jobs will not utilize partition space efficiently

  22. Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as it requires This technique was used by IBM’s mainframe operating system, OS/MVT

  23. Effect of Dynamic Partitioning

  24. Dynamic Partitioning

  25. Placement Algorithms

  26. Memory Configuration Example

  27. Buddy System • Comprised of fixed and dynamic partitioning schemes • Space available for allocation is treated as a single block • Memory blocks are available of size 2K words, L ≤ K ≤ U, where • 2L = smallest size block that is allocated • 2U = largest size block that is allocated; generally 2U is the size of the entire memory available for allocation

  28. Buddy System Example

  29. Tree Representation

  30. Addresses

  31. Relocation

  32. Review • Memory Management: Allocation, de-allocation, protection • Requirements: techniques to support relocation, memory protection, memory sharing • Early allocation methods: • Fixed partitions: internal fragmentation, limited number of processes due to inflexible partition size but easy to keep track of available memory • Variable partitions: external fragmentation, higher overhead related to tracking free memory, memory compaction • Characteristics of partitioned memory: • The entire process must be loaded into memory or programmer must use overlays. • The entire virtual address space must be loaded into consecutive memory locations to support relocation and protection (see previous slide)

  33. Paging Partition memory into equal fixed-size chunks that are relatively small Process is also divided into small fixed-size chunks of the same size

  34. Assignment of Process to Free Frames

  35. Page Table Instead of a single base register, we need a way to keep track of every possible page that a process might have – the page table Maintained by operating system for each process Contains the frame location for each page of the process that is currently in memory. Used by processor to produce a physical addressfrom the logical address Processor must know how to access the page table for the current process

  36. Data Structures

  37. Logical Addresses • Relative Address: assigned by the translator, expresses an offset from the first location in the program or. • Logical Address: refers to a memory location, but is independent of the current “assignment of data to memory”; i.e., it has meaning in the address space of the process but doesn’t relate to physical memory. • A logical address consists of a page # and an offset.

  38. Logical Addresses • Logical addresses must be translated to physical addresses • Show that relative addresses are equivalent to logical. • Example: based on 16-bit addresses, with 1K page size. • Page size = 210 ; we need 10 bits to express the addresses on a single page • Page displacement = 26, the number of bits that express the page number

  39. Logical Addresses

  40. Logical to Physical: Basics • Page size = power of 2; logical addressing scheme is transparent to the programmer, translator, etc. • Consider addresses of n + m bits, where leftmost n specify page number and rightmost m specify offset within a page. • For k = page number and page size = 2m, starting page addresses are k * 2m (For m = 10, page addresses are 0, 1024, 2048, 3072, 4096, … ) • In binary, the addresses are 000000 0000000000, 000001 0000000000, 000010 0000000000, 000011 0000000000, 000100 0000000000, and so on.

  41. Logical to Physical: Basics • From the logical address, extract the left-most 6 bits ( the logical page number). • Use it as an index into the page table to find the physical page that holds this logical page. • Append the logical offset (rightmost 10 bits) to the physical page number to get the physical address.

  42. Logical-to-Physical Address Translation - Paging

  43. Segmentation • A program can be subdivided into segments • may vary in length • there is a maximum length • Addressing consists of two parts: • segment number • an offset • Similar to dynamic partitioning • Eliminates internal fragmentation

  44. Logical-to-Physical Address Translation - Segmentation

  45. Security Issues

  46. Buffer Overflow Attacks Security threat related to memory management Also known as a buffer overrun Can occur when a process attempts to store data beyond the limits of a fixed-sized buffer One of the most prevalent and dangerous types of security attacks

  47. Buffer Overflow Example

  48. Buffer Overflow Stack Values

  49. Defending Against Buffer Overflows Prevention Detecting and aborting Countermeasure categories:

  50. Summary • Memory Management • one of the most important and complex tasks of an operating system • needs to be treated as a resource to be allocated to and shared among a number of active processes • desirable to maintain as many processes in main memory as possible • desirable to free programmers from size restriction in program development • basic tools are paging and segmentation (possible to combine) • paging – small fixed-sized pages • segmentation – pieces of varying size

More Related