linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] pagemap: report swap location for shared pages
@ 2021-07-14 15:24 Tiberiu Georgescu
  2021-07-14 15:24 ` [RFC PATCH 1/1] " Tiberiu Georgescu
  2021-07-14 16:01 ` [RFC PATCH 0/1] " Peter Xu
  0 siblings, 2 replies; 8+ messages in thread
From: Tiberiu Georgescu @ 2021-07-14 15:24 UTC (permalink / raw)
  To: akpm, peterx, catalin.marinas, peterz, chinwen.chang, linmiaohe,
	jannh, apopple, christian.brauner, ebiederm, adobriyan,
	songmuchun, axboe, linux-kernel, linux-fsdevel, linux-mm
  Cc: ivan.teterevkov, florian.schmidt, carl.waldspurger, Tiberiu Georgescu

When a page allocated using the MAP_SHARED flag is swapped out, its pagemap
entry is cleared. In many cases, there is no difference between swapped-out
shared pages and newly allocated, non-dirty pages in the pagemap interface.

Example pagemap-test code (Tested on Kernel Version 5.14-rc1):

	#define NPAGES (256)
	/* map 1MiB shared memory */
	size_t pagesize = getpagesize();
	char *p = mmap(NULL, pagesize * NPAGES, PROT_READ | PROT_WRITE,
			   MAP_ANONYMOUS | MAP_SHARED, -1, 0);
	/* Dirty new pages. */
	for (i = 0; i < PAGES; i++)
		p[i * pagesize] = i;

Run the above program in a small cgroup, which allows swapping:

	/* Initialise cgroup & run a program */
	$ echo 512K > foo/memory.limit_in_bytes
	$ echo 60 > foo/memory.swappiness
	$ cgexec -g memory:foo ./pagemap-test

Check the pagemap report. This is an example of the current expected output:

	$ dd if=/proc/$PID/pagemap ibs=8 skip=$(($VADDR / $PAGESIZE)) count=$COUNT | hexdump -C
	00000000  00 00 00 00 00 00 80 00  00 00 00 00 00 00 80 00  |................|
	*
	00000710  e1 6b 06 00 00 00 80 a1  9e eb 06 00 00 00 80 a1  |.k..............|
	00000720  6b ee 06 00 00 00 80 a1  a5 a4 05 00 00 00 80 a1  |k...............|
	00000730  5c bf 06 00 00 00 80 a1  90 b6 06 00 00 00 80 a1  |\...............|

The first pagemap entries are reported as zeroes, indicating the pages have
never been allocated while they have actually been swapped out. It is
possible for bit 55 (PTE is Soft-Dirty) to be set on all pages of the
shared VMA, indicating some access to the page, but nothing else (frame
location, presence in swap or otherwise).

This patch addresses the behaviour and modifies pte_to_pagemap_entry() to
make use of the XArray associated with the virtual memory area struct
passed as an argument. The XArray contains the location of virtual pages in
the page cache, swap cache or on disk. If they are on either of the caches,
then the original implementation still works. If not, then the missing
information will be retrieved from the XArray.

The root cause of the missing functionality is that the PTE for the page
itself is cleared when a swap out occurs on a shared page.  Please take a
look at the proposed patch. I would appreciate it if you could verify a
couple of points:

1. Why do swappable and non-syncable shared pages have their PTEs cleared
   when they are swapped out ? Why does the behaviour differ so much
   between MAP_SHARED and MAP_PRIVATE pages? What are the origins of the
   approach?

2. PM_SOFT_DIRTY and PM_UFFD_WP are two flags that seem to get lost once
   the shared page is swapped out. Is there any other way to retrieve
   their value in the proposed patch, other than ensuring these flags are
   set, when necessary, in the PTE?

Kind regards,
Tibi

Tiberiu Georgescu (1):
  pagemap: report swap location for shared pages

 fs/proc/task_mmu.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

-- 
2.32.0


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

end of thread, other threads:[~2021-07-15  9:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 15:24 [RFC PATCH 0/1] pagemap: report swap location for shared pages Tiberiu Georgescu
2021-07-14 15:24 ` [RFC PATCH 1/1] " Tiberiu Georgescu
2021-07-14 16:08   ` Peter Xu
2021-07-14 16:24     ` David Hildenbrand
2021-07-14 16:30       ` David Hildenbrand
2021-07-14 17:12         ` Peter Xu
2021-07-15  9:48     ` Tiberiu Georgescu
2021-07-14 16:01 ` [RFC PATCH 0/1] " Peter Xu

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).