memory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
memory [2013/02/20 13:20] – s/Move/Moved KubilayKocakmemory [2018/09/06 01:59] (current) – MarkJohnston
Line 1: Line 1:
-A plain language description of the memory stats seen in places like top(8) and sysctl output, designed specifically for a non-developer audience.+A plain language description of the memory stats seen in places like top(1) and sysctl output, designed specifically for a non-developer audience.
  
-===== General =====+===== Overview =====
  
-Userland memory is generally either Anonymous (swap-backed) or (file-backed)+%%FreeBSD%%'s VM operates on memory in units of pages, which have a size of 4KB on most platforms.
  
-===== Memory Classes =====+%%FreeBSD%% uses a set of 3 queues to manage pageable memory.  The size of each queue (Active, Inactive, and Laundry) is visible in top(1).
  
-**Active** Queue +Pageable memory consists of anonymous memory and file data.  Anonymous memory has no dedicated backing storage, and will be written to the swap device if the memory needs to be reused for some other purpose.  If the swapped-out memory is referenced again, some free memory will be allocated, and the saved contents of the swapped-out memory will be read back in.  Examples of anonymous memory include but are not limited to:
-  * "Actively" (Recently) used by userland     +
-  * Moved to Inactive when act(ivity)_count=0 (by pagedaemon) +
-  * act_count is updated by hardware page access bits +
-  * "Second Chance" replacement algorithm+
  
-**Inactive** Queue +  * memory returned by malloc() to a userland application 
-  * Inactively (not recently used) used by userland +  * the contents of a MD device of type "swap" (see mdconfig(8%%))%% 
-  * Not recently used (LRU) +  * tmpfs filesystems 
-  * Cannot be re-allocated to other processes+  * %%SysV%% or POSIX shared memory segments
  
-**Cached** +File data is simply the cached contents of files, and file metadata.  In general, filesystems will maintain their own fixed-size cache of file data and metadata.  With UFS, msdosfs, NFS and others, this is called the "buffer cache"; with ZFS this is the ARC (adaptive replacement cache).  When memory is evicted from the buffer cache to make room for new data, it is placed in the inactive queue.  Memory evicted from the ARC is simply freed immediately and never enters the page queues.
-  * Almost "Free" +
-  * Backed by swap or files (ie mmap(%%))%% +
-  * Available for re-allocation+
  
-**Free** +Pages belonging to page queues are in one of two states: clean or dirty.  Dirty pages must have their contents saved before they can be reused for some other purpose, at which point they become clean.  Dirty anonymous pages are cleaned by writing their contents to the swap device, and dirty file pages are cleaned by writing their contents to the filesystem's backing storage.  Once a page is clean, it can be easily freed and reused.
-  * Literally Free.+
  
-**Wired** +===== Memory Classes =====
-  * Locked in-memory (by kernel, mlock, etc) +
-  * Cannot be swapped out +
-  * Kernel, kernel modules and kernel heap live here+
  
-===== Other =====+**Active** 
 +  * Contains pages "actively" (recently) referenced by userland 
 +  * Contains a mix of clean and dirty pages 
 +  * Pages are regularly scanned by the page daemon (each page is visited once every vm.pageout_update_period seconds) 
 +  * Scans check to see if the page has been referenced since the last scan 
 +  * If enough scans complete without seeing a reference, the page is moved to the inactive queue 
 +  * Implements pseudo-LRU
  
-**Buffer** +**Inactive** 
-  * Accounts for Disk IO cache entries for non ZFS filesystems +  * Contains pages aged out of the active queue 
-  * Data may be stored in Active, Inactive and Wired +  * Contains pages evicted from the buffer cache 
-  * Only usable by the kernel+  * Contains a mix of clean and dirty pages 
 +  * Pages are scanned by the page daemon (starting from the head of the queue) when there is a memory shortage: 
 +    * Pages which have been referenced are moved back to the active queue or the tail of the inactive queue 
 +    * Pages which are dirty are moved to the tail of the laundry queue 
 +    * Unreferenced, clean pages may be freed and reused immediately 
 +  * Implements second-chance LRU
  
-===== Thanks =====+**Laundry** 
 +  * Queue for managing dirty inactive pages, which must be cleaned ("laundered") before they can be reused 
 +  * Managed by a separate thread, the laundry thread, instead of the page daemon 
 +  * Laundry thread launders a small number of pages to balance the inactive and laundry queues 
 +  * Frequency of laundering depends on: 
 +    * How many clean pages the page daemon is freeing; more frees contributes to a higher frequency of laundering 
 +    * The size of the laundry queue relative to the inactive queue; if the laundry queue is growing, we will launder more frequently 
 +  * Pages are scanned by the laundry thread (starting from the head of the queue): 
 +    * Pages which have been referenced are moved back to the active queue or the tail of the laundry queue 
 +    * Dirty pages are laundered and then moved close to the head of the inactive queue
  
-Special thanks to **avg** and **zont** for putting up with my probing questions for over and hour to squeeze this valuable information out :)+**Free** 
 +  * Memory available for use by the rest of the system. 
 + 
 +**Wired** 
 +  * Non-pageable memory: cannot be freed until explicitly released by the owner 
 +  * Userland memory can be wired by mlock(2) (subject to system and per-user limits) 
 +  * Kernel memory allocators return wired memory 
 +  * Contents of the ARC and the buffer cache are wired 
 +  * Some memory is permanently wired and is never freed (e.g., the kernel file itself)
  
  • memory.1361366449.txt.gz
  • Last modified: 2013/02/20 13:20
  • by KubilayKocak