In computing, the term memory refers explicitly to system RAM.
You may think this should be relatively simple, with enough RAM allocated to each process.
The reality, however, as it often is, is more complex than that, though.
Contents
Historical Memory Use
In early computers, system RAM usage was that simple.
Applications requested the amount of RAM they needed.
This approach ran into several issues, though.
The first issue is cost vs. capacity.
In those days, system RAM was costly, so computers tended to have minimal RAM.
This causes issues if you have multiple applications running at once.
It also causes issues if you have extensive programs that need more RAM than is physically available.
The second issue was one of efficient manageability.
Large programs tended to need to manage their RAM usage.
The final issue was one of complexity.
Generally, the software would grab a continuous block of RAM.
This makes it easy to define where everything is stored and makes prefetching instructions more efficient.
Paging Virtual Memory
Virtual memory solves all of these issues or at least facilitates the solution.
Virtual memory adds an abstraction layer on top of the actual memory addresses.
The operating system itself controls this abstraction.
The operating system provides the requested virtual memory to an software in one continuous block.
At least, seems as if way from the applications view.
This allows the operating system to manage the RAM as efficiently as possible for all programs.
The virtual memory space provided to a program can be expanded or contracted as needed.
In reality, the operating system uses what space it has, wherever that may be.
Virtual memory incidentally offers a helpful security feature, memory isolation.
Paging is another critical feature enabled by the implementation of virtual memory.
Virtual memory is split into units of allocatable memory called pages.
Instead, some virtual memory address space can point to disk storage.
Is Paging a Bad Idea?
This generally requires something else to be swapped out.
A page table is needed to translate the virtual memory address to the physical memory address.
It is critically important that this paging table is never swapped out itself.
If it were, the operating system would then be unable to find the page file to check.
To enable this, a Pinned flag prevents certain pages from being swapped out to disk storage.
Thrashing
Under hefty RAM workloads, thrashing can occur.
The computer spends unreasonable time swapping data to and from the disk storage.
Thrashing prevents the computer from being able to perform much helpful work.
Software tends to have a minimum set of pages it needs in actual RAM to make meaningful progress.
Adjusting the code of the program can help to reduce its RAM requirements.
However, this is only possible for first-party applications in active development.
Conclusion
Virtual memory is an operating system abstraction of system RAM.
Instead of assigning applications physical address spaces in RAM, the operating system gives them virtual address spaces.
While this adds the requirement to track the translation of addresses, it offers multiple benefits.
For example, the operating system can manage RAM allocation more efficiently.
The operating system can also run more virtual memory than it has physical memory.
This approach can appear to expand the overall available RAM of a system.
It can undoubtedly prevent hard crashes from RAM exhaustion.
It can, however, cause performance issues such as thrashing if its relied on too heavily.