1 / 65

Operating System II

Operating System II. Lecturer Assistant Sadeer Dheyaa Abdulameer. Cihan University - Sulaimaniya. Computer science Department. Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging. Memory Management Terms. Background.

Télécharger la présentation

Operating System II

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 System II Lecturer Assistant SadeerDheyaaAbdulameer Cihan University - Sulaimaniya Computer science Department

  2. Memory Management • Background • Swapping • Contiguous Allocation • Paging • Segmentation • Segmentation with Paging Memory Management Terms

  3. Background • Program must be brought into memory and placed within a process for it to be run. • Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program. • User programs go through several steps before being run. • Main memory and registers are only storage CPU can access directly. • Register access in one CPU clock (or less). • Main memory access can take many cycles, causing a stall. • Stallmean that CPU does not have required data to complete the instruction that it is executing. And it is solved by adding memory between CPU and Main Memory such as Cache.

  4. Binding of Instructions and Data to Memory • Address binding of instructions and data to memory addresses canhappen at three different stages: • binding : mean that it is a mapping from one address space to another. • Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes. • Load time: Must generate relocatable code if memory location is not known at compile time. final binding delayed until load time. • Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). • symbolic address in source program such as (count)converted to re locatable address by compiler such as (14 bytes) the linkage editor or loader bind the relocatable address to absolute address such 740

  5. Multistep Processing of a User Program

  6. Logical vs. Physical Address Space • The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. • Logical address –generated by the CPU; also referred to as virtual address. • Physical address – address seen by the memory unit. And loaded into Memory address register. • Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme. • Logical address space is the set of all logical addresses generated by a program. • Physical address space is the set of all physical addresses corresponding to logical address .

  7. Cont. • in compile and run time the address binding method generate identical logical and physical addresses. • in execution time the address binding method generate different logical and physical addresses.

  8. Memory-Management Unit (MMU) • Hardware device that maps virtual address to physical address. • In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory. • The user program deals with logical addresses; it never sees the real physical addresses. • Execution-time binding occurs when reference is made to location in memory. • Logical address bound to physical addresses.

  9. Dynamic relocation using a relocation register

  10. Dynamic Loading • Routine is not loaded until it is called. • Better memory-space utilization; unused routine is never loaded. • All routines kept on disk in relocatable load format. • Useful when large amounts of code are needed to handle infrequently occurring cases. • No special support from the operating system is required • Implemented through program design. • OS can help by providing libraries to implement dynamic loading.

  11. Dynamic Linking • Static linking - system libraries and program code combined by the loader into the binary program image. • Dynamic linking-linking postponed until execution time. • Small piece of code, stub, used to locate the appropriate memory-resident library routine. • Stub replaces itself with the address of the routine, and executes the routine. • Operating system needed to check if routine is in processes’ memory address. • Dynamic linking is particularly useful for libraries.

  12. Overlays • Keep in memory only those instructions and data that are needed at any given time. • Needed when process is larger than amount of memory allocated to it. • Implemented by user, no special support needed from operating system, programming design of overlay structure is complex.

  13. Swapping • A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. • Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images. • Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed. • Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped. • Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows. • System maintains a ready queue of ready-to-run processes which have memory images on disk • Does the swapped out process need to swap back in to same physical addresses? Depends on address binding method

  14. Schematic View of Swapping

  15. Contiguous Allocation • Main memory usually divided into two partitions: • Resident operating system, usually held in low memory with interrupt vector. • User processes then held in high memory. • Single-partition allocation • Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. • Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register. • MMU maps logical address dynamically.

  16. Cont. • usually want several user processes to reside in memory at the same time. • therefore need to consider how to allocate available memory to the processes that are in the input queue waiting to be brought into memory. • In contiguous memory allocation, each process is contained in a single section of memory that is contiguous to the section containing the next process. • The relocation-register scheme provides an effective way to allow the operating system’s size to change dynamically(Flexibility). • For example, If a device driver (or other operating-system service)is not commonly used, we do not want to keep the code and data in memory, as we might be able to use that space for other purposes. Such code is sometimes called transient operating-system code; it comes and goes as needed. Thus, using this code changes the size of the operating system duringprogram execution.

  17. Hardware Support for Relocation and Limit Registers

  18. Contiguous Allocation (Cont.) • Multiple-partition allocation • Degree of multiprogramming limited by number of partitions. • Hole – block of available memory; holes of various size are scattered throughout memory. • When a process arrives, it is allocated memory from a hole large enough to accommodate it. • Process exiting frees its partition, adjacent free partitions combined. • Operating system maintains information about:a) allocated partitions b) free partitions (hole)

  19. Dynamic Storage-Allocation Problem • How to satisfy a request of size n from a list of free holes? • Following are the most commonly strategies used to select a free hole from the set of available holes: • First-fit: Allocate the first hole that is big enough. • Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. • Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. • First-fit and best-fit better than worst-fit in terms of speed and storage utilization.

  20. (First fit , best fit , worst fit -memory placement strategies)

  21. Fragmentation • External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous. (In other words, happens when the memory allocator leaves sections of unused memory blocks between portions of allocated memory. ) • Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. (In other words, occurs when the memory allocator leaves extra space empty inside of a block of memory that has been allocated for a client.) • External fragmentation reduced by two approach: • 1- Compaction • Shuffle memory contents to place all free memory together in one large block. • Compaction is possible only if relocation is dynamic, and is done at execution time.

  22. Cont. • If addresses are relocated dynamically, relocation requires only moving the program and data and then changing the base register to reflect the new base address. • The simplest compaction algorithm is to move all processes toward one end of memory; all holes move in the other direction, producing one large hole of available memory. 2- permit the logical address space of the processes to be noncontiguous. And this approach achieved by : • Segmentation • paging

  23. segmentation • most programmers they prefer to view memory as a collection of variable-sized segments, with no necessary ordering among the segments Programmer’s view Of the program

  24. Cont. • Segmentation: is a memory-management scheme that supports the programmer view of memory. A logical address space is a collection of segments. • Each segment has a name and a length. The addresses specify both the segment name(Segment number) and the segment offset within the segment. • The programmer therefore specifies each address by two quantities: ( segment name and an offset). • thus logical address consist of two tuple : <segment number, offset>

  25. Segmentation hardware • Mapping two dimensional user defined address into one dimensional physical address effected by (segment table). • Each entry in the segment table has ( segment base and a segment limit). • Segment base: contains the starting physical address where the segment resides in memory. • Segment limit: specifies the length of the segment.

  26. Cont. 3. the logical address consist of two part: • 1- the segment number(s) which used as index to the segment table. • 2- segment offset (d) which must be between 0 and segment limit. If it not then we trap operating system(logical addressing attempt beyond end of segment). • 3- when offset if legal (less then limit) it is added to the segment base to produce the address in physical memory.

  27. Segmentation hardware

  28. Example of segmentation

  29. Example of segmentation: We have five segments numbered from 0 through 4. The segments are stored in physical memory as shown in example of segmentation. The segment table has a separate entry for each segment, giving the beginning address of the segment in physical memory (or base) and the length of that segment (or limit). For example, segment 2 is 400 bytes long and begins at location 4300. Thus, a reference to byte 53 of segment 2 is mapped onto location 4300 + 53 = 4353. A reference to segment 3, byte 852, is mapped to 3200 (the base of segment 3) + 852 = 4052. A reference to byte 1222 of segment 0 would result in a trap to the operating system, as this segment is only 1000 bytes long.

  30. paging Paging: is another memory management scheme that permit the physical address space of a process to be non contiguous. • Paging avoid the external fragmentation and the need of compaction. • Solve the problem of fitting memory chunks of varying size into the backing store. • paging implemented by the corporation between the operating system and the computer hardware.

  31. Paging implementation • The physical memory divided into fixed size blocks called frames. • the logical memory divided into fixed size of blocks called pages. • When a process is to be executed, its pages are loaded into any available memory frames • The backing store is divided into fixed-sized blocks that are the same size as the memory frames. • as shown in following diagram, every address generated by CPU is divided into two parts: • Page number (p) • Page offset (d)

  32. Paging hardware • The page number(p) used as index to page table. • The page table contain the base address of each page in physical memory. • The base address combined with the page offset to generate the physical memory address that is sent to memory unit.

  33. Paging model of logical and physical memory • The page size like frame size and defined by hardware. • The size of page is power of 2 and varying between 512 bytes and 1 GB per page, depending on computer architecture. • the size of logical address space is 2 power of m ( ). • the size of page is 2 power of n bytes ( ).

  34. Example : • consider the memory logical address, n= 2 , m = 4 Using a page size of 4 bytes and a physical memory of 32 bytes (8 pages). • Logical address 0 is page 0, offset 0. therefore Indexing into the page table, we find that page 0 is in frame 5. • logical address 0 maps to physical address 20 =[(5 × 4) +0]. • Logical address 3 (page 0, offset 3) maps to physical address 23 =[ (5 × 4) +3]. • Logical address 4 is page 1, offset 0; according to the page table, page 1 is mapped to frame 6. • logical address 4 maps to physical address 24 =[ (6*4)+0].

  35. Paging example for a 32-byte memory with 4-byte pages.

  36. Q1: what we men by: Input queue , stall ---- slide 3 Binding --- slide 4 Logical address , physical address, Logical address space, physical address space. Slide 6 Q: explain instruction and data binding in memory with diagram. Slide 4 -5 Or: what are the three stages of instruction binding in memory? Explain with diagram. Q:explain logical vs physical address slide 7-8 Q: what we mean by Memory management unit? Explain with diagram. Slide 8-9 Q: explain dynamic loading. Slide 10

  37. Q: explain dynamic linking? Slide 11. Q: define: static linking? Dynamic linking? Stub? Slide 11 . Q: explain overlays? Or define overlays . Slide 12 Q: explain swapping with diagram? Slide 13-14. Or: define swapping. Or explain swapping? Slide 13-14 Q:explain contiguous memory allocation with diagrams. Slide 15-18 Q: explain single partition allocation and multiple partition allocation.(slide 15-18) Q:define transient operating-system code slide 16. Q:define holes? Slide 18. Q:explain strategies used to select free hole in dynamic memory allocation? With numeric example. Slide 19-20 Q:what are types of fragmentation? Slide 21-22 Q: what are the approaches used to reduce external fragmentation explain with diagram. Slide 21-35 Q:what we mean by segmentation? Explain hardware segmentation with diagram. Slide 24 -28

  38. Q:what we mean by paging? Explain paging implementation. With example slide 30-35

  39. Q1: define • Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program. • Stallmean that CPU does not have required data to complete the instruction that it is executing. And it is solved by adding memory between CPU and Main Memory such as Cache. • binding : mean that it is a mapping from one address space to another address space. • Logical address –generated by the CPU; also referred to as virtual address. • Physical address – address seen by the memory unit. And loaded into Memory address register. • Logical address space is the set of all logical addresses generated by a program. • Physical address space is the set of all physical addresses corresponding to logical address .

  40. define : • transient operating-system code: it is a code not commonly used, we do not want to keep the code and data in memory, as we might be able to use that space for other purposes. Such code is sometimes called transient operating-system code; it comes and goes as needed. Thus, using this code changes the size of the operating system duringprogram execution. • Hole – block of available memory; holes of various size are scattered throughout memory

  41. Q2:Explain Binding of Instructions and Data to Memory. Q2:what are the three stages of instruction binding in memory? Explain with diagram • Address binding of instructions and data to memory addresses canhappen at three different stages: • binding : mean that it is a mapping from one address space to another. • Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes. • Load time: Must generate relocatable code if memory location is not known at compile time. final binding delayed until load time. • Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). • symbolic address in source program such as (count)converted to re locatable address by compiler such as (14 bytes) the linkage editor or loader bind the relocatable address to absolute address such 740

  42. Multistep Processing of a User Program

  43. Q3what we mean by Memory management unit? Explain with diagram • Hardware device that maps virtual address to physical address. • In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory. • The user program deals with logical addresses; it never sees the real physical addresses. • Execution-time binding occurs when reference is made to location in memory. • Logical address bound to physical addresses.

  44. Dynamic relocation using a relocation register

  45. Q4:explain overlays? Or define overlays • Keep in memory only those instructions and data that are needed at any given time. • Needed when process is larger than amount of memory allocated to it. • Implemented by user, no special support needed from operating system, programming design of overlay structure is complex.

  46. Q5:define swapping. Or explain swapping? • A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. • Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images. • Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed. • Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped. • Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows. • System maintains a ready queue of ready-to-run processes which have memory images on disk • Does the swapped out process need to swap back in to same physical addresses? Depends on address binding method

  47. Schematic View of Swapping

  48. Q6:explain contiguous memory allocation with diagrams .Q6: explain single partition allocation and multiple partition allocation • Main memory usually divided into two partitions: • Resident operating system, usually held in low memory with interrupt vector. • User processes then held in high memory. • Single-partition allocation • Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. • Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register. • MMU maps logical address dynamically.

  49. Cont. • usually want several user processes to reside in memory at the same time. • therefore need to consider how to allocate available memory to the processes that are in the input queue waiting to be brought into memory. • In contiguous memory allocation, each process is contained in a single section of memory that is contiguous to the section containing the next process. • The relocation-register scheme provides an effective way to allow the operating system’s size to change dynamically(Flexibility). • For example, If a device driver (or other operating-system service)is not commonly used, we do not want to keep the code and data in memory, as we might be able to use that space for other purposes. Such code is sometimes called transient operating-system code; it comes and goes as needed. Thus, using this code changes the size of the operating system duringprogram execution.

  50. Hardware Support for Relocation and Limit Registers

More Related