> For the complete documentation index, see [llms.txt](https://chunhthanhde.gitbook.io/google-learning-programs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chunhthanhde.gitbook.io/google-learning-programs/google-it-support-professional-certificate/course-1-technical-support-fundamentals/module-3-operating-system/1.what-is-an-operating-system/5.memory-management-and-virtual-memory.md).

# Memory Management and Virtual Memory

🖥️ When a **process** runs, it requires both **CPU time** and **memory**. Processes need space in memory (RAM) for fast access and execution. However, memory is limited compared to storage space on hard drives, so we use **virtual memory** to extend available memory.

***

## Virtual Memory

💾 **Virtual memory** is a combination of **hard drive space** and **RAM** that acts like additional memory for processes. This allows us to run more processes than the physical memory can accommodate.

***

## Pages and Swapping

📦 A program's data is divided into chunks called **pages**, which are stored in virtual memory. When a process needs to execute, its pages are swapped between virtual memory and RAM.

❓ **Why not store everything in RAM?**

* Small programs can fit in RAM, but for larger applications, it would be inefficient to load all features into memory at once.
* Only the necessary pages are loaded, like reading just the relevant pages from a recipe book.

⏱️ If you experience a slowdown when accessing an infrequently used feature, it’s because the system is loading that page from virtual memory into RAM.

***

## Swap Space

📁 **Swap space** is the area of the hard drive designated to store virtual memory. In disk partitioning, we allocate specific space for swap, which helps manage virtual memory effectively.

🔧 The **kernel** coordinates the swapping of pages between RAM and virtual memory, ensuring efficient memory operations.

***

## Keep Exploring

👏 You've made great progress! Continue learning about **memory management**, **virtual memory algorithms**, and **disk partitioning techniques** to deepen your understanding.
