I am aware that this is simplified/generalized explanation, but top(1)
utility divides memory in FreeBSD into six pools- Active
, Inactive
, Wired
, Cache
, Buffers
and Free
. Example from top(1)
output:
Mem: 130M Active, 42M Inact, 51M Wired, 14M Cache, 34M Buf, 648K Free
Swap: 512M Total, 512M Free
Active
is used by running processes and Wired
is used mainly for kernel. Inactive
is memory from closed processes which is still cached in case it needs to be reused, Cache
is cached data, Buffers
is disk buffers(I guess it is similar to cached
in Linux free(1)
output(?)) and Free
is completely unused memory. Am I correct that FreeBSD kernel automatically allocates space from Inactive
, Cache
and Buffers
pools to Active
or Wired
if needed?
Best Answer
To make it short, active and wired is used memory that shouldn't or cannot be swapped out to free memory. While inactive can properly be swapped out, but is still owned (not freed) by a process or the kernel, so this is not heavily used memory, but still used.
New is laundry which is a list of dirty memory pages, which might needs to be written to the swap device. Either if dirty memory needed to be swapped or not, they it is added back into the inactive queue.
Wired memory is not supposed to be swapped, for safety (in case of the kernel) or for userland process optimisation (like ZFS). Wired memory is used for caches of filesystems, which might be freed by the kernel. At lest for ZFS this can be seen as mostly free memory.
Free memory is definitely free.
Cached (now deprecated, I guess) is ready to be freed, since it is already swapped out and only there for possible reallocation.
Buffer is used as a cache by most filesystems (UFS, FAT, ...) and is the amount of memory used by the filesystems. It can be actice, inactive or wired.
ARC (Adaptive Replacement Cache) is the cache used by ZFS and it is memory that can be freed when need.
From the FreeBSD Wiki on Memory
From The design and implementation of the FreeBSD operating system chapter 6.12 Page Replacement (Not fully accurate any more, but here for referenz of the old question):
To answer your original question
Active pages can become inactive if they were not used for some time. If the kernel swaps out an inactive page this page is moved to the cache list. Page in the cache list are not part of the virtual mapping of any process but can easily be reclaimed, as active or wired. Or when needed for I/O as a buffer cache.
Wired memory can not be swaped out of main memory. If it is wired by a process it needs to be unwired with the
munlock
call to become active memory again.Active, inactive and wired memory can be freed by the process or kernel and added to the free list.