we use “Address” to detect those processes, but how? Is the address given by CPU same as the address in memory?
Absolutely, no. We have two kinds of address:
- Logical address(Virtual address): Is the address at which an item (memory cell, storage element, network host) appears to reside from the perspective of an executing application program.
- Physical address: Physical Address is a memory address that is represented in the form of a binary number on the address bus circuitry in order to enable the data bus to access a particular storage cell of main memory, or a register of memory mapped I/O device.
Target: Enable a process to be larger than the amount of memory allocated to it
- Keep in memory only those instructions and data that are needed at any given time.
- Implemented by user, no special support needed from operating system, programming design of overlay structure is complex.
What is Symbol Table(シンボルテーブル):
- Δ Symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier (a.k.a. symbol) in a program’s source code is associated with information relating to its declaration or appearance in the source.
- Each process is contained in a single contiguous section of memory, this mechanism is called “Contiguous Allocation”(“連続メモリ割り当て”).
- There are two partitions in the main memory:
- Resident operating system, usually held in low memory with interrupt vector(“割り込みベクタ”).
- User processes then held in high memory.
Memory is usually divided into two areas, one for the operating system and the other for user processes. The operating system can be located in low memory or high memory. The main factor affecting this decision is the location of the interrupt vector. Because the interrupt vector is usually located in low memory, programmers usually put the operating system page in low memory.
However, because those allocation is contiguous, how can we protect one process from one another ?
- Relocation Register: which contains value of smallest physical address.
- Limit Register: which contains range of logical addresses.
- Under the joint action of these two mechanisms, the MMU maps the logical address dynamically by adding the value in the relocation register, and each logical address must be less than the limit register (Limit Register can control the memory range of each process)
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. OS maintains information about:
- allocated partitions
- free partitions (hole)
How to satisfy a request of size n from a list of free 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.
Fragmentation (“フラグメンテーション”) :
- External Fragmentation(“外部断片化”): total memory space exists to satisfy a request, but it is not contiguous.
- Internal Fragmentation(“内部断片化”): allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.
Reduce external fragmentation by memory 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.
Compaction is one way to solve this problem, but there is another way is Paging, which is a classical method in modern OS.
- Divide physical memory (“物理アドレス”) into fixed-sized blocks called Frames(“フレイム”) (size is power of 2, between 512 bytes and 8192 bytes).
- Divide logical memory (“仮想/論理アドレス”) into blocks of same size called Pages(“ページ”).
Address generated by CPU is divided into:
- Page number (p) (“ページ番号”): used as an index into a page table which contains base address of each page in physical memory.
- Page offset (d) (“オフセット”): combined with base address to define the physical memory address that is sent to the memory unit.
Page 0 => page table (0,5) => Frame 5 Page 1 => page table (1,6) => Frame 6 … … “a” => (number, offset) = (0, 0) => page table (0,5) => [Frame 5, +0] = 4*5 + 0 “f” => (number, offset) = (1, 1) => page table (1,6) => [Frame 6, +1] = 4*5 + 1 … …
Paging is a form of dynamic relocation.
Every logical address is bound by the paging hardware to some physical address. Using paging is similar to using a table of base (or relocation) registers, one for each frame of memory.
Using paging scheme, there is no external fragmentation, but may be some internal fragmentation, because each page-size is usually 4 bytes long, and process may be leave some space.
Page table is kept in main memory.
- Page-table base register (PTBR) points to the page table.
- Page-table length register (PTLR) indicates size of the page table.
What is Hierarchical Page Tables?
Most modern computer systems support a large logical address space, in which the page table becomes excessively large.
So we would not want to allocate the page table contiguously in main memory, we break up the logical address space into multiple page tables.
An important aspect of paging is the clear separation between the user’s view of memory and the actual physical memory:
The difference between the user’s view of memory and the actual physical memory is reconciled by the address-translation hardware.
Memory segmentation is a computer (primary) memory management technique of division of a computer’s primary memory into segments or sections.
In a computer system using segmentation, a reference to a memory location includes a value that identifies a segment and an offset (memory location) within that segment.
The difference between Page and Segmentation
- A page is of fixed block size, and segmentation is of variable size.
- Page may lead to internal fragmentation, segmentation may lead to external fragmentation
Every segmentation has a Segment-table base register(STBR) and Segment-table length register(STLR).
Virtual memory is a technology of memory management in computer system. It makes the application think that it has continuous available memory (a continuous and complete address space), but in fact, it is usually divided into multiple physical memory fragments, and some of them are temporarily stored on the external disk storage for data exchange when necessary.
Compared with the system without virtual memory technology, the system using this technology makes the writing of large programs easier and the use of real physical memory (such as RAM) more efficient.
When there is no free frame: Page Replacement(ページ置換):
- What’s that mean?
Find some page in memory, but not really in use, swap it out.
- Prevent Page Fault(“ページフォールト”):
Prevent over-allocation of memory by modifying page-fault service routine to include page replacement.
Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory.
- Of course, we want lowest page fault rate.
- Paging Replacement Algorithm: FIFO, Least Recently Used, Counting (including LFU, MFU)
Benefits of virtual memory:
- Allows both parent and child process to initially share the same pages in memory.
- If either process modifies a shared page, it will modify a new page copied from the shared page.
- memory -mapped file:
- Allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory.
- A file is initially read using demand paging. A page-sized portion of the file is read from the file system into a physical page. Subsequent reads/writes to/from the file are treated as ordinary memory accesses.
- Fixed allocation:
If 100 frames and 5 processes, give each process 20 pages.
- Priority allocation:
According to the size of process. select for replacement a frame from a process with lower priority number.
- Global allocation:
One process can take a frame from another.
If another process has a old frame, you can replace that frame, but local allocate could only check it’s own frames’ status.
A process is busy swapping pages in and out. It will lead to:
- Low CPU utilization.
- OS thinks that it needs to increase the degree of multiprogramming. another process added to the system.
VCVina copyrights this specification. No part of this specification may be reproduced in any form or means, without the prior written consent of VCVina.