Lecture 11- Memory Management Flashcards
What are the Aims of Memory Management?
- To provide the memory space for concurrent processes
- To provide satisfactory performance
- To protect each process from each other
- To allow sharing of memory space
- To make the addressing of memory space transparent
What is Memory Addressability?
Memory space is limited by the width of the address bus.
- A 32-bit bus can reference 232 = 4.3Gbytes
Machine instructions cannot directly access the whole memory space.
The solution is to use register(s) to hold a base address
The address part of machine instructions is used as an offset from the base address. For example,
code base address: 1,000;
instruction: JMP 123;
effective address jumped to: 1,000 + 123 = 1,123
What is Single Process System?
- The system only run one process at a time
- Load process into free space in memory
What is Fixed Partition Memory?
- Divide memory into several partitions of fixed sizes
- Store each process in its own partition
- Each partition has unused space—internal fragmentation
- Internal fragmentation wastes space
- May not have a big enough partition to fit a process
What is Variable Partition Memory?
- Each process is allocated exact size of memory space
- Processes are loaded into contiguous memory until full
- When a process terminates, its space is freed up
- This may introduce “holes”—external fragmentation
- Adjacent fragmentations can be coalesced
What is Virtual memory?
- The memory seen by the OS is not the real memory
- Part of the available addresses are in fact located on the disc
- The OS uses the virtual space of addresses
- The virtual address is translated to the real address by the Memory Management Unit (MMU).
- The translation of addresses has to be very fast, therefore the MMU is implemented in hardware.
What are the Implementation issues?
- Reading data from the disc is much slower than reading data from the main memory.
- Moreover, normally the programs address memory entries that are closely located.
- Therefore, there is a danger of multiple consecutive disc
- references that would significantly slow down the work of the computer.
Solution to the problem:
- Recognise that some area in the disc is to be addressed by the program
- Move this area to the RAM.
What is Paging?
The virtual memory is partitioned into consecutive chunks of the same size. These chunks are called pages
Each page page correspond to a group of consecutive
addresses in the main memory called page frame.
When the currently running process references a page frame located on disc, page fault occurs.
In this case, one of page frames in the main memory should be swapped with the page frame being referenced.
What are Paging-related implementation issues?
Choosing the page size.
- Too large - the swapping will take a long time
- Too small - the swapping will be repeated often
- Usual page size is about 8K
Choosing the page replacement algorithm.
Many of the page frames are currently in the main memory
Which of them to swap with the frame on the disc?
The one that will not be referenced the longest time!
This way we can ensure that the expensive operation of swapping will not be repeated too often.
What is the Optimal page replacement algorithm?
- Input needed: for each page frame, the earliest future instruction referencing this frame.
- The page referenced by the latest instruction is sent to the disc.
- Impossible to implement in a real operating system due to the inherent impossibility to predict behaviour of a program
Why is The optimal algorithm is nevertheless useful?
Suppose you have a real page replacement algorithm and want to test its performance.
This is done by comparing it against the optimal algorithm.
But how do we supply the required information to the optimal algorithm?
We run the same program twice! On the first run all the
relevant information is gathered. On the second run the
actual test is performed.
What are the Principles of real page replacement algorithms?
The future behaviour is predicted according to the information about the past.
The line of reasoning: if a page has not been referenced a long time, it would not be referenced in the future.
This approach is logically ridiculous, yet it works.
We will consider two ways of its implementation
What is the Not Recently Used algorithm?
Each page frame is associated with a bit whose 0 value means this frame has not been referenced yet, the bit is set to 1 when the frame is referenced.
The page to be swapped is selected randomly among those associated with 0 bit.
In a time the bits of most frames become 1.
When this happens, all bits are reset to 0. Why?
Obvious disadvantages: crude selection and the need to reset the bits
What is the Least Recently Used algorithm?
The system maintains a 64 bits counter that is incremented with each CPU instruction. BTW such counter is never overflown. Why?
Each page is associated with 64 bits register.
When the frame is referenced, the value of the counter is
copied to the register.
The frame associated with the smallest value of the register is swapped.
What is the important remark?
Processes can use shared memory, e.g.
printer spooler. But that memory belongs to the shared
resource, not to the own space of the processes.