0

I know that:

The virtual memory is split into user-space and kernel-space, and is mapped into the physical memory. When a user process accesses a file the kernel will cache the file into memory, before giving access to process (page cache).

However

Will the memory space of page cache be limited by the kernel space? or which thing will limit the page cache size except config in linux?

danvid
  • 3

1 Answers1

3

The page cache is stored in RAM. In principle, it can fill the entire physical memory. The reason that it does not, is that memory is also used for other purposes.

"Anonymous" (swap-backed) memory allocations compete with the file-backed allocations of the page cache. The two are balanced by the memory management code. The exact behaviour of the memory management is ferociously complicated. When there is no free RAM for a new page allocation, Linux will choose whether to evict an old swap-backed page, or an old file-backed page. The balance of this choice can be tuned using the vm.swappiness configuration value.

Some architectures supported by Linux are starved for virtual address space (only 32 or even 31 bits :-). This does not limit the size of the page cache. The page cache is explicitly written to support using temporary virtual mappings. Look at the primary source: https://www.kernel.org/doc/html/latest/vm/highmem.html

Other uses of memory are

  1. unevictable non-cache allocations. E.g. the kernel code. These allocations also include in-kernel allocations made with kmalloc(), which are (mostly?) shown as "slab" allocations. There are other types as well.

    An example of unevictable memory allocations which can grow very large overall, are kernel network buffers.

  2. the "watermark" memory. This is reserved, to make progress in memory management while under pressure. For example, I believe these reserves may be used when the watermark is reached, and some memory is required in to write an old anonymous page to swap, to make space for something else. Typically the reserves might be 1-3% of memory (and less on larger systems). How large are the "watermark" memory reservations on my system? The reason why this might appear as large as 3% on a small system, has to do with "transparent huge pages".

sourcejedi
  • 50,249