Hi Everyone,
I'd like to learn more about how FreeBSD manages memory, specifically about the types of memory that top shows. I've read a few articles on the topic, also Chapter 7 in the Architecture Handbook. The following is my current understanding on the subject. Please clarify if I got something wrong:
Does this summary line up with reality? I'm particularly concerned about Buffers and ARC. My understanding is that Buffers and Laundry belong to the filesystem cache under UFS, both backed by vnodes; Laundry being pages whose content have changed in memory. But on my ZFS system I still have Laundry in addition to ARC. If ARC replaced Buffers, what is Laundry doing?
Please make any comments/corrections to the above. Thanks!
I'd like to learn more about how FreeBSD manages memory, specifically about the types of memory that top shows. I've read a few articles on the topic, also Chapter 7 in the Architecture Handbook. The following is my current understanding on the subject. Please clarify if I got something wrong:
FreeBSD manages memory in 4kB units called pages. These pages exist either in RAM or on the swap device. Each page can be in one of the following states, showed in the output of top:
Wired Pages that must be kept in RAM at all times. Kernel memory is always wired. Active Allocated memory which has been accessed recently by a process. Since a recent access makes future accesses more likely, the memory manager tries to keep Active pages in RAM, but they may be moved out to swap when RAM is filling up. Doing so will likely incur heavy performance penalties. Inactive Allocated memory which has not been accessed recently by any process. These pages may be moved out to swap, and the expected cost is much lower than for active pages. Buffers Pages that represent the content of a file on the hard disk or other non-volatile storage device. This redundant information exists only to speed up filesystem access if enough RAM is available. When RAM becomes scarce, then buffers can be deallocated any time, therefore they are regarded as free memory. ARC ARC replaces Buffers for systems using ZFS. The Total field shows the number of wired bytes in ARC. MRU stands for Most Recently Used, MFU stands for Most Frequently Used data. There's also the Anon, Header and Other fields, which I have no clue about. Laundry Pages assigned to a file whose content has been modified since it was read from the disk, or it has not been stored on the disk yet. Laundry pages must be written back to the filesystem before they can be deallocated. They may count as free memory, though their availability may depend on how quickly they can be backed up. Free Free memory.
This description implies that determining which memory pages are considered free at any time is not that straightforward: inactive pages are allocated, but they may be moved out to swap, whereas laundry pages should become free soon, but they have to be written back to disk first. In general, we should regard Wired, Active, Inactive and ARC pages as used memory, whereas Buffers, Laundry and Free comprise free memory.
Top also shows the allocated memory for each process. RES shows the number of bytes which is currently present in physical RAM on behalf of the process. SIZE shows the total memory size that the process is able to address. This memory does not need to reside in physical RAM, and it can be shared among different processes; for example shared libraries are counted for each process that links to them.
Does this summary line up with reality? I'm particularly concerned about Buffers and ARC. My understanding is that Buffers and Laundry belong to the filesystem cache under UFS, both backed by vnodes; Laundry being pages whose content have changed in memory. But on my ZFS system I still have Laundry in addition to ARC. If ARC replaced Buffers, what is Laundry doing?
Please make any comments/corrections to the above. Thanks!