linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Is anonymous memory part of the page cache on Linux?
@ 2021-03-12 14:43 Peter Weber
  2021-03-12 15:15 ` Matthew Wilcox
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Weber @ 2021-03-12 14:43 UTC (permalink / raw)
  To: linux-mm

Hello!
Hopefully I'm asking here in the right place and don't disturb.

Is anonymous memory - i.e. program heap and stack - part of the page 
cache on Linux? The documentation[1] of the kernel does not state that. 
But the Wikipedia entry about page cache contains a graphic[2] (look at 
the top right) which gives me the impression that 'malloc()' allocates 
dynamic memory within the page cache.
Is it possible that the page cache serves as general foundation for 
memory management on Linux? Taking into account that `mmap()` also 
allows for anonymous mappings this could fit together?

I've asked this originally on Stackoverflow[3].

Thank you
Peter

[1] 
https://www.kernel.org/doc/html/latest/admin-guide/mm/concepts.html#anonymous-memory
[2] 
https://en.wikipedia.org/wiki/Page_cache#/media/File:The_Linux_Storage_Stack_Diagram.svg
[3] https://stackoverflow.com/q/66587345/1054324


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Is anonymous memory part of the page cache on Linux?
@ 2021-03-14 23:06 Wxz76
  2021-03-15  0:07 ` Matthew Wilcox
  0 siblings, 1 reply; 7+ messages in thread
From: Wxz76 @ 2021-03-14 23:06 UTC (permalink / raw)
  To: willy; +Cc: linux-mm, peter.weber

[-- Attachment #1: Type: text/plain, Size: 2050 bytes --]

Hi Matthew and Peter,

I had a few questions to clarify my understanding of the page/swap cache.

> There's a swap cache, but that's not the same thing as the page cache.

My understanding of the swap cache comes from:

1) Understanding the Linux Kernel by Bovet and Cesati:

“The swap cache is implemented by the page cache data structures and procedures ” and

“Pages in the swap cache are stored as every other page in the page cache, with the following special treatment:

• The mapping field of the page descriptor is set to NULL.

• The PG_swapcache flag of the page descriptor is set.

• The private field stores the swapped-out page identifier associated with the page”

2) Understanding the Linux Virtual Memory Manager by Mel Gorman:

“The swap cache is purely conceptual because it is simply a specialization of the page cache. The first principal difference between pages in the swap cache rather than the page cache is that pages in the swap

cache always use swapper space as their address space in page→mapping. The second difference is that pages are added to the swap cache with add to swap cache(), shown in Figure 11.3, instead of add to page cache().”

I understand that those books are more than ten years old, but is what they write no longer the case?

Is the swap cache mechanism not a specialization of the page cache, and, if not, how are they different?

> Anonymous memory is not handled by the page cache.

> Anonymous pages enter the storage stack via swap; they are

> found in the page tables, sent to the swap cache and then written to

> swap devices or swap files.

This is for the case of swapping out anonymous memory, but what about anonymous memory that is allocated dynamically with malloc/mmap: where is this memory coming from?

When mmap opens files, it maps a process address spaces to a region in the page cache for the file, does it not?

Is this behavior not the same for allocating anonymous memory (minus dealing with a file)?

I appreciate the help in clarifying this for me.

wxz

[-- Attachment #2: Type: text/html, Size: 4843 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-17 13:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 14:43 Is anonymous memory part of the page cache on Linux? Peter Weber
2021-03-12 15:15 ` Matthew Wilcox
2021-03-12 15:41   ` Peter Weber
2021-03-12 22:45     ` Matthew Wilcox
2021-03-17 13:42       ` David Hildenbrand
2021-03-14 23:06 Wxz76
2021-03-15  0:07 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).