From nobody Wed Dec 31 01:09:51 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9938FC4167D for ; Thu, 9 Nov 2023 03:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbjKIDbh (ORCPT ); Wed, 8 Nov 2023 22:31:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbjKIDbd (ORCPT ); Wed, 8 Nov 2023 22:31:33 -0500 X-Greylist: delayed 344 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 08 Nov 2023 19:31:31 PST Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [IPv6:2001:41d0:203:375::b9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62A511FD6 for ; Wed, 8 Nov 2023 19:31:31 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699500351; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b7QgHrHMcQgDYNH9cSurCrN2io0udjYc/RXiOMn9HQo=; b=hPDBsLerGi2CsDGvsyury3Y7/vRfFLrFqniLSN9fLNoEOxsjniR6+2yoRufgY/ESIOkfDC hxgIyJGxT8EIAg3Nr3sL0jfaPGEsQ1/mwz0+sPIkno1r/+6iBvJyla6Ek+XO8p+oMuiCTj AyxVNGd5WlH4qVnpOxDC3n3Jp4lJhz8= From: Jeff Xie 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 Subject: [RFC][PATCH 1/4] mm, page_owner: add folio allocate post callback for struct page_owner to make the owner clearer Date: Thu, 9 Nov 2023 11:25:18 +0800 Message-Id: <20231109032521.392217-2-jeff.xie@linux.dev> In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev> References: <20231109032521.392217-1-jeff.xie@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" adding a callback function in the struct page_owner to let the slab layer o= r the anon/file handler layer or any other memory-allocated layers to implement w= hat they would like to tell. Signed-off-by: Jeff Xie --- include/linux/page_owner.h | 9 +++++++++ mm/page_owner.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h index 119a0c9d2a8b..71698d82df7c 100644 --- a/include/linux/page_owner.h +++ b/include/linux/page_owner.h @@ -4,6 +4,9 @@ =20 #include =20 +typedef int (folio_alloc_post_page_owner_t)(struct folio *folio, struct ta= sk_struct *tsk, + void *data, char *kbuf, size_t count); + #ifdef CONFIG_PAGE_OWNER extern struct static_key_false page_owner_inited; extern struct page_ext_operations page_owner_ops; @@ -17,6 +20,8 @@ extern void __set_page_owner_migrate_reason(struct page *= page, int reason); extern void __dump_page_owner(const struct page *page); extern void pagetypeinfo_showmixedcount_print(struct seq_file *m, pg_data_t *pgdat, struct zone *zone); +extern void set_folio_alloc_post_page_owner(struct folio *folio, + folio_alloc_post_page_owner_t *folio_alloc_post_page_owner, void *data); =20 static inline void reset_page_owner(struct page *page, unsigned short orde= r) { @@ -72,5 +77,9 @@ static inline void set_page_owner_migrate_reason(struct p= age *page, int reason) static inline void dump_page_owner(const struct page *page) { } +static inline void set_folio_alloc_post_page_owner(struct folio *folio, + folio_alloc_post_page_owner_t *folio_alloc_post_page_owner, void *data) +{ +} #endif /* CONFIG_PAGE_OWNER */ #endif /* __LINUX_PAGE_OWNER_H */ diff --git a/mm/page_owner.c b/mm/page_owner.c index 4f13ce7d2452..4de03a7a10d4 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -32,6 +32,9 @@ struct page_owner { char comm[TASK_COMM_LEN]; pid_t pid; pid_t tgid; + folio_alloc_post_page_owner_t *folio_alloc_post_page_owner; + /* for folio_alloc_post_page_owner function parameter */ + void *data; }; =20 static bool page_owner_enabled __initdata; @@ -152,6 +155,8 @@ void __reset_page_owner(struct page *page, unsigned sho= rt order) page_owner =3D get_page_owner(page_ext); page_owner->free_handle =3D handle; page_owner->free_ts_nsec =3D free_ts_nsec; + page_owner->folio_alloc_post_page_owner =3D NULL; + page_owner->data =3D NULL; page_ext =3D page_ext_next(page_ext); } page_ext_put(page_ext); @@ -256,6 +261,8 @@ void __folio_copy_owner(struct folio *newfolio, struct = folio *old) new_page_owner->ts_nsec =3D old_page_owner->ts_nsec; new_page_owner->free_ts_nsec =3D old_page_owner->ts_nsec; strcpy(new_page_owner->comm, old_page_owner->comm); + new_page_owner->folio_alloc_post_page_owner =3D old_page_owner->folio_all= oc_post_page_owner; + new_page_owner->data =3D old_page_owner->data; =20 /* * We don't clear the bit on the old folio as it's going to be freed @@ -272,6 +279,25 @@ void __folio_copy_owner(struct folio *newfolio, struct= folio *old) page_ext_put(old_ext); } =20 +void set_folio_alloc_post_page_owner(struct folio *folio, + folio_alloc_post_page_owner_t *folio_alloc_post_page_owner, void *data) +{ + struct page *page; + struct page_ext *page_ext; + struct page_owner *page_owner; + + page =3D &folio->page; + page_ext =3D page_ext_get(page); + if (unlikely(!page_ext)) + return; + + page_owner =3D get_page_owner(page_ext); + page_owner->folio_alloc_post_page_owner =3D folio_alloc_post_page_owner; + page_owner->data =3D data; + + page_ext_put(page_ext); +} + void pagetypeinfo_showmixedcount_print(struct seq_file *m, pg_data_t *pgdat, struct zone *zone) { @@ -400,6 +426,7 @@ print_page_owner(char __user *buf, size_t count, unsign= ed long pfn, depot_stack_handle_t handle) { int ret, pageblock_mt, page_mt; + struct task_struct *tsk; char *kbuf; =20 count =3D min_t(size_t, count, PAGE_SIZE); @@ -414,6 +441,15 @@ print_page_owner(char __user *buf, size_t count, unsig= ned long pfn, page_owner->tgid, page_owner->comm, page_owner->ts_nsec); =20 + if (page_owner->folio_alloc_post_page_owner) { + rcu_read_lock(); + tsk =3D find_task_by_pid_ns(page_owner->pid, &init_pid_ns); + rcu_read_unlock(); + ret +=3D page_owner->folio_alloc_post_page_owner(page_folio(page), tsk, = page_owner->data, + kbuf + ret, count - ret); + } else + ret +=3D scnprintf(kbuf + ret, count - ret, "OTHER_PAGE\n"); + /* Print information relevant to grouping pages by mobility */ pageblock_mt =3D get_pageblock_migratetype(page); page_mt =3D gfp_migratetype(page_owner->gfp_mask); --=20 2.34.1 From nobody Wed Dec 31 01:09:51 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56186C4167B for ; Thu, 9 Nov 2023 03:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbjKIDbi (ORCPT ); Wed, 8 Nov 2023 22:31:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbjKIDbd (ORCPT ); Wed, 8 Nov 2023 22:31:33 -0500 X-Greylist: delayed 342 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 08 Nov 2023 19:31:31 PST Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA16026A2 for ; Wed, 8 Nov 2023 19:31:31 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699500357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wNM/9AevUF/j2VNxIIJfzv4M+2rCeqcsvFMA+tau3Ik=; b=n5nLAt33vu68n5XOR8wfuoMwuOsrYmFbqUormWmo3tffPeqYeIiAiUe5LDLU86jzAvB8b7 i3Z0y+6mVqQQrIj2np5f3kbeRycc+XToQwL/sDcYB+8+ZUH+no3gv0dHD1+ZtvCMNJZPfa +4AihrFRti7/kLoDX6Sh56JxhizH7b8= From: Jeff Xie 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 Subject: [RFC][PATCH 2/4] mm, slub: implement slub allocate post callback for page_owner Date: Thu, 9 Nov 2023 11:25:19 +0800 Message-Id: <20231109032521.392217-3-jeff.xie@linux.dev> In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev> References: <20231109032521.392217-1-jeff.xie@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement the callback function slab_alloc_post_page_owner for the page_own= er to make the owner of the slab page clearer For example, for slab page, a line is added to the result of page_owner added: "SLAB_PAGE slab_name:kmalloc-32" Page allocated via order 0, mask 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORE= TRY), pid 1, tgid 1 (swapper/0), ts 340615384 ns SLAB_PAGE slab_name:kmalloc-32 PFN 0x4be0 type Unmovable Block 37 type Unmovable Flags 0x1fffc0000000800(s= lab|node=3D0|zone=3D1|lastcpupid=3D0x3fff) post_alloc_hook+0x77/0xf0 get_page_from_freelist+0x58d/0x14e0 __alloc_pages+0x1b2/0x380 alloc_pages_mpol+0x97/0x1f0 allocate_slab+0x31f/0x410 ___slab_alloc+0x3e8/0x850 __kmem_cache_alloc_node+0x111/0x2b0 kmalloc_trace+0x29/0x90 iommu_setup_dma_ops+0x299/0x470 bus_iommu_probe+0xe1/0x150 iommu_device_register+0xad/0x120 intel_iommu_init+0xe3a/0x1260 pci_iommu_init+0x12/0x40 do_one_initcall+0x45/0x210 kernel_init_freeable+0x1a4/0x2e0 kernel_init+0x1a/0x1c0 added: "SLAB_PAGE slab_name:mm_struct" Page allocated via order 3, mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__G= FP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), \ pid 86, tgid 86 (linuxrc), ts 1121118666 ns=20 SLAB_PAGE slab_name:mm_struct PFN 0x6388 type Unmovable Block 49 type Unmovable Flags 0x1fffc0000000840(s= lab|head|node=3D0|zone=3D1|lastcpupid=3D0x3fff) post_alloc_hook+0x77/0xf0 get_page_from_freelist+0x58d/0x14e0 __alloc_pages+0x1b2/0x380 alloc_pages_mpol+0x97/0x1f0 allocate_slab+0x31f/0x410 ___slab_alloc+0x3e8/0x850 kmem_cache_alloc+0x2b8/0x2f0 mm_alloc+0x1a/0x50 alloc_bprm+0x8a/0x300 do_execveat_common.isra.0+0x68/0x240 __x64_sys_execve+0x37/0x50 do_syscall_64+0x42/0xf0 entry_SYSCALL_64_after_hwframe+0x6e/0x76 Signed-off-by: Jeff Xie --- include/linux/slab.h | 8 +++++++- mm/slub.c | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index d6d6ffeeb9a2..c8969eb4f322 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -795,5 +795,11 @@ int slab_dead_cpu(unsigned int cpu); #define slab_prepare_cpu NULL #define slab_dead_cpu NULL #endif - +#ifndef CONFIG_PAGE_OWNER +static inline int slab_alloc_post_page_owner(struct folio *folio, struct t= ask_struct *tsk, + void *data, char *kbuf, size_t count) +{ + return 0; +} +#endif #endif /* _LINUX_SLAB_H */ diff --git a/mm/slub.c b/mm/slub.c index 63d281dfacdb..7ab8c7aa78e5 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -44,6 +44,7 @@ =20 #include #include +#include =20 #include "internal.h" =20 @@ -1993,6 +1994,19 @@ static inline bool shuffle_freelist(struct kmem_cach= e *s, struct slab *slab) } #endif /* CONFIG_SLAB_FREELIST_RANDOM */ =20 +#ifdef CONFIG_PAGE_OWNER +static int slab_alloc_post_page_owner(struct folio *folio, struct task_str= uct *tsk, + void *data, char *kbuf, size_t count) +{ + int ret; + struct kmem_cache *kmem_cache =3D data; + + ret =3D scnprintf(kbuf, count, "SLAB_PAGE slab_name:%s\n", kmem_cache->na= me); + + return ret; +} +#endif + static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int n= ode) { struct slab *slab; @@ -2028,6 +2042,7 @@ static struct slab *allocate_slab(struct kmem_cache *= s, gfp_t flags, int node) stat(s, ORDER_FALLBACK); } =20 + set_folio_alloc_post_page_owner(slab_folio(slab), slab_alloc_post_page_ow= ner, s); slab->objects =3D oo_objects(oo); slab->inuse =3D 0; slab->frozen =3D 0; --=20 2.34.1 From nobody Wed Dec 31 01:09:51 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B920BC4332F for ; Thu, 9 Nov 2023 03:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232384AbjKIDbn (ORCPT ); Wed, 8 Nov 2023 22:31:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbjKIDbe (ORCPT ); Wed, 8 Nov 2023 22:31:34 -0500 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [IPv6:2001:41d0:203:375::b1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EACAA26AE for ; Wed, 8 Nov 2023 19:31:31 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699500363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j2kk5g3tQ3UUIa7vViud2pPRUP19REPVC10h2UQ9aR4=; b=O+cLqZw78XMy/RUaAaJG1q1LYtKy68Wy9IpJueJN0f04+SHP2aLjD7VfxwdBnhr9sA4SZS 0j10Fv6LvgoIO525gB/h9KeEijjA0eytpeZ6o/jCo5nhzAI+RRiJBSRloSgdFyomMDg3S9 lSyyzdptnsa7UC71g413H54av3HNmfk= From: Jeff Xie 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 Subject: [RFC][PATCH 3/4] filemap: implement filemap allocate post callback for page_owner Date: Thu, 9 Nov 2023 11:25:20 +0800 Message-Id: <20231109032521.392217-4-jeff.xie@linux.dev> In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev> References: <20231109032521.392217-1-jeff.xie@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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=20 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=20 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 0x4c2= 000 - 0x4c3000" Page allocated via order 0, mask 0x152c4a(GFP_NOFS|__GFP_HIGHMEM|__GFP_NOWA= RN|__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 - 0x= 4c3000 PFN 0x5be8e type Movable Block 735 type Movable Flags 0x1fffc0000020028(upt= odate|lru|mappedtodisk|node=3D0|zone=3D1|lastcpupid=3D0x3fff) 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 /=20 Signed-off-by: Jeff Xie --- 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, struc= t 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 #include #include +#include #include #include #include "internal.h" @@ -838,6 +839,48 @@ void replace_page_cache_folio(struct folio *old, struc= t folio *new) } EXPORT_SYMBOL_GPL(replace_page_cache_folio); =20 +#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 =3D 0x0; + unsigned long virtual_end =3D 0x0; + struct address_space *mapping =3D data; + + mapcount =3D folio_mapcount(folio); + if (mapcount && tsk && tsk->mm) { + mm =3D 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 =3D vma_address(&folio->page, vma); + virtual_end =3D virtual_start + folio_nr_pages(folio) * PAGE_SIZE; + break; + } + } + mmap_read_unlock(mm); + } + + inode =3D mapping->host; + if (mapping->host->i_sb) + s_dev =3D mapping->host->i_sb->s_dev; + else + s_dev =3D mapping->host->i_rdev; + ret =3D scnprintf(kbuf, count, "FILE_PAGE dev %d:%d ino:%lu index:0x%lx m= apcount:%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; =20 + set_folio_alloc_post_page_owner(folio, filemap_alloc_post_page_owner, map= ping); trace_mm_filemap_add_to_page_cache(folio); return 0; error: --=20 2.34.1 From nobody Wed Dec 31 01:09:51 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EE0EC4167D for ; Thu, 9 Nov 2023 03:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232332AbjKIDbl (ORCPT ); Wed, 8 Nov 2023 22:31:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjKIDbe (ORCPT ); Wed, 8 Nov 2023 22:31:34 -0500 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0139626B1 for ; Wed, 8 Nov 2023 19:31:31 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699500368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yFdep+48cn5+ZFbHO3HlhiGibtZePlz/+w+2QxfYwYY=; b=C4B7IH4JlssLIKZU77TqalG3IHvqAIr7PjXfY1Uudqf1Vd5DDtHxXho00q/GTaq6FsPUhW NEYOXgwXMACBf2JDt8bMaObYEq1V9T24mVQ0qIO+xqNU1J7N3XzJxhKAut+d3fcIDN3Rxb fQOAhHvoFza5KCRwK3es8m5e/PwvwXo= From: Jeff Xie 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 Subject: [RFC][PATCH 4/4] mm/rmap: implement anonmap allocate post callback for page_owner Date: Thu, 9 Nov 2023 11:25:21 +0800 Message-Id: <20231109032521.392217-5-jeff.xie@linux.dev> In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev> References: <20231109032521.392217-1-jeff.xie@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement the callback function anon_alloc_post_page_owner for the page_own= er to make the owner of the anon page clearer For the pid 98: [root@JeffXie ]# cat /proc/98/maps=20 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=20 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(upt= odate|lru|mappedtodisk|swapbacked|node=3D0|zone=3D1|lastcpupid=3D0x3fff) 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 /=20 Signed-off-by: Jeff Xie --- 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 t= ask_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 #include #include - +#include #include =20 #define CREATE_TRACE_POINTS @@ -1151,6 +1151,18 @@ void folio_move_anon_rmap(struct folio *folio, struc= t 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_str= uct *tsk, + void *data, char *kbuf, size_t count) +{ + int ret; + unsigned long address =3D (unsigned long)data; + + ret =3D scnprintf(kbuf, count, "ANON_PAGE address 0x%lx\n", address); + + return ret; +} +#endif =20 /** * __folio_set_anon - set up a new anonymous rmap for a folio @@ -1182,6 +1194,7 @@ static void __folio_set_anon(struct folio *folio, str= uct vm_area_struct *vma, anon_vma =3D (void *) anon_vma + PAGE_MAPPING_ANON; WRITE_ONCE(folio->mapping, (struct address_space *) anon_vma); folio->index =3D linear_page_index(vma, address); + set_folio_alloc_post_page_owner(folio, anon_alloc_post_page_owner, (void = *)address); } =20 /** --=20 2.34.1