Skip to content

Commit 60fa4a9

Browse files
Kent Overstreetakpm00
authored andcommitted
mm: percpu: add codetag reference into pcpuobj_ext
To store codetag for every per-cpu allocation, a codetag reference is embedded into pcpuobj_ext when CONFIG_MEM_ALLOC_PROFILING=y. Hooks to use the newly introduced codetag are added. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kent Overstreet <[email protected]> Signed-off-by: Suren Baghdasaryan <[email protected]> Tested-by: Kees Cook <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: Alice Ryhl <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Benno Lossin <[email protected]> Cc: "Björn Roy Baron" <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Dennis Zhou <[email protected]> Cc: Gary Guo <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wedson Almeida Filho <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8f30d26 commit 60fa4a9

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

mm/percpu-internal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ struct pcpuobj_ext {
3636
#ifdef CONFIG_MEMCG_KMEM
3737
struct obj_cgroup *cgroup;
3838
#endif
39+
#ifdef CONFIG_MEM_ALLOC_PROFILING
40+
union codetag_ref tag;
41+
#endif
3942
};
4043

41-
#ifdef CONFIG_MEMCG_KMEM
44+
#if defined(CONFIG_MEMCG_KMEM) || defined(CONFIG_MEM_ALLOC_PROFILING)
4245
#define NEED_PCPUOBJ_EXT
4346
#endif
4447

@@ -86,7 +89,11 @@ struct pcpu_chunk {
8689

8790
static inline bool need_pcpuobj_ext(void)
8891
{
89-
return !mem_cgroup_kmem_disabled();
92+
if (IS_ENABLED(CONFIG_MEM_ALLOC_PROFILING))
93+
return true;
94+
if (!mem_cgroup_kmem_disabled())
95+
return true;
96+
return false;
9097
}
9198

9299
extern spinlock_t pcpu_lock;

mm/percpu.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,32 @@ static void pcpu_memcg_free_hook(struct pcpu_chunk *chunk, int off, size_t size)
16991699
}
17001700
#endif /* CONFIG_MEMCG_KMEM */
17011701

1702+
#ifdef CONFIG_MEM_ALLOC_PROFILING
1703+
static void pcpu_alloc_tag_alloc_hook(struct pcpu_chunk *chunk, int off,
1704+
size_t size)
1705+
{
1706+
if (mem_alloc_profiling_enabled() && likely(chunk->obj_exts)) {
1707+
alloc_tag_add(&chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].tag,
1708+
current->alloc_tag, size);
1709+
}
1710+
}
1711+
1712+
static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t size)
1713+
{
1714+
if (mem_alloc_profiling_enabled() && likely(chunk->obj_exts))
1715+
alloc_tag_sub(&chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].tag, size);
1716+
}
1717+
#else
1718+
static void pcpu_alloc_tag_alloc_hook(struct pcpu_chunk *chunk, int off,
1719+
size_t size)
1720+
{
1721+
}
1722+
1723+
static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t size)
1724+
{
1725+
}
1726+
#endif
1727+
17021728
/**
17031729
* pcpu_alloc - the percpu allocator
17041730
* @size: size of area to allocate in bytes

0 commit comments

Comments
 (0)