I'm trying to understand how operating systems work. Right now I'm studying virtual memory. Here's my understanding: Memory is divided into fixed-size blocks called pages, which are not contiguous in memory but are treated as if they were. Page sizes are a power of 2. The operating system has the job of finding a page and returning its value to a process that requests it. It does this using the Memory Management Unit, a hardware component that divides virtual memory into pages and stores their virtual addresses. The MMU caches virtual addresses in the Translation Lookaside Buffer (TLB), which is a cache stored in the CPU cache that holds entries from the page table. The page table is content-addressable memory (CAM), which is the hardware equivalent of an associative array, and it contains mappings of virtual addresses to physical addresses. When memory is requested from CAM, it searches its entire table and then returns a value.
So the question I want to ask is, first of all, am I right in my understanding of virtual memory and paging? Second, what advantage does paging serve and how does it improve the performance of a computer?
2 replies to this topic
#1
Posted 13 September 2010 - 05:30 AM
Programming is a journey, not a destination.
|
|
|
#2
Posted 13 September 2010 - 06:32 AM
DarkLordofthePenguins said:
Here's my understanding: Memory is divided into fixed-size blocks called pages, which are not contiguous in memory but are treated as if they were. Page sizes are a power of 2. The operating system has the job of finding a page and returning its value to a process that requests it. It does this using the Memory Management Unit
DarkLordofthePenguins said:
the Memory Management Unit, a hardware component that divides virtual memory into pages and stores their virtual addresses.
DarkLordofthePenguins said:
The MMU caches virtual addresses in the Translation Lookaside Buffer (TLB), which is a cache stored in the CPU cache that holds entries from the page table. The page table is content-addressable memory (CAM), which is the hardware equivalent of an associative array, and it contains mappings of virtual addresses to physical addresses. When memory is requested from CAM, it searches its entire table and then returns a value.
DarkLordofthePenguins said:
So the question I want to ask is, first of all, am I right in my understanding of virtual memory and paging?
DarkLordofthePenguins said:
Second, what advantage does paging serve and how does it improve the performance of a computer?
If you do not have any virtual memory, you must precalculate the needed space for each program. For example you reserve from address 1000 to 2000 for the first program. The second program is stored between 2000 and 3000, and so on. What happens if the first program needs to allocate more memory than it was initially reserved ? will you deny the request, even if the area between 3000 and the end of memory is available ? or will you allow that programs have memory fragments dispersed through all the memory space ? Another problem is that each program could "see" the memory of the other programs.
Obviosly this is not good for any modern operating system. What paging adds in this case is:
- Space: every program has virtually all memory available
- Security: one program cannot access the memory area of other programs
For example, the first program uses 10 pages, and the operating system allocates these pages at address 1000. Another program is loaded. It uses 20 pages. The operating system removes the 10 pages used by the first program from the virtual address space and allocates the new 20 pages at address 1000 (the same address of the first program). When the operating system decides to switch the current process, it removes its pages from memory and remaps the pages of the other program.
If one of the processes requests more memory, the operating system searches a new free physical page and maps it just after the last used virtual page. Thus, the process sees a contiguous memory space all the time.
Another advantage of having pages is that you can assign rights independently to each page. So you can define some pages that the program can read but not write, other pages that cannot contain executable code, pages that are reserved for private use of the operating system...
Another advantage of paging is that you can have a mechanism that allows you to have more memory than you actually have (using a paging file or swap area in disk). Each page can be marked as present or not present. When some page is not used for a long period of time, the operating system writes the contents of this page to the disk and marks the page as not present. This means that the physical memory page is freed and available to other processes that need memory.
When a program tries to access a non present page, the MMU intercepts the access and tells the operating system that that page must be reloaded. Then, the OS reads the page from disk and marks it as present again so that the program can continue.
All this requires some processing time, but the advantages are worth it. Most of this things are totally transparent to the user and programs.
#3
Posted 24 September 2010 - 07:40 PM
As far as I know, the paging can save a lot of memory for the hard disk.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









