Memory Addressing
A number that is assigned to each byte in a computer's memory that the CPU uses to track where data and instructions are stored in RAM. The computer's CPU uses the address bus to communicate which memory address it wants to access, and the memory controller reads the address and then puts the data stored in that memory address back onto the address bus for the CPU to use.
Memory Protection
Each process in the system has its own virtual address space. These virtual address spaces are completely separate from each other and so a process running one application cannot affect another. The hardware virtual memory mechanisms allow areas of memory to be protected against writing. This protects code and data from being overwritten by other applications.
Memory Mapping
Memory mapping is used to map data into a process's address space. In memory mapping, the contents of a file are linked directly into the virtual address space of a process.
Memory Addressing
In a system with virtual memory, the main memory acts like a cache for the disk. The entire main memory is a single address set. Any page can be placed anywhere in the main memory with a tag and an offset.
The tag field identifies a page number in the logical address space. The offset field identifies the location within a page for a memory address. The tag field is also called the page number.
An Example
A computer uses 32-bit byte addressing. The computer uses paged virtual memory with 4KB pages. Calculate the number of bits in the page number and offset fields of a logical address.
Answer
Since there are 4K bytes in a cache block,
the offset field must contain 12 bits (2^12 = 4K).
The remaining 20 bits are page number bits.
Thus a logical address format is
page number(20bits) + offset (12bits) = 32 bits
Page Tables
Virtual memory address translation uses page tables. These are simple arrays in memory indexed by page number. Each page table entry contains information about a single page. Page tables translate logical address to form a physical address.
Paging
Paging makes inactive pages to be temporarily removed from physical memory if necessary and reloaded to main memory when needed .(page fault occurs)
Page fault
If a page referenced is not found in the main memory, a page fault will occur, and the pages read into physical memory from the disk again. This is called paging.
Advantages of using Virtual Memory
Virtual memory addressing enables programs to run from almost any location in the main memory. This means that it is possible to have many programs and their data in memory at the same time and to switch between them very quickly. CPU time is not wasted while a process performs disk I/O, waits for user input, or waits to resolve a page fault.
Demand Paging
In order to use physical memory efficiently, O/S only loads virtual pages that are currently being used by the executing program. For example, a database program running a query a database does not need to load the whole database into memory. This technique of only loading virtual pages into memory as they are accessed is known as demand paging.
Swapping
If a process needs to bring a virtual page into physical memory when there are no free physical pages available, the operating system makes room for this page by discarding another page from physical memory by saving in an image or data file.
Page Allocation and Deallocation
Processes running in the system demand physical pages in the system. Hence the operating system allocates pages and deallocates (discard/freed) when the process is finished executing and unloading.
Q.1 In a virtual memory system, the addresses used by the programmer belong to
(A) memory space. (B) physical addresses. (C) address space. (D) main memory address.
Ans: C
An address used by programmers in a system supporting a virtual memory concept is called a virtual address and the set of such addresses is called address space.
Memory segmentation is the division of a computer's primary memory into sections. The reference to a memory location includes a value that identifies a segment (page) and an offset within that segment. Different classes of memory are used for code and data of running processes. Certain segments may even be shared between programs/processes.
Define the function of the memory manager.
The part of the operating system that manages memory is called the memory manager. Its job is to keep track of which parts of memory are in use and which parts are not in use. It allocates memory to processes and de-allocates it, when they are terminated. It also manages to swap between the main memory and disk when the main memory has not enough space to hold all the processes.
Difference between logical address and physical address?
A physical address represents the actual location in the main memory, where instructions or data are loaded. An address generated by the CPU is commonly referred to as a logical address or virtual address. It is a reference to a memory location.
What is the difference between page and a frame?
Paging is a memory management scheme. Using this scheme, physical memory is divided into small equal fixed-size blocks called frames or page frames. Similarly, each process is divided into blocks called pages that are of the same size as page frames
What is paging in the operating system with examples?
What is paging in an operating system?
The operating system maintains a page table for each process. The page table holds the frame locations for each page of the process. It contains one entry for each page of the process.
Example:
On a paging system with 2^24 bytes of physical memory, 256 pages of logical address space, and a page size of 2^10 bytes, answer the following questions;
(i) How many bits are in a logical address?
The logical address space contains 256 = 2^8 bytes. So the total logical address space is 2^10 x 2^8 = 2^18 bytes. Therefore, an 18-bit address is required to cover a 2^18-byte address space.
(ii) How many bytes are in a page frame?
The page frame size is the same as the page size i.e. 2^10 bytes.
(iii) How many entries are in the page table?
A page table consists of one entry for each table. There are 256 pages in the logical address space. So there are 256 entries in the page table.