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 2/4] mm, slub: implement slub allocate post callback for page_owner
Date: Thu, 9 Nov 2023 11:25:19 +0800 [thread overview]
Message-ID: <20231109032521.392217-3-jeff.xie@linux.dev> (raw)
In-Reply-To: <20231109032521.392217-1-jeff.xie@linux.dev>
Implement the callback function slab_alloc_post_page_owner for the page_owner
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_NORETRY), 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(slab|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
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|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), \
pid 86, tgid 86 (linuxrc), ts 1121118666 ns
SLAB_PAGE slab_name:mm_struct
PFN 0x6388 type Unmovable Block 49 type Unmovable Flags 0x1fffc0000000840(slab|head|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
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 <jeff.xie@linux.dev>
---
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 task_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 @@
#include <linux/debugfs.h>
#include <trace/events/kmem.h>
+#include <linux/page_owner.h>
#include "internal.h"
@@ -1993,6 +1994,19 @@ static inline bool shuffle_freelist(struct kmem_cache *s, struct slab *slab)
}
#endif /* CONFIG_SLAB_FREELIST_RANDOM */
+#ifdef CONFIG_PAGE_OWNER
+static int slab_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
+ void *data, char *kbuf, size_t count)
+{
+ int ret;
+ struct kmem_cache *kmem_cache = data;
+
+ ret = scnprintf(kbuf, count, "SLAB_PAGE slab_name:%s\n", kmem_cache->name);
+
+ return ret;
+}
+#endif
+
static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
{
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);
}
+ set_folio_alloc_post_page_owner(slab_folio(slab), slab_alloc_post_page_owner, s);
slab->objects = oo_objects(oo);
slab->inuse = 0;
slab->frozen = 0;
--
2.34.1
next prev parent reply other threads:[~2023-11-09 3:26 UTC|newest]
Thread overview: 17+ 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 ` Jeff Xie [this message]
2023-11-09 14:05 ` [RFC][PATCH 2/4] mm, slub: implement slub allocate post callback for page_owner 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 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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox