ablog

不器用で落着きのない技術者のメモ

/proc/meminfo の Inactive は利用可能なメモリ領域ではない

ちょくちょく、/proc/meminfo の Active が使用中、Inactive は使用可能な領域ですよねと聞かれることがあり、違いますよと話すことがあるので、出典をメモっておく。

  • がちゃぴん先生のブログ

Activeはページキャッシュや無名ページ(注3)のうち、最近利用したり、まだストレージとの同期が取れていない「捨てられない」ページです。Inactiveは、同じくページキャッシュや無名ページのうち、最後にアクセスされてからある程度時間がたち、ストレージとの同期も完了していて、すぐに捨てられるページです。よって、/proc/meminfoの出力でいうところの MemFreeとInactiveを足すことで確実に利用可能なメモリ量を算出することができます。

(実際に利用可能なメモリ量)≒(MemFree+Inactive)

この値を利用し、一定量を下回らないようにするのが、簡単・確実なメモリ利用率監視法といえます。

減り続けるメモリ残量! 果たしてその原因は!? (3/3):Linuxトラブルシューティング探偵団 番外編(1) - @IT

間違ってる。完全に。

(中略)

まず、ActiveとInactiveの違いは、メモリ不足発生時にInactiveのほうが先に回収可能性チェックをされる。という意味しかない。Inactiveにもダーティーページ(ストレージが同期がとれていないページ)やmlockされたページなど捨てられないページは大量に混じっている。また、Inactiveをチェックして、回収したりActiveに入れなおしたりして減ったInactiveのページ数はActiveからInactiveに落とすことにより、補充されるので、Activeであることも何も保障してない。

革命の日々! @ITのmeminfoの見方の説明が完全に間違っている件について
  • 中井(id:enakai00)先生の本
    • P.56 1.4.2 メモリの割り当てと解放

プロのための Linuxシステム・10年効く技術 (Software Design plus)

プロのための Linuxシステム・10年効く技術 (Software Design plus)

  • [twitter:@brendangregg]先生の本

Systems Performance: Enterprise and the Cloud (English Edition)

Systems Performance: Enterprise and the Cloud (English Edition)

    • 7.3.2. Software - Page Scanning

The page-out daemon is called kswapd(), which scans LRU page lists of inactive and active memory to free pages. It is woken up based on free memory and two thresholds to provide hysteresis, as shown in Figure 7.8.
Once free memory has reached the lowest threshold, kswapd operates in synchronous mode, freeing pages of memory as they are requested (the kernel is exempt from this requirement) [Gorman 04]. This lowest threshold is tunable (vm.min_free_kbytes), and the others are scaled based on it (by 2x, 3x).
The page cache has separate lists for inactive pages and active pages. These operate in an LRU fashion, allowing kswapd to find free pages quickly. They are shown in Figure 7.9.
kswapd scans the inactive list first, and then the active if needed. The term scanning refers to checking pages as the list is walked: a page may be ineligible to be freed if it is locked or dirty. This term has a different meaning with the original page-out daemon, which scans all of memory and still exists in Solaris-based systems.