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 3/4] filemap: implement filemap allocate post callback for page_owner
Date: Thu,  9 Nov 2023 11:25:20 +0800	[thread overview]
Message-ID: <20231109032521.392217-4-jeff.xie@linux.dev> (raw)
In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev>

Implement the callback function filemap_alloc_post_page_owner for the page_owner
to make the owner of the file 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: "FILE_PAGE dev 253:0 ino:1954 index:0xc1 mapcount:1 refcount:2 0x4c2000 - 0x4c3000"

Page allocated via order 0, mask 0x152c4a(GFP_NOFS|__GFP_HIGHMEM|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_HARDWALL|__GFP_MOVABLE),\
 pid 98, tgid 98 (a.out), ts 28441476044 ns
FILE_PAGE dev 253:0 ino:1954 index:0xc1 mapcount:1 refcount:2 0x4c2000 - 0x4c3000
PFN 0x5be8e type Movable Block 735 type Movable Flags 0x1fffc0000020028(uptodate|lru|mappedtodisk|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
 folio_alloc+0x18/0x50
 page_cache_ra_unbounded+0x9b/0x1a0
 filemap_fault+0x5f7/0xc20
 __do_fault+0x31/0xc0
 __handle_mm_fault+0x1333/0x1760
 handle_mm_fault+0xbc/0x2f0
 do_user_addr_fault+0x1f8/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/pagemap.h |  7 +++++++
 mm/filemap.c            | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index bcc1ea44b4e8..900aa136c71f 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1514,4 +1514,11 @@ unsigned int i_blocks_per_page(struct inode *inode, struct page *page)
 {
 	return i_blocks_per_folio(inode, page_folio(page));
 }
+#ifndef CONFIG_PAGE_OWNER
+static inline int filemap_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
+		void *data, char *kbuf, size_t count)
+{
+	return 0;
+}
+#endif
 #endif /* _LINUX_PAGEMAP_H */
diff --git a/mm/filemap.c b/mm/filemap.c
index 9710f43a89ac..0a346443309a 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -45,6 +45,7 @@
 #include <linux/migrate.h>
 #include <linux/pipe_fs_i.h>
 #include <linux/splice.h>
+#include <linux/page_owner.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include "internal.h"
@@ -838,6 +839,48 @@ void replace_page_cache_folio(struct folio *old, struct folio *new)
 }
 EXPORT_SYMBOL_GPL(replace_page_cache_folio);
 
+#ifdef CONFIG_PAGE_OWNER
+static int filemap_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
+			void *data, char *kbuf, size_t count)
+{
+	int ret;
+	int mapcount;
+	dev_t s_dev;
+	struct inode *inode;
+	struct vm_area_struct *vma;
+	struct mm_struct *mm;
+	unsigned long virtual_start = 0x0;
+	unsigned long virtual_end = 0x0;
+	struct address_space *mapping = data;
+
+	mapcount = folio_mapcount(folio);
+	if (mapcount && tsk && tsk->mm) {
+		mm = tsk->mm;
+		VMA_ITERATOR(vmi, mm, 0);
+		mmap_read_lock(mm);
+		for_each_vma(vmi, vma) {
+			if (page_mapped_in_vma(&folio->page, vma)) {
+				virtual_start = vma_address(&folio->page, vma);
+				virtual_end = virtual_start + folio_nr_pages(folio) * PAGE_SIZE;
+				break;
+			}
+		}
+		mmap_read_unlock(mm);
+	}
+
+	inode = mapping->host;
+	if (mapping->host->i_sb)
+		s_dev = mapping->host->i_sb->s_dev;
+	else
+		s_dev = mapping->host->i_rdev;
+	ret = scnprintf(kbuf, count, "FILE_PAGE dev %d:%d ino:%lu index:0x%lx mapcount:%d refcount:%d 0x%lx - 0x%lx\n",
+		MAJOR(s_dev), MINOR(s_dev), inode->i_ino, folio->index, mapcount, folio_ref_count(folio),
+		virtual_start, virtual_end);
+
+	return ret;
+}
+#endif
+
 noinline int __filemap_add_folio(struct address_space *mapping,
 		struct folio *folio, pgoff_t index, gfp_t gfp, void **shadowp)
 {
@@ -915,6 +958,7 @@ noinline int __filemap_add_folio(struct address_space *mapping,
 	if (xas_error(&xas))
 		goto error;
 
+	set_folio_alloc_post_page_owner(folio, filemap_alloc_post_page_owner, mapping);
 	trace_mm_filemap_add_to_page_cache(folio);
 	return 0;
 error:
-- 
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 ` Jeff Xie [this message]
2023-11-09 14:09   ` [RFC][PATCH 3/4] filemap: implement filemap " 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 ` [RFC][PATCH 4/4] mm/rmap: implement anonmap " Jeff Xie
2023-11-09 14:10   ` 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-4-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.