Documenting shmem as an exception case for the pagemap
Subsystems (3)
v3 cover Documenting shmem as an exception case for the pagemap
This patch follows the discussions on previous documentation patch threads [1][2]. It presents the exception case of shared memory management from the pagemap's point of view. It briefly describes what is missing, why it is missing and alternatives to the pagemap for page info retrieval in user space.
In short, the kernel does not keep track of PTEs for swapped out shared pages within the processes that references them. Thus, the proc/pid/pagemap tool cannot print the swap destination of the shared memory pages, instead setting the pagemap entry to zero for both non-allocated and swapped out pages. This can create confusion for users who need information on swapped out pages.
The reasons why maintaining the PTEs of all swapped out shared pages among all processes while maintaining similar performance is not a trivial task, or a desirable change, have been discussed extensively [1][3][4][5]. There are also arguments for why this arguably missing information should eventually be exposed to the user in either a future pagemap patch, or by an alternative tool.
[1]: https://marc.info/?m=162878395426774
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/lkml/[email protected]/
Tiberiu A Georgescu (1):
Documentation: update pagemap with shmem exceptions
Documentation/admin-guide/mm/pagemap.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
Signature · 1 line
2.33.0.363.g4c719308ce
PATCH v3 1/1 Documentation: update pagemap with shmem exceptions
Mentioning the current missing information in the pagemap and alternatives on how to retrieve it, in case someone stumbles upon unexpected behaviour.
--- Documentation/admin-guide/mm/pagemap.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
Documentation/admin-guide/mm/pagemap.rst +22 -0
@@ -196,6 +196,28 @@ you can go through every map in the process, find the PFNs, look those up in kpagecount, and tally up the number of pages that are only referenced once. +Exceptions for Shared Memory +============================ + +Page table entries for shared pages are cleared when the pages are zapped or +swapped out. This makes swapped out pages indistinguishable from never-allocated +ones. + +In kernel space, the swap location can still be retrieved from the page cache. +However, values stored only on the normal PTE get lost irretrievably when the +page is swapped out (i.e. SOFT_DIRTY). + +In user space, whether the page is present, swapped or none can be deduced with +the help of lseek and/or mincore system calls. + +lseek() can differentiate between accessed pages (present or swapped out) and +holes (none/non-allocated) by specifying the SEEK_DATA flag on the file where +the pages are backed. For anonymous shared pages, the file can be found in +``/proc/pid/map_files/``. + +mincore() can differentiate between pages in memory (present, including swap +cache) and out of memory (swapped out or none/non-allocated). + Other notes ===========
Signature · 1 line
2.33.0.363.g4c719308ce
Re: [PATCH v3 1/1] Documentation: update pagemap with shmem exceptions
Quoted 8 lines · Tiberiu A Georgescu
Mentioning the current missing information in the pagemap and alternatives on how to retrieve it, in case someone stumbles upon unexpected behaviour.
Signed-off-by Tiberiu A Georgescu <[email protected]>Reviewed-by Ivan Teterevkov <[email protected]>Reviewed-by Florian Schmidt <[email protected]>Reviewed-by Carl Waldspurger <[email protected]>Reviewed-by Jonathan Davies <[email protected]>
Thanks,
Signature · 1 line
Peter Xu
David Hildenbrand
Reviewed-byRe: [PATCH v3 1/1] Documentation: update pagemap with shmem exceptions
Quoted 11 lines · Peter Xu
Quoted 8 lines · Tiberiu A Georgescu
Mentioning the current missing information in the pagemap and alternatives on how to retrieve it, in case someone stumbles upon unexpected behaviour.
Signed-off-by Tiberiu A Georgescu <[email protected]>Reviewed-by Ivan Teterevkov <[email protected]>Reviewed-by Florian Schmidt <[email protected]>Reviewed-by Carl Waldspurger <[email protected]>Reviewed-by Jonathan Davies <[email protected]>Reviewed-by Peter Xu <[email protected]>
LGTM as well; I like that we only give hints instead of listing steps to perform as in the previous version.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 26 lines · Tiberiu A Georgescu
This patch follows the discussions on previous documentation patch threads [1][2]. It presents the exception case of shared memory management from the pagemap's point of view. It briefly describes what is missing, why it is missing and alternatives to the pagemap for page info retrieval in user space.
In short, the kernel does not keep track of PTEs for swapped out shared pages within the processes that references them. Thus, the proc/pid/pagemap tool cannot print the swap destination of the shared memory pages, instead setting the pagemap entry to zero for both non-allocated and swapped out pages. This can create confusion for users who need information on swapped out pages.
The reasons why maintaining the PTEs of all swapped out shared pages among all processes while maintaining similar performance is not a trivial task, or a desirable change, have been discussed extensively [1][3][4][5]. There are also arguments for why this arguably missing information should eventually be exposed to the user in either a future pagemap patch, or by an alternative tool.
[1]: https://marc.info/?m=162878395426774
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/lkml/[email protected]/
Quoted 5 lines
Tiberiu A Georgescu (1):
Documentation: update pagemap with shmem exceptionsDocumentation/admin-guide/mm/pagemap.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
Applied, thanks.
jon