Microprocessor Design/Virtual Memory - Wikibooks, open books for an open world (2024)
Microprocessor Design
Virtual Memory is a computer concept where the main memory is broken up into a series of individual pages. Those pages can be moved in memory as a unit, or they can even be moved to secondary storage to make room in main memory for new data. In essence, virtual memory allows a computer to use more RAM than it has available.
If a simple virtual==physical address path is adequate for your CPU, you don't need virtual memory.
Most processors have a very simple address path -- address bits come from the PC or some other programmer-visible register, or directly from some instruction, and they are directly applied to the address bus.
Many general-purpose processors have a more complex address path: user-level programs run as if they have a simple address path, but the physical address applied to the address bus is significantly different than the programmer-visible address.This enables virtual memory, memory protection, and other desirable features.
If your CPU needs to do this, then you need something to translate user-visible addresses to physical address -- either design the CPU to connect to some off-chip bank register or MMU (such as the 8722 MMU or the 68851 MMU) or design in an on-chip bank register or MMU.
You may want to do this in order to:
support various debug tools that trap on reads or writes to selected addresses.
allow access to more RAM (wider physical address) than the user-level address seems to support (banking)
support many different programs all in RAM at the same time at different physical RAM locations, even though they were all compiled to run at location 0x300.
allow a program to successfully read and write a large block of data using normal LOAD and STORE instructions as if it were all in RAM, even though the machine doesn't have that much RAM (paging with virtual memory)
support a "protected" supervisor-level system that can run buggy or malicious user-level code in an isolated sandbox at full speed without damaging other user-level programs or the supervisor system itself -- Popek and Goldberg virtualization, W xor X memory protection, etc.
or some combination of the above.
Contents
1 Implementation
2 Memory Accessing
3 Pages
4 Page Table
4.1 Page Faults
4.2 Translation Look-Aside Buffer
4.2.1 TLB entry
5 Further reading
Implementation[edit | edit source]
Virtual memory can be implemented both in hardware and (to a lesser degree) in software, although many modern implementations have both hard and soft components. We discuss virtual memory here because many modern PC and server processors have virtual memory capabilities built in.
Paging systems are designed to be transparent, that is, the (user-mode) programs running on the microprocessor do not need to be explicitly aware of the paging mechanism to operate correctly.
Many processor systems give pages certain qualifiers to specify what kinds of data can be stored in the page. For instance, many new processors specify whether a page contains instructions or data, so that data pages cannot be executed as instructions, and instructions cannot be corrupted by data writes (see W^X).
The hardware part of virtual memory is called the memory management unit (MMU).Most MMUs have a granularity of one page.
A few CPU designs use a more fine-grained access control to detect and prevent buffer overflow bugs, a common security vulnerability.[1]
Memory Accessing[edit | edit source]
Memory addresses correspond to a particular page, and an offset within that page. If a page is 212 bytes in a 32-bit computer, then the first 20 bits of the memory address are the page address, and the lower 12 bits are the offset of the data inside that page. The top 20 bits in this case will be separated from the address, and they will be replaced with the current physical address of that page. If the page does not exist in main memory, the processor (or the paging software) will retrieve the page from secondary storage, which can cause a significant delay.
Pages[edit | edit source]
A page is a basic unit of memory, typically several kilobytes or larger. A page may be moved in memory to different locations, or if it is not being used, it can frequently be moved to secondary storage instead. The area in the secondary storage is typically known as the page file, the "scratchpad", or something similar.
Page Table[edit | edit source]
The addresses of the various pages are stored in a paging table. The paging table itself can be stored in a memory unit inside the processor, or it can reside in a dedicated area of main memory.
Page Faults[edit | edit source]
A page fault occurs when the processor cannot find a page in the page table.
Translation Look-Aside Buffer[edit | edit source]
The translation look-aside buffer (TLB) is a small structure, similar to a cache, that stores the addresses of the most recently used pages. Looking up a page in the TLB is much faster than searching for the page in the page table. When the processor cannot find a particular page in the TLB, it is known as a "TLB Miss". When the TLB misses, the processor looks for the page in the page table. If the page is not in the table either, there is a page fault.
Notice that even though the TLB can be considered a kind of cache, caching part of the page table stored in main memory, it is a physically separate structure than the instruction cache or the data cache, and has several features not found in those caches.
TLB entry[edit | edit source]
The SRAM in the TLB can be seen as entirely composed of TLB entries.The format of the TLB entries in the TLB SRAM is fixed by the TLB hardware.The paging supervisor -- part of the operating system -- typically maintains a page table in main memory which stores the page table entries in exactly the same format as TLB entries.Each TLB entry contains:
the virtual address of a page (analogous to the "tag" in a cache)
the physical address of a page (analogous to the "data" in a cache)
While not essential, some TLB hardware has many other optional control and protection fields and flags in the TLB, including:
the no-execute bit (NX bit), used to implement W^X ("Write XOR Execute")
a "dirty bit" (also called the "modified bit"), set whenever there is a STORE written into that page, and typically cleared when the modified page is written to the backing store.
the writable bit, used to implement PaX, sometimes cleared and later set by the OS in order to implement copy-on-write (COW)
statistics on which TLB entries were most recently or most frequently used, used to decide which TLB entry to discard when loading a new TLB entry from main memory
statistics on which page was most recently or most frequently used, used to support LRU or more sophisticated page-replacement algorithms that decide which page currently in main memory to "page out" to the backing store when the OS needs to load some other page from the backing store into physical memory
The page table entries may include additional per-page fields that are not copied into the TLB entries, such as
the "pinned bit" (aka "fixed flag") that indicates that a page must stay in main memory -- the paging supervisor marks as pinned pages that must stay in main memory, including the paging supervisor executable code itself, the device drivers for the secondary storage devices on which pages are swapped out; interrupt handler executable code. Some data buffers are also pinned during I/O transactions during the time that devices outside the CPU read or write those buffers (direct memory access and I/O channel hardware).
a "present" bit (clear when that particular virtual page does not currently exist in physical main memory)
Further reading[edit | edit source]
Thomas W. Barr, Alan L. Cox, Scott Rixner. "Translation Caching: Skip, Don’t Walk (the Page Table)". describes the Intel x86-64 MMU cache, the AMD Page Walk Cache, 3 other MMU cache arrangements, and compares their performance.
Virtual memory is a common technique used in a computer's operating system (OS). Virtual memory uses both hardware and software to enable a computer to compensate for physical memory shortages, temporarily transferring data from random access memory (RAM) to disk storage.
Virtual memory is an area of a computer system's secondary memory storage space, such as an HDD or SSD, that acts as if it were a part of the system's RAM or primary memory. Ideally, the data needed to run applications is stored in RAM, where the CPU can quickly access it.
Access the System Properties settings. Go to Start > Run. Type sysdm.cpl and click OK. In the System Properties dialog box, click the Advanced tab. Under Performance, click Settings. In the Performance Options dialog box, click the Advanced tab.
Windows 10 virtual memory exists as a physical, hidden file on the hard disk called the page file: pagefile.sys. IT professionals should think of the virtual memory as using the hard disk for additional memory when there is not enough RAM for all process requests.
Virtual memory provides virtual address mapping between applications and hardware memory. Virtual memory provides many functions, including multitasking (multiple tasks executing at once on one CPU), allowing multiple processes to access the same shared library in memory, swapping, and others.
How does virtual memory work? Virtual memory uses both the computer's software and hardware to work. It transfers processes between the computer's RAM and hard disk by copying any files from the computer's RAM that aren't currently in use and moving them to the hard disk.
Virtual memory is usually much larger than physical memory, making it possible to run programs for which the total code plus data size is greater than the amount of RAM available. This is known as "demand paged virtual memory".
On Windows 10, you can use an SD card as virtual RAM in the same way you do with your hard drive; so, the answer to the question "can I use an SD card as RAM on Windows 10" is yes. Creating virtual RAM with an SD card on Windows 10 actually works similarly to how we described it for Android devices.
As a rule of thumb, the paging file should be a minimum of 1.5 times the size of your installed RAM, and a maximum of 3 times your RAM size. For example, if you have 8 GB RAM, your minumum would be 1024 x 8 x 1.5 = 12,288 MB, and your maximum would be 1024 x 8 x 3 = 24,576 MB.
Click Start > Settings > Control Panel. Double-click the System icon. In the System Properties dialog box, click the Advanced tab and click Performance Options. In the Performance Options dialog, under Virtual memory, click Change.
Note: Microsoft recommends that you set virtual memory to not less than 1.5 times the size of your RAM and not more than three times the size of your RAM. So, if you have 2GB of RAM, you could type 6,000MB (1GB equals around 1,000MB) into Initial size and Maximum size boxes. Finally, click Set and then OK.
In the default Windows configuration, 2 gigabytes (GB) of this virtual address space are designated for the private use of each process, and the other 2 GB is shared between all processes and the operating system.
Using virtual memory makes a computer run slower, as the processor has to wait while data is swapped between hard disk and RAM. As secondary storage devices have slower access times than RAM, the computer's processing performance can be severely impaired.
In this case, third-party software may experience the lack of virtual memory if we choose to disable the latter, especially for the software like PhotoShop. Therefore, no matter how large the capacity of RAM is, it's still necessary for us to enable the virtual memory.
Applications may run slower if the system is using virtual memory. Likely takes more time to switch between applications. Offers lesser hard drive space for your use. It reduces system stability.
Virtual memory is a common part of most operating systems on desktop computers. It has become so common because it provides a big benefit for users at a very low cost.
It works by converting some of the internal storage space to function as extra memory. For example, if a device has 6GB RAM and 128GB storage, the feature might use around 6GB of space and add it to the system memory.
As a general rule it's probably best to give every instance of Windows 10/11 4GB of memory, that includes the host OS so you could run 3 VM's with 16GB of RAM. If your host OS is only going to be used to run VM's then you can use Windows server core and that will run happily with just 2GB.
Most mining software requires at least 16 GB virtual memory. In systems with many GPU's, even more virtual memory is required to be able to work well with all mining software and algorithms. A good rule of thumb is to allocate 4 GB plus the total amount of memory on all GPU's.
Go to the Start Menu and click on Settings. Type performance. Choose Adjust the appearance and performance of Windows. In the new window, go to the Advanced tab and under the Virtual memory section, click on Change.
On most Windows 10 systems with 8 GB of RAM or more, the OS manages the size of the paging file nicely. The paging file is typically 1.25 GB on 8 GB systems, 2.5 GB on 16 GB systems and 5 GB on 32 GB systems. For systems with more RAM, you can make the paging file somewhat smaller.
You should give virtual machine however much RAM you need for the tasks you're using it to perform. If you're running a single virtual machine, the suggestion you read is OK (provided that your host machine has enough RAM, which it does).
If you want to run a virtualized environment, you should put the emphasis on more (as in, several) rather than big (as in, powerful or fast). In other words, more cores are better than big/fast cores. Likewise, more Random Access Memory (RAM) is preferable to better/faster RAM.
512MB is simply the default recommended amount. If you have a need for the virtual machine to have more then 512MB then increase the amount. The default value has to be something and the developers choose 512MB.
What happens with too much virtual memory? However, users should not overly rely on virtual memory, since it is considerably slower than RAM. If the OS has to swap data between virtual memory and RAM too often, the computer will begin to slow down -- this is called thrashing.
Manual adjustments to this setting are done at your own risk, and this should not be attempted unless you have solid guidelines about what you actually need. Under-allocating space for virtual memory can lead to programs or your system as a whole malfunctioning.
With virtual machines RAM is user configurable. For decent performance at least 8GB would be recommended if you have a computer with 16GB or more. Linux in general works best with at least 4GB of RAM, but it all depends on the workload.
The Page File should be approximately 1.5 - 2 times the size of your total system memory (RAM). A computer with 4GB of RAM will need a Page File a minimum of 6GB (6144 MB) and a maximum of 8GB (8192MB).
VirtualBox recommends that the memory size be at least 512MB, however, the more memory you make available to the VM, the smoother and more powerful it will be. As a rule of thumb, 1/4 of the amount of memory you have on your computer should be just fine.
Using an SSD as the storage device for virtual machine swap files allows you to make use of memory overcommitment without taking a big hit in performance. While SSDs do not offer the same performance as RAM, they are a big improvement over mechanical drives.
Physical memory, which is the actual RAM, is a form of computer data storage that stores the currently executing programs. In contrast, virtual memory is a memory management technique that creates an illusion to users of larger physical memory. Thus, this is the main difference between physical and virtual memory.
Cache memory is a type of memory that stores frequently used data and instructions so that they can be quickly accessed by the processor. Virtual memory is a type of memory that allows a computer to use more memory than is physically available in the system.
Overview. The virtual 8086 mode is a mode for a protected-mode task. Consequently, the processor can switch between VM86 and non-VM86 tasks, enabling multitasking legacy (DOS) applications.
Virtual-memory segments are partitioned in units called pages. A paging space is a type of logical volume with allocated disk space that stores information which is resident in virtual memory but is not currently being accessed.
Using virtual memory makes a computer run slower, as the processor has to wait while data is swapped between hard disk and RAM. As secondary storage devices have slower access times than RAM, the computer's processing performance can be severely impaired.
Virtual memory is commonly implemented by demand paging. It can also be implemented in a segmentation system. Demand segmentation can also be used to provide virtual memory.
Click Start > Settings > Control Panel. Double-click the System icon. In the System Properties dialog box, click the Advanced tab and click Performance Options. In the Performance Options dialog, under Virtual memory, click Change.
Disk cache is a type of memory that is used to store frequently accessed data, while virtual memory is a type of memory that is used to store data that is not currently in use. Both of these types of memory are important for the efficient operation of a computer system.
Real mode is characterized by a 20-bit segmented memory address space (giving 1 MB of addressable memory) and unlimited direct software access to all addressable memory, I/O addresses and peripheral hardware. Real mode provides no support for memory protection, multitasking, or code privilege levels.
The microprocessor is the central unit of a computer system that performs arithmetic and logic operations, which generally include adding, subtracting, transferring numbers from one area to another, and comparing two numbers. It's often known simply as a processor, a central processing unit, or as a logic chip.
The CPU is responsible for executing the instructions that the virtual machine needs to run, and it is also responsible for managing the resources that the virtual machine needs to run. The CPU is also responsible for managing the memory and storage that the virtual machine needs to run.
A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in the page table. It is the smallest unit of data for memory management in a virtual memory operating system.
The idea behind virtual memory is that physical memory is divided into fixed size pages. Pages are typically 512 to 8192 bytes, with 4096 being a typical value.
Introduction: My name is Jonah Leffler, I am a determined, faithful, outstanding, inexpensive, cheerful, determined, smiling person who loves writing and wants to share my knowledge and understanding with you.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.