Memory management. Paging and segmentation Learning objective: 12.3.4.2 explain the principle of memory organization by segment and page I. Paging explained 1. Page Frames and Pages. Memory division. The physical memory (RAM) is divided into fixed-size units called page frames. Program/Data division. A program or data file is divided into equal-sized units called pages. Each page is the same size as a page frame. 2. Loading pages into memory. Dynamic loading. One or more pages of a program or data can be loaded into memory at any given time. This allows for efficient memory usage, as only the necessary parts of a program or data are loaded. 3. Discontiguous pages. Non-Contiguous Allocation. Pages of a program or data do not need to be stored in contiguous memory locations. This means that the pages can be scattered throughout the memory, which helps in reducing memory fragmentation. 4. Swapping pages. Demand paging. Pages are swapped in and out of memory as needed. If a page is required for execution and it is not in memory, it is loaded from the backing store (e.g., disk) into a free page frame. Page replacement. When memory is full, a page not currently in use is swapped out to make room for a new page. 5. Storage of non-resident pages. Virtual memory/backing store. Pages that are not in main memory are stored in virtual memory, which is typically a disk or another form of secondary storage. This allows for the illusion of having more memory than is physically available. 6. Page table. Tracking pages. A page table is maintained to keep track of the location of each page. The page table acts as an index, mapping virtual addresses to physical addresses. Process management. Each process has its own page table, which is used by the operating system to manage the memory of that process. 7. Address translation. Absolute address calculation. The absolute address (the actual physical memory address) is calculated by adding the page address (from the page table) to the relative address (the offset within the page) specified in an instruction. 8. Transparency to programmers. Paging is hidden. Paging is transparent to the programmer, meaning that the programmer does not need to be aware of the underlying memory management. The operating system handles the details of loading, swapping, and translating addresses, allowing the programmer to focus on the logic of the program. Summary: Paging is a memory management technique that divides memory into fixed-size pages and page frames, allowing for efficient use of memory and the illusion of larger memory space through virtual memory. It handles the loading, swapping, and tracking of pages transparently to the programmer, ensuring that programs can run smoothly without manual memory management. II. Segmentation explained 1. Variable-length blocks. Memory division. In segmentation, the memory is divided into variable-sized blocks called segments. Unlike paging, where memory is divided into fixed-size units, segmentation allows for more flexible memory allocation based on the needs of the program. 2. Program structure. Multiple segments. A program can be composed of multiple segments, each representing a different part of the program, such as code, data, stack, or heap. This aligns with the natural logical divisions within a program. 3. Natural division. Logical blocks. Segments typically correspond to the natural divisions or logical blocks within a job or program. For example, a segment might represent a function, a data structure, or a module. This makes it easier for programmers to manage and understand the program's memory organization. 4. Segment index. Storage of segment information. An index of segments is maintained, which contains crucial information about each segment. This index serves as a reference for the operating system to manage memory effectively. Base address. The index stores the base address of each segment, which is the starting address of the segment in memory. Length. It also stores the length of each segment, indicating the size of the segment. 5. Programmer's role. Organizing code. The programmer is responsible for organizing the code modules into segments. This involves deciding how to divide the program into logical units and specifying the segments' properties, such as their size and purpose. Memory management. By organizing code into segments, the programmer can manage memory more effectively, as each segment can be allocated and deallocated independently. 6. Advantages of segmentation. Flexibility. Segmentation allows for more flexible memory allocation, as segments can vary in size and can be allocated based on the program's needs. Protection and sharing. Segments can be protected from unauthorized access and can be shared between processes if needed, enhancing security and resource utilization. Modularity. Segmentation supports modular programming, as each segment can represent a separate module or component of the program. 7. Address translation. Segment addressing. When a program is executed, the operating system uses the segment index to translate logical addresses (segment number and offset) into physical addresses. This process is similar to paging but operates with variable-sized units. Summary: Segmentation is a memory management technique that divides memory into variable-sized segments, reflecting the natural divisions within a program. It provides flexibility, protection, and modularity, allowing programmers to organize code into logical blocks. The operating system maintains an index of segments, storing their base addresses and lengths, to manage memory effectively and translate logical addresses to physical addresses.
Page tables This, of course, all takes time and contributes to the computer slowing down. This kind of tracking system for pages is relatively simple to implement but there are some disadvantages. Segmentation Questions:
Exercises: Ex. 1 Fill the blanks (Designed by Mr. Halil Mali - CS teacher of NIS Uralsk) Ex. 2 Exam questions:
| |
| |
Просмотров: 6116 | | |
Всего комментариев: 0 | |