Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles."— Presentation transcript:

1 Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles

2 Memory Management Requirements Hardware + software Main purpose: allocate memory to processes efficiently, so as many processes as possible can be in memory, ready to run Memory management must also satisfy the following requirements: Relocation Protection Sharing Logical organization Physical organization

3 Relocation When a program is compiled it is not known where a program will be stored in main memory, so it is impossible to assign actual physical addresses to instructions and data. Instead, logical (virtual) addresses are assigned When the program is loaded into memory, it is relocated : that is, bound to a set of physical addresses 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 back in would be limiting may need to relocate the process to a different area of memory

4 Hardware & OS must know where program is stored so it can have the actual address of the data, stack top, PCB, etc.

5 Protection Location of a program in main memory is not known until it is loaded Memory references generated by a process must be checked at run time – the general rule is that a process can only read/write locations that are part of its process image Mechanisms that support relocation also support protection

6 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 Mechanisms used to support relocation support sharing capabilities

7 Memory is organized as linear Segmentation is the tool that most readily satisfies requirements but is not commonly used Programs are written in modules modules can be written and compiled independently different degrees of protection given to modules (read-only, execute-only) sharing on a module level corresponds to the user’s way of viewing the problem

8 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.

9 Physical Organization Cannot leave the programmer with the responsibility to manage memory Memory available for a program plus its data may be insufficient overlaying allows various modules to be assigned the same region of memory but is time consuming to program Programmer does not know how much space will be available

10 Memory Partitioning Memory management brings processes into main memory for execution by the processor  today, involves virtual memory  based on paging or paging with segmentation Partitioning  used in several variations in some now-obsolete operating systems  does not involve virtual memory

11 Table 7.2 Memory Management Techniques (Table is on page 315 in textbook)

12 What if all partitions are full and no process is in the Ready state?

13

14 A program may be too big to fit in a partition program needs to be designed with the use of overlays The number of partitions specified at system generation time limits the number of active processes in the system 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

15 Partitions are of variable length and number Process is allocated exactly as much memory as it requires (sometimes within a power of 2) This technique was used by IBM’s mainframe operating system, OS/MVT

16

17 Dynamic Partitioning memory becomes more and more fragmented with small blocks of free space that are not big enough to use. memory utilization declines External Fragmentation technique for overcoming external fragmentation OS shifts processes so that they are contiguous free memory is together in one block time consuming and wastes CPU time Compaction

18 Placement Algorithms Best-fit chooses the block that is closest in size to the request First-fit begins to scan memory from the beginning and chooses the first available block that is large enough Next-fit begins to scan memory from the location of the last placement and chooses the next available block that is large enough

19

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

21

22

23 Addresses reference to a memory location independent of the current assignment of data to memory Logical address is expressed as a location relative to some known point – generated by translators Relative (a type of logical address) actual location in main memory Physical or Absolute

24 (and protection)

25 Simple Paging A Prelude to Virtual Memory

26 Table 7.1 Memory Management Terms

27 Partition memory into equal fixed-size chunks that are relatively small Process is also divided into small fixed-size chunks of the same size Pages chunks of a process Frames available chunks of memory

28

29 Page Table But now the base and bounds register approach won’t work for either relocation or protection. We need the equivalent of a base register for each page of the process The answer is a data structure known as a page table Maintained by operating system for each process

30 Page Table Contains the frame location for each page in the process Processor must know how to access the page table for the current process Just as with partitioned memory, hardware translates logical addresses to physical addresses The page table holds the information needed for translation.

31  Each page table is an array  The page table indexes refer to the page numbers in the program, the contents of each indexed entry gives the page number where that logical page is stored. So page 3 of process D is stored in frame 11.

32 Logical Addresses Our addresses are relative to a start address of 0, although other start addresses are acceptable as well A relative address can be divided into two parts: A (logical) page number A (absolute) position within the page (an offset) The page table is used by the memory management hardware to convert the logical address to an absolute (or physical) address during execution.

33 Logical Addresses To see how this works, consider the example on the next slide. Conditions Page & frame sizes are always powers of 2 In the example, addresses are 16 bits and a page is 1K 1K = 2 10, so it takes 10 bits to represent the locations in a single page, leaving 6 bits for a page number. The leftmost six bits represent the page number and the remaining 10 bits represent the offset – the address of a memory location on the selected page.

34

35

36 Summary Memory partitioning fixed partitioning dynamic partitioning buddy system relocation Memory management requirements relocation protection sharing logical organization physical organization Paging

37 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

38 Segmentation Usually visible Provided as a convenience for organizing programs and data Typically the programmer will assign programs and data to different segments For purposes of modular programming the program or data may be further broken down into multiple segments the principal inconvenience of this service is that the programmer must be aware of the maximum segment size limitation

39 Address Translation Another consequence of unequal size segments is that there is no simple relationship between logical addresses and physical addresses The following steps are needed for address translation: Extract the segment number as the leftmost n bits of the logical address Use the segment number as an index into the process segment table to find the starting physical address of the segment Compare the offset, expressed in the rightmost m bits, to the length of the segment. If the offset is greater than or equal to the length, the address is invalid The desired physical address is the sum of the starting physical address of the segment plus the offset

40


Download ppt "Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles."

Similar presentations


Ads by Google