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)
  • which virtual address space a physical page belongs to (unnecessary on a single address space operating system)
  • the supervisor bit
  • 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]

  1. Albert Kwon, Udit Dhawan, Jonathan M. Smith, Thomas F. Knight, Jr., and André DeHon."Low-Fat Pointers: Compact Encoding and Efficient Gate-Level Implementation of Fat Pointers for Spatial Safety and Capability-based Security".2013.
Microprocessor Design/Virtual Memory - Wikibooks, open books for an open world (2024)

FAQs

What is virtual memory in microprocessor? ›

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.

Is virtual memory the same as RAM? ›

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.

How do I increase virtual memory in Windows 11? ›

Procedure
  1. 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.
  2. Adjust the virtual memory setting.
Jan 13, 2023

Where is virtual memory located Windows 10? ›

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.

What is the purpose of virtual memory? ›

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 the virtual memory work? ›

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.

Can virtual memory be bigger than RAM? ›

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".

How much virtual memory 16gb RAM? ›

The initial size would be 1.5 x 4,096 = 6,144 MB and the maximum size would be 3 x 6,144 = 18,432 MB.

Can I use an SD card as virtual RAM? ›

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.

How do I manually increase virtual memory? ›

How to Increase Your Virtual Memory
  1. Head to Control Panel > System and Security > System.
  2. Select Advanced System Settings to open your System Properties. Now open the Advanced tab.
  3. Under Performance, select Settings. Open the Advanced tab. Under Virtual memory, select Change. Here are your Virtual Memory options.

How much virtual memory should I set for 8GB RAM? ›

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.

How do I set virtual memory for best performance? ›

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.

How much virtual memory should I set for 64gb RAM? ›

Microsoft recommends that you set virtual memory to be no less than 1.5 times and no more than 3 times the amount of RAM on your computer.

What is the recommended size of virtual memory for Windows 10? ›

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.

What is the default Windows virtual memory? ›

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.

What problem can virtual memory cause? ›

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.

Is virtual memory still needed? ›

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.

What is a disadvantage of virtual memory? ›

Disadvantages of 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.

Do all computers have virtual memory? ›

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.

How much storage does virtual RAM take? ›

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.

How many virtual machines can I run on 16GB RAM? ›

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.

What is the maximum RAM per virtual machine? ›

The maximum ram of a Linux VM is limited to 64 GB on Azure - Virtual Machines | Microsoft Learn.

How much virtual memory should I set for 16gb RAM mining? ›

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.

How do I create a virtual memory in Windows 10? ›

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.

What is the best page file size for 8gb RAM? ›

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.

Can I give all my RAM to virtual machine? ›

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).

Does RAM speed matter for virtual machines? ›

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.

What is the best RAM for virtual box? ›

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 if virtual memory is too high? ›

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.

Should you manually set virtual memory? ›

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.

How do I create a virtual memory? ›

  1. Right-click My Computer, and then click Properties.
  2. On the Advanced tab, click Settings under Startup and Recovery.
  3. Under System Startup, click Edit.
  4. Add space /3GB to end of last line of boot. ini file.
  5. Click on File>Save>Exit.
  6. Sample Boot. ini File Before and After Changing To Increase Virtual Memory.

How much RAM should I have to smoothly run a virtual machine? ›

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.

What should I set my virtual memory to if I have 4GB of RAM? ›

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).

How much base memory should I give my virtual machine? ›

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.

Can I use SSD as virtual memory? ›

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.

What is real and virtual memory in microprocessor? ›

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.

What is virtual and cache memory in microprocessor? ›

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.

What is use of virtual mode in microprocessor? ›

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.

What is the difference between paging and virtual memory? ›

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.

What is the problem with virtual memory? ›

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.

How do you implement virtual memory? ›

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.

How do I set up virtual RAM? ›

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.

Is virtual memory the same as disk cache? ›

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.

What is the real mode of microprocessor? ›

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.

Which are the basic four operations performed by the microprocessor? ›

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.

How does a virtual machine use a CPU? ›

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.

What are the disadvantages of virtual memory? ›

Disadvantages of 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.
Jun 10, 2023

What are pages in virtual memory? ›

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.

What is the page size of virtual memory? ›

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.

References

Top Articles
Latest Posts
Article information

Author: Jonah Leffler

Last Updated:

Views: 5675

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Jonah Leffler

Birthday: 1997-10-27

Address: 8987 Kieth Ports, Luettgenland, CT 54657-9808

Phone: +2611128251586

Job: Mining Supervisor

Hobby: Worldbuilding, Electronics, Amateur radio, Skiing, Cycling, Jogging, Taxidermy

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.