From the man pages of proc(5)
:
AnonPages %lu (since Linux 2.6.18)
Non-file backed pages mapped into user-space page tables.
The way a process maps memory in Linux is usually using the mmap(2)
system call which "maps files or devices into memory".
The memory can be backed by an actual file in the disk, so you could handle a file as if it was a regular memory block.
However, you could also allocate empty memory section not backed by any file. Those memory pages are called "Anonymous". From the man page of mmap
:
MAP_ANONYMOUS
The mapping is not backed by any file; its contents are initialized to zero.
If you've ever programmed in C, you're probably familiar with malloc(3)
and used it to allocate dynamic memory. In Linux, in most cases, under the hood malloc
would actually call mmap
to allocate Anonymous memory pages.
AnonPages
shows the usage of the most common type of memory - dynamic memory areas that are used by process.
Note that allocating Anonymous pages using mmap
or malloc
will not necessarily be reflected immediately by the AnonPages
; When you allocate dynamic memory, you just get a virtual address space that you can use, but the memory pages do not actually "instantiate" and mapped into the user-space memory of the process until it starts using them (write or read to/from a memory). Only then those memory pages are loaded to the RAM and accounted by AnonPages
.
Simply put, AnonPages
represents the first thing that probably pops to your mind by default when you think about "memory" and "RAM". Just "regular" memory pages dynamically allocated for processes by their request, and used by those processes. There's nothing really to "fix". It's expected and quite common for AnonPages
to be the "top hitter".
You should just look for the processes that takes most amount of memory (for instance, using top
) and act accordingly. Maybe there's a process that consumes large amount of memory (RSS), or many processes that fill up the memory.