See here for more information about paging
ZZUNGS opened this issue · 1 comments
Paging is a method of writing and reading data from a secondary storage(Drive) for use in primary storage(RAM). When a computer runs out of RAM, the operating system (OS) will move pages of memory over to the computer’s hard disk to free up RAM for other processes. This ensures that the operating system will never run out of memory and crash. Too much reliance on memory paging can impair performance, however, because random access memory operates much faster than disk memory. This means the operating system has to wait for the disk to catch up every time a page is swapped; the more a work.
How Does It Work?
The OS reads data from blocks called pages, all of which have identical size. In order to do so, the OS first needs to consult the page table which is used by virtual memory to store the mapping between virtual addresses and physical addresses. The physical part of the memory containing a single page is called a frame. When paging is used, a frame does not have to comprise a single physically contiguous region in storage. This approach offers an advantage over earlier memory management methods, because it facilitates more efficient and faster use of storage.
When a program tries to access a page that is not stored in RAM, the processor treats this action as a page fault. When this occurs the operating system must:
- Determine the location of the data on disk.
- Obtain an empty page frame in RAM to use as a container for the data.
- Load the requested data into the available page frame.
- Update the page table to refer to the new page frame.
- Return control to the program, transparently retrying the instruction that caused the page fault.
When all page frames are in use, the operating system must select a page frame to reuse for the page the program now needs. If the evicted page frame was dynamically allocated by a program to hold data, or if a program modified it since it was read into RAM, it must be written out to disk before being freed. If a program later references the evicted page, another page fault occurs and the page must be read back into RAM.
Pros:
By diving the memory into fix blocks, it eliminates the issue of External Fragmentation. It also supports Multiprogramming. Overheads that come with compaction during relocation are eliminated. Easy to swap since everything is the same size, which is usually the same size as disk blocks to and from which pages are swapped.
Cons:
Paging increases the price of computer hardware, as page addresses are mapped to hardware. Memory is forced to store variables like page tables. Some memory space stays unused when available blocks are not sufficient for address space for jobs to run. Since the physical memory is split into equal sizes, it allows for internal fragmentation.
How To Make Paging More Efficient
Every time the OS is translating from logical to physical, it requires a look up in the page table, which is stored in RAM. Meaning every process request would require two physical memory accesses. This issue greatly reduces the overall performance of our equipment.
In order to tackle this problem we use the Translation Lookaside Buffer(TLB). The TLB is a memory cache that stores recent translations of virtual memory to physical addresses for faster retrieval.
thank you!