logo
logo
Sign in

What Is Linux Memory Management?

avatar
Peter Daniel
What Is Linux Memory Management?

The Linux memory management subsystem takes care of memory management, which is exactly what its name says it does. There are a lot of cool features like virtual memory and demand paging, memory allocation for internal kernel structures and user space programs, mapping files into the address space of a process, etc. Linux's system for managing memory is advanced and very flexible.


Overview:

Linux's memory management is a complex system that has grown to work with a wide range of hardware, from microcontrollers without a memory management unit (MMU) to supercomputers. It needs its own document, which hopefully will be written in the future. But even though some terms and ideas are the same, it is assumed here that there is an MMU and that a CPU can change a virtual address to a physical address.



  • Huge Pages
  • Virtual Memory Primer
  • Zones
  • Page Cache
  • Nodes
  • Anonymous Memory
  • OOM killer
  • Compaction
  • Reclaim


Huge Pages

To address translation, you must read and write to memory more than once. Compared to how fast the CPU can process data, these memory accesses are very slow. CPUs keep a cache of these translations, called a Translation Lookaside Buffer, so they don't have to waste valuable processing cycles on the address translation (TLB).


A Guide to Virtual Memory

A computer's physical memory can only hold a certain amount of data. Memory can't always be accessed in one big chunk. Sometimes, it may be given out as a group of subnets that work together as a single address. Also, different CPU architectures and implementations of the same architecture have different ideas about defining these ranges.


Virtual memory was set up as a way to avoid having to deal with the complexity of physical memory directly. In the program context, virtual memory hides the details of how physical memory works. It ensures that only the most important information is stored in physical memory. It allows data to be sent between processes in a secure way that doesn't compromise privacy.


Zones: Linux divides its memory into "zones," or groups of pages, based on what they might be used for. In this example, we'll say that ZONE HIGHMEM is a memory that isn't permanently mapped into the kernel's address space, ZONE DMA is a memory that may be used by different devices for DMA, and ZONE NORMAL is a memory that is addressed normally.


Page Cache

Due to the way physical memory works, the most common way to load data into RAM is by reading from files. When a file is read, the information is stored in the page cache so that the computer doesn't have to go to the disc repeatedly. When a file is written, just like when it is read, its contents are temporarily stored in memory before being stored permanently on the file's device.


Nodes

NUMA, "Non-Uniform Memory Access," is a computer architecture that includes machines with more than one processor. In these kinds of systems, the RAM is split up into "banks," and each bank has its own access latency based on how close it is to the CPU. Linux sets up a separate memory management subsystem for each node, which is a group of banks. Each node stores a set of zones, a running count of how many pages are being used and how many are free, and various statistics counters.


The memory of Anonymous

"Anonymous mapping" or "anonymous memory" are terms for storage that are not tied to a specific file system. These mappings are made either automatically for the program's heap and stack or explicitly by calling the mmap(2) system call. Most of the time, the anonymous mappings only do one thing: they tell the program where it can go in virtual memory.


OOM killer

There is a chance that all of the memory on the machine will be used up before the kernel can free up enough space for further implementation.


Compaction

Partitions are made when memory is given and taken away as needed while the system runs. But you can use virtual memory to get these loosely held physical pages to stay together. The most important part of partitioning challenges is memory compression.


Reclaim

Linux's memory management changes how a page is handled based on its use. Pages on a hard drive that can be reclaimed are those that are used as a cache for information that is stored elsewhere on the drive or can be swapped back in.


Conclusion:

Virtual memory is a memory that doesn't exist in the real world but that the kernel can access. Data pages changed by a process are marked as "dirty" and can either be rewritten to memory or "flushed."

collect
0
avatar
Peter Daniel
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more