Search

A technology, a device or an article

Why free RAM pages cannot form every large block

Equal free RAM totals can hide different allocatable blocks. A constructive example explains buddy orders, alignment, zones and what compaction can change.

A wooden tray with scattered empty cells and dark inserts beside a long solid block
ITNWS AI-generated conceptual illustration. A material metaphor for scattered space and one contiguous block; not a memory module or an address map.ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

Let’s draw a strip of sixteen physical pages and number them from 0 to 15. In the first option, pages with even numbers are free, the rest are occupied. In the second, pages from 0 to 7 are free, the rest are occupied. The available space is the same: eight pages. But only in the second option can you immediately take a contiguous block of eight pages. Adding the free bytes more precisely cannot help the first layout. Summing the free bytes discarded their locations, precisely the information a large contiguous allocation needs.

This is a mental construct, not a snapshot of the editorial machine. It separates the capacity of RAM from the form of available space. For an ordinary virtual range, the program may not notice that neighboring addresses rely on spaced physical pages. But some kernel and device operations require different guarantees. If a physically contiguous block is needed, eight scattered pages do not become such a block because they occupy one “free” line in the report. The question lies in the property of the set of addresses, which a single capacity value cannot express.

The sum does not contain coordinates

Linux describes available blocks in /proc/buddyinfo. Manual proc_buddyinfo(5) sets the order block size with the formula 2^order · PAGE_SIZE. With a page of 4096 bytes, order 0 means 4096 bytes, order 1 means 8192, order 2 means 16384. Order 9 corresponds to 512 pages, that is, 2 MiB. The base page size needs to be known for the system under study: the number 4096 is an assumption of this example, and not a universal constant for all Linux platforms and all memory configurations.

Each column contains the number of free blocks of the corresponding order, not the number of bytes or the number of individual pages within all large blocks. To get the volume, you need to multiply the quantity by the size and add the products. One free block of order 3 already includes eight pages. With this representation, it cannot be additionally counted as four blocks of order 1 and eight blocks of order 0: this is multiple counting of the same memory. Splitting changes the representation of free space rather than creating new physical bytes.

In our strip, the first layout could have eight blocks of order 0 and no larger ones. The second is one block of order 3, without separate smaller free blocks. In both cases the weighted total is eight pages. An order-3 allocation request distinguishes between these states immediately. If the observation function left only the sum, it is impossible to restore the answer from it: one value corresponds to at least two layouts with different results. This is a simple proof of why total free volume is not sufficient to predict large contiguous allocation.

Now let’s reduce the requirement to order 0. Both layouts are capable of serving individual small requests under other acceptable conditions. The large block in the second option can be divided, obtaining the required smaller parts and keeping the remaining free. Consequently, the absence of free blocks in the low column does not in itself mean that a small allocation is impossible. We also need to look at higher orders, which can be broken down. Conversely, many lower-order blocks do not guarantee a higher-order block unless their physical arrangement allows for the required merging.

It is this asymmetry that the buddy allocator expresses. From one block it is easy to make two equal halves of the next smaller order. The reverse action requires that both corresponding halves be free and fit together. Adding two arbitrary equal-sized capacities is not enough. They may be far from each other or cross the boundary of a higher order pair. The algorithm has an address-based buddy relationship that does not turn into a simple equal-size test. The name buddy points to this address-based relationship.

The neighborhood still needs to match the alignment

Let’s take another drawing in the same illustrative strip. Four adjacent pages from 1 to 4 are free. There is enough length for four pages in a row, but a standard block of order 2 must start at the appropriate boundary: in our figure this is 0, 4, 8 or 12. The range 1–4 is not such an aligned block. Pair 2-3 can be merged, and pages 1 and 4 belong to other pairs. It is impossible to get one block of order 2 without changing the layout. Contiguity and the form served by a given allocator have separate requirements.

This is not to say that any four physically adjacent pages are generally useless. A different interface may solve a different problem and use a different organization. We analyze allocation of buddy blocks of a given order. The algorithm maintains a power-of-two structure that keeps split and join operations manageable. Trying to read its table as a catalog of all possible contiguous ranges creates unnecessary expectations. It represents specific free blocks, rather than the results of searching through each physical address with each allowable length.

Page positions also cannot be transferred directly to the appearance of the DIMM. The operating system’s physical addresses pass through the memory controller and hardware address mapping; logical contiguity of the address space does not literally describe adjacent chips or tracks on the board. Fragmentation in the sense discussed refers to the availability of address blocks. It does not mean that the RAM has cracked, deteriorated, or acquired a charge retention defect. Replacing the words "occupied space between vacant ones" with "defective site" would change the subject without any evidence.

Pencil-drawn rectangular blocks, a branching line and a stone between mismatched halves
ITNWS AI-generated conceptual illustration. An image of the buddy-pair merge condition. Colors and the stone are symbolic; this is not a numeric page layout. — ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

In a real system, one common list is also not enough because the memory is divided into nodes and zones. Linux Physical Memory documentation explains the organization of node and zone and the architectural reasons for the limitations. The buddyinfo line refers to a specific node and zone pair. A free large block in one area is not necessarily available to a request that is allowed in another. The sum for the entire machine can be correct and at the same time not answer the allocation question. You must preserve the memory domain permitted for the request before comparing its free blocks with the size of the request.

Therefore, even a found block of the required order is not an unconditional promise of success for an arbitrary call. The decision is influenced by watermarks, reserves, placement policies, flags, and current competing requests. Between observing and allocating, another job may pick up a suitable block. The table describes the state of a specific accounting interface and does not provide the caller with an exclusive reservation. It is also not a complete census of all possible sources of free pages, including local allocator caches. Useful analysis uses it in conjunction with the context of a particular request, not instead of it.

Memory Allocation Guide separately links allocator behavior to GFP flags. Some contexts allow waiting and direct reclaim, others prohibit such work. The failure of a fast request does not prove that a more patient operation could never have obtained the same size. But waiting is not allowed everywhere: a handler or code with special restrictions cannot arbitrarily begin long-term work. In this sense, block availability has a time dimension. For the system, it is important not only the existence of a possible future placement, but also the allowed cost of achieving it now.

Moving pages preserves data; freeing them changes ownership

Compaction attempts to improve the physical layout by moving suitable occupied pages and collecting free areas. The virtual addresses through which code uses them can be preserved during supported page migration, although the physical support changes. Thus, the original chess layout, with permitted page migrations, can turn into a more convenient one. But it is a job that requires time, destinations and the ability to migrate. The presence of a procedure does not prove that specific content can be moved at all in the current context. Unmovable or held pages can prevent the desired result.

Reclaim addresses a related but different issue: which pages can be freed from current use, for example by evicting suitable cached content. It is able to increase the free volume without necessarily immediately assembling the desired aligned block. Compaction is able to change placement with a similar total amount of free memory. These mechanisms interact, but the difference in their purpose is important for interpretation. If there is not enough total available memory, rearrangement alone cannot create the missing bytes. If there are bytes, additional release does not guarantee the desired geometry.

VM sysctl documentation describes compaction and its policy parameters. The mere fact of the availability of manual compaction does not make it a mandatory treatment for any failure. This action adds system work and may change the delays of other clients. It has not been performed here and is not offered as a universal recipe. To engineer a solution, you first need to establish the size, area, allocation context, and the real reason for the constraint. Otherwise, the cost of the intervention is paid before the question to which it is intended to change the answer is formulated.

The difference between virtual and physical contiguity opens up the possibility of changing the allocation requirement itself. If contiguous virtual addresses are sufficient for the consumer, an interface that maps noncontiguous physical pages may be suitable. The Linux manual distinguishes between kmalloc and vmalloc precisely because of these essential guarantees. But you can’t arbitrarily replace one with the other: devices, DMA mapping, valid contexts, and release rules have their own requirements. The choice of allocator is part of the contract with the consumer. This is not a cosmetic change to the function name after the first failed call.

Large pages also do not invalidate the original proof. A given large page will require appropriate physical placement, whereas an ordinary virtual range can exist on base pages. Failure to receive a large option does not always mean that it is impossible to work at all: some code paths can use a smaller format with a different address-translation cost. Others require a strictly defined form. You cannot generalize the conclusion from one case across all RAM allocations. First, it is determined whether a large block is a requirement or a preferred optimization with a feasible fallback path.

Gradual fragmentation also does not prove a leak. A leak refers to the loss of the ability to gracefully release an occupied resource, while external fragmentation refers to the placement of available space between occupied regions. They can coexist, but the presence of forgotten objects cannot be deduced from the disappearance of higher orders. Likewise, it is impossible to assess the health of DRAM using the beautiful buddyinfo table. This interface helps you understand the distribution of pages. It does not test cells, measure electrical parameters, or describe the entire fate of each byte of data.

Sources were checked on November 3, 2026; live documentation pages are not taken to describe the version of the kernel on the reader’s machine. The original strip still has eight free pages in both versions. The sum is correct and does not intentionally hide the differences – it simply does not contain coordinates. For RAM, capacity measures the amount of space, and a large physical block also requires a certain shape. This form cannot be returned to the argument by adding additional decimal places to the free gigabytes indicator.

Sources & documentation

  1. Linux man-pages: proc_buddyinfo(5) ↗
  2. Linux Memory Allocation Guide ↗
  3. Linux Physical Memory ↗
  4. Linux VM sysctl: compaction ↗