All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Xie <jeff.xie@linux.dev>
To: akpm@linux-foundation.org, iamjoonsoo.kim@lge.com,
	vbabka@suse.cz, cl@linux.com, penberg@kernel.org,
	rientjes@google.com, roman.gushchin@linux.dev,
	42.hyeyoo@gmail.com, willy@infradead.org
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, chensong_2000@189.cn,
	xiehuan09@gmail.com, Jeff Xie <jeff.xie@linux.dev>
Subject: [RFC][PATCH 4/4] mm/rmap: implement anonmap allocate post callback for page_owner
Date: Thu,  9 Nov 2023 11:25:21 +0800	[thread overview]
Message-ID: <20231109032521.392217-5-jeff.xie@linux.dev> (raw)
In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev>

Implement the callback function anon_alloc_post_page_owner for the page_owner
to make the owner of the anon page clearer

For the pid 98:
[root@JeffXie ]# cat /proc/98/maps 
00400000-00401000 r--p 00000000 fd:00 1954	/test/mm/a.out
00401000-00499000 r-xp 00001000 fd:00 1954      /test/mm/a.out
00499000-004c2000 r--p 00099000 fd:00 1954      /test/mm/a.out
004c2000-004c6000 r--p 000c1000 fd:00 1954      /test/mm/a.out
004c6000-004c9000 rw-p 000c5000 fd:00 1954      /test/mm/a.out
004c9000-004ce000 rw-p 00000000 00:00 0 
01d97000-01db9000 rw-p 00000000 00:00 0                 [heap]
7f1588fc8000-7f1588fc9000 rw-p 00000000 fd:00 1945      /a.txt
7ffda207a000-7ffda209b000 rw-p 00000000 00:00 0         [stack]
7ffda2152000-7ffda2156000 r--p 00000000 00:00 0         [vvar]
7ffda2156000-7ffda2158000 r-xp 00000000 00:00 0         [vdso]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]

added: "ANON_PAGE address 0x4c4000"

Page allocated via order 0, mask 0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), pid 98, tgid 98 (a.out), ts 28442066180 ns
ANON_PAGE address 0x4c4000
PFN 0x2c3db type Movable Block 353 type Movable Flags 0x1fffc00000a0028(uptodate|lru|mappedtodisk|swapbacked|node=0|zone=1|lastcpupid=0x3fff)
 post_alloc_hook+0x77/0xf0
 get_page_from_freelist+0x58d/0x14e0
 __alloc_pages+0x1b2/0x380
 alloc_pages_mpol+0x97/0x1f0
 vma_alloc_folio+0x5c/0xd0
 do_wp_page+0x288/0xe30
 __handle_mm_fault+0x8ca/0x1760
 handle_mm_fault+0xbc/0x2f0
 do_user_addr_fault+0x158/0x5e0
 exc_page_fault+0x73/0x170
 asm_exc_page_fault+0x26/0x30
Charged to memcg / 

Signed-off-by: Jeff Xie <jeff.xie@linux.dev>
---
 include/linux/rmap.h |  7 +++++++
 mm/rmap.c            | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index b26fe858fd44..d85650c9c520 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -502,4 +502,11 @@ static inline int page_mkclean(struct page *page)
 {
 	return folio_mkclean(page_folio(page));
 }
+#ifndef CONFIG_PAGE_OWNER
+static inline int anon_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
+		void *data, char *kbuf, size_t count)
+{
+	return 0;
+}
+#endif
 #endif	/* _LINUX_RMAP_H */
diff --git a/mm/rmap.c b/mm/rmap.c
index 7a27a2b41802..41c8a387cd37 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -75,7 +75,7 @@
 #include <linux/memremap.h>
 #include <linux/userfaultfd_k.h>
 #include <linux/mm_inline.h>
-
+#include <linux/page_owner.h>
 #include <asm/tlbflush.h>
 
 #define CREATE_TRACE_POINTS
@@ -1151,6 +1151,18 @@ void folio_move_anon_rmap(struct folio *folio, struct vm_area_struct *vma)
 	 */
 	WRITE_ONCE(folio->mapping, anon_vma);
 }
+#ifdef CONFIG_PAGE_OWNER
+static int anon_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
+			void *data, char *kbuf, size_t count)
+{
+	int ret;
+	unsigned long address = (unsigned long)data;
+
+	ret = scnprintf(kbuf, count, "ANON_PAGE address 0x%lx\n", address);
+
+	return ret;
+}
+#endif
 
 /**
  * __folio_set_anon - set up a new anonymous rmap for a folio
@@ -1182,6 +1194,7 @@ static void __folio_set_anon(struct folio *folio, struct vm_area_struct *vma,
 	anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
 	WRITE_ONCE(folio->mapping, (struct address_space *) anon_vma);
 	folio->index = linear_page_index(vma, address);
+	set_folio_alloc_post_page_owner(folio, anon_alloc_post_page_owner, (void *)address);
 }
 
 /**
-- 
2.34.1


  parent reply	other threads:[~2023-11-09  3:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09  3:25 [RFC][PATCH 0/4] mm, page_owner: make the owner in page owner clearer Jeff Xie
2023-11-09  3:25 ` [RFC][PATCH 1/4] mm, page_owner: add folio allocate post callback for struct page_owner to make the " Jeff Xie
2023-11-09 13:59   ` Matthew Wilcox
2023-11-09 15:25     ` Jeff Xie
2023-11-09 15:36       ` Matthew Wilcox
2023-11-09 16:04       ` jeff.xie
2023-11-09 16:38         ` Matthew Wilcox
2023-11-09  3:25 ` [RFC][PATCH 2/4] mm, slub: implement slub allocate post callback for page_owner Jeff Xie
2023-11-09 14:05   ` Matthew Wilcox
2023-11-09 15:34   ` jeff.xie
2023-11-09  3:25 ` [RFC][PATCH 3/4] filemap: implement filemap " Jeff Xie
2023-11-09 14:09   ` Matthew Wilcox
2023-11-09 15:43   ` jeff.xie
2023-11-09 15:46     ` Matthew Wilcox
2023-11-09 22:16   ` kernel test robot
2023-11-09  3:25 ` Jeff Xie [this message]
2023-11-09 14:10   ` [RFC][PATCH 4/4] mm/rmap: implement anonmap " Matthew Wilcox
2023-11-09 15:47   ` jeff.xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231109032521.392217-5-jeff.xie@linux.dev \
    --to=jeff.xie@linux.dev \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chensong_2000@189.cn \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=xiehuan09@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.