title: Is anonymous memory part of the page cache on Linux?
body: <p>Is <a href="https://www.kernel.org/doc/html/latest/admin-guide/mm/concepts.html#anonymous-memory" rel="nofollow noreferrer">anonymous memory</a> - i.e. program heap and stack - part of the page cache on Linux? The linked documentation of the kernel does not state that.</p>
  <p>But the Wikipedia entry about <a href="https://en.wikipedia.org/wiki/Page_cache" rel="nofollow noreferrer">Page Cache</a> contains a graphic (look at the top right) which gives me the impression that <a href="https://en.cppreference.com/w/c/memory/malloc" rel="nofollow noreferrer">malloc()</a> allocates dynamic memory within the page cache:<br />
  <a href="https://i.stack.imgur.com/ZxMNv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZxMNv.png" alt="linux storage stack diagram from thomas krenn" /></a></p>
  <p>Does that make sense? Regarding <code>mmap()</code>, when it is used to access files it makes sense to use the page cache. Also generally for anonymous memory e.g. <code>malloc()</code> and anonymous mappings through <code>mmap()</code>?</p>
  <p>I would appreciate some explanation.</p>
  <p>Thank you.</p>
  <p><strong>Edit 2021-03-14</strong><br />
  I've decided it is the best to ask the kernel maintainers of the memory subsystem on their <a href="https://linux-mm.org/" rel="nofollow noreferrer">mailing-list</a>. Luckily <a href="https://kernelnewbies.org/MatthewWilcox" rel="nofollow noreferrer">Matthew Wilcox</a> responded and helped me. Extract:</p>
  <ul>
  <li>Anonymous memory is not handled by the <code>page cache</code>.</li>
  <li>Anonymous pages are handled in a number of different ways -- they can be found on <code>LRU lists</code> (Least Recently Used) and they can be found through the <code>page tables</code>. Somewhat ad-hoc.</li>
  <li>The wikipedia diagram is wrong. And it contains further flaws.</li>
  <li>If a system provides swap and if anonymous memory is swapped - it enters the <code>swap cache</code>, not the <code>page cache</code>.</li>
  </ul>
  <p>The discussion can be read on <a href="https://lore.kernel.org/linux-mm/e17246e9216435e0e65b3d99cb190fab@flapflap.eu/#t" rel="nofollow noreferrer">here</a> or <a href="https://marc.info/?l=linux-mm&amp;m=161556020024488&amp;w=2" rel="nofollow noreferrer">here</a>.</p>