How does the operating system keep track of free frames?

Dani AI

Generated

Since asked which OS and confirmed Linux, here's a concise explanation of how Linux keeps track of free frames.

Physical memory is split into page frames (commonly 4 KiB). The kernel keeps a descriptor for every physical page (the struct page) that carries a reference count and status flags. When a page's reference count reaches zero and it is not otherwise reserved or locked, the page becomes eligible to be returned to the free pool.

Free pages are managed by the page allocator (the buddy allocator). Free pages are grouped by order (blocks of 2^n pages) and by memory zone (for example DMA/Normal/HighMem on some systems). The allocator maintains per-order free lists of struct page descriptors and splits or merges buddies to satisfy requests for single pages or contiguous runs. Per-CPU caches and fast paths reduce locking overhead on common allocations.

To know which frames are in use the kernel consults page tables and per-page metadata. Linux keeps reverse mappings so reclaim code can find all mappings for a physical page; it also maintains active/inactive (LRU) lists to choose victims for reclaim or swap. reclaim logic checks flags (dirty, locked), reference counts and page type (pagecache vs anonymous) before freeing frames back to the buddy lists.

Quick ways to inspect a running system:

cat /proc/meminfo        # overall counters (MemFree, Buffers, Cached)
cat /proc/buddyinfo      # buddy allocator free-block counts by order
free -h                  # human-friendly summary
# /proc/<pid>/pagemap is binary; parse it as root to map a VA -> PFN

Note: MemFree is only part of the picture — cached/buffered pages are usually reclaimable. For exact implementation details in your kernel version, inspect the mm sources (e.g. mm/page_alloc.c, mm/rmap.c).

Recommended Answers

All 2 Replies

What operating system?

os = linux

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.