Skip to content

Commit 8f30d26

Browse files
Kent Overstreetakpm00
authored andcommitted
mm: percpu: introduce pcpuobj_ext
Upcoming alloc tagging patches require a place to stash per-allocation metadata. We already do this when memcg is enabled, so this patch generalizes the obj_cgroup * vector in struct pcpu_chunk by creating a pcpu_obj_ext type, which we will be adding to in an upcoming patch - similarly to the previous slabobj_ext patch. 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: Dennis Zhou <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: [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: Gary Guo <[email protected]> Cc: Miguel Ojeda <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wedson Almeida Filho <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e26d876 commit 8f30d26

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

mm/percpu-internal.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ struct pcpu_block_md {
3232
int nr_bits; /* total bits responsible for */
3333
};
3434

35+
struct pcpuobj_ext {
36+
#ifdef CONFIG_MEMCG_KMEM
37+
struct obj_cgroup *cgroup;
38+
#endif
39+
};
40+
41+
#ifdef CONFIG_MEMCG_KMEM
42+
#define NEED_PCPUOBJ_EXT
43+
#endif
44+
3545
struct pcpu_chunk {
3646
#ifdef CONFIG_PERCPU_STATS
3747
int nr_alloc; /* # of allocations */
@@ -64,8 +74,8 @@ struct pcpu_chunk {
6474
int end_offset; /* additional area required to
6575
have the region end page
6676
aligned */
67-
#ifdef CONFIG_MEMCG_KMEM
68-
struct obj_cgroup **obj_cgroups; /* vector of object cgroups */
77+
#ifdef NEED_PCPUOBJ_EXT
78+
struct pcpuobj_ext *obj_exts; /* vector of object cgroups */
6979
#endif
7080

7181
int nr_pages; /* # of pages served by this chunk */
@@ -74,6 +84,11 @@ struct pcpu_chunk {
7484
unsigned long populated[]; /* populated bitmap */
7585
};
7686

87+
static inline bool need_pcpuobj_ext(void)
88+
{
89+
return !mem_cgroup_kmem_disabled();
90+
}
91+
7792
extern spinlock_t pcpu_lock;
7893

7994
extern struct list_head *pcpu_chunk_lists;

mm/percpu.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,9 +1392,9 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
13921392
panic("%s: Failed to allocate %zu bytes\n", __func__,
13931393
alloc_size);
13941394

1395-
#ifdef CONFIG_MEMCG_KMEM
1395+
#ifdef NEED_PCPUOBJ_EXT
13961396
/* first chunk is free to use */
1397-
chunk->obj_cgroups = NULL;
1397+
chunk->obj_exts = NULL;
13981398
#endif
13991399
pcpu_init_md_blocks(chunk);
14001400

@@ -1463,12 +1463,12 @@ static struct pcpu_chunk *pcpu_alloc_chunk(gfp_t gfp)
14631463
if (!chunk->md_blocks)
14641464
goto md_blocks_fail;
14651465

1466-
#ifdef CONFIG_MEMCG_KMEM
1467-
if (!mem_cgroup_kmem_disabled()) {
1468-
chunk->obj_cgroups =
1466+
#ifdef NEED_PCPUOBJ_EXT
1467+
if (need_pcpuobj_ext()) {
1468+
chunk->obj_exts =
14691469
pcpu_mem_zalloc(pcpu_chunk_map_bits(chunk) *
1470-
sizeof(struct obj_cgroup *), gfp);
1471-
if (!chunk->obj_cgroups)
1470+
sizeof(struct pcpuobj_ext), gfp);
1471+
if (!chunk->obj_exts)
14721472
goto objcg_fail;
14731473
}
14741474
#endif
@@ -1480,7 +1480,7 @@ static struct pcpu_chunk *pcpu_alloc_chunk(gfp_t gfp)
14801480

14811481
return chunk;
14821482

1483-
#ifdef CONFIG_MEMCG_KMEM
1483+
#ifdef NEED_PCPUOBJ_EXT
14841484
objcg_fail:
14851485
pcpu_mem_free(chunk->md_blocks);
14861486
#endif
@@ -1498,8 +1498,8 @@ static void pcpu_free_chunk(struct pcpu_chunk *chunk)
14981498
{
14991499
if (!chunk)
15001500
return;
1501-
#ifdef CONFIG_MEMCG_KMEM
1502-
pcpu_mem_free(chunk->obj_cgroups);
1501+
#ifdef NEED_PCPUOBJ_EXT
1502+
pcpu_mem_free(chunk->obj_exts);
15031503
#endif
15041504
pcpu_mem_free(chunk->md_blocks);
15051505
pcpu_mem_free(chunk->bound_map);
@@ -1646,9 +1646,9 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg,
16461646
if (!objcg)
16471647
return;
16481648

1649-
if (likely(chunk && chunk->obj_cgroups)) {
1649+
if (likely(chunk && chunk->obj_exts)) {
16501650
obj_cgroup_get(objcg);
1651-
chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg;
1651+
chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup = objcg;
16521652

16531653
rcu_read_lock();
16541654
mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B,
@@ -1663,13 +1663,13 @@ static void pcpu_memcg_free_hook(struct pcpu_chunk *chunk, int off, size_t size)
16631663
{
16641664
struct obj_cgroup *objcg;
16651665

1666-
if (unlikely(!chunk->obj_cgroups))
1666+
if (unlikely(!chunk->obj_exts))
16671667
return;
16681668

1669-
objcg = chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT];
1669+
objcg = chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup;
16701670
if (!objcg)
16711671
return;
1672-
chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = NULL;
1672+
chunk->obj_exts[off >> PCPU_MIN_ALLOC_SHIFT].cgroup = NULL;
16731673

16741674
obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size));
16751675

0 commit comments

Comments
 (0)