Skip to content

Commit b2807f0

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: add "sock" to cgroup2 memory.stat
Provide statistics on how much of a cgroup's memory footprint is made up of socket buffers from network connections owned by the group. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Vladimir Davydov <vdavydov@virtuozzo.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 587d9f7 commit b2807f0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/linux/memcontrol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ enum mem_cgroup_stat_index {
5050
MEM_CGROUP_STAT_WRITEBACK, /* # of pages under writeback */
5151
MEM_CGROUP_STAT_SWAP, /* # of pages, swapped out */
5252
MEM_CGROUP_STAT_NSTATS,
53+
/* default hierarchy stats */
54+
MEMCG_SOCK,
55+
MEMCG_NR_STAT,
5356
};
5457

5558
struct mem_cgroup_reclaim_cookie {
@@ -87,7 +90,7 @@ enum mem_cgroup_events_target {
8790

8891
#ifdef CONFIG_MEMCG
8992
struct mem_cgroup_stat_cpu {
90-
long count[MEM_CGROUP_STAT_NSTATS];
93+
long count[MEMCG_NR_STAT];
9194
unsigned long events[MEMCG_NR_EVENTS];
9295
unsigned long nr_page_events;
9396
unsigned long targets[MEM_CGROUP_NTARGETS];

mm/memcontrol.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,8 @@ static int memory_stat_show(struct seq_file *m, void *v)
51285128
(u64)tree_stat(memcg, MEM_CGROUP_STAT_RSS) * PAGE_SIZE);
51295129
seq_printf(m, "file %llu\n",
51305130
(u64)tree_stat(memcg, MEM_CGROUP_STAT_CACHE) * PAGE_SIZE);
5131+
seq_printf(m, "sock %llu\n",
5132+
(u64)tree_stat(memcg, MEMCG_SOCK) * PAGE_SIZE);
51315133

51325134
seq_printf(m, "file_mapped %llu\n",
51335135
(u64)tree_stat(memcg, MEM_CGROUP_STAT_FILE_MAPPED) *
@@ -5631,6 +5633,8 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56315633
if (in_softirq())
56325634
gfp_mask = GFP_NOWAIT;
56335635

5636+
this_cpu_add(memcg->stat->count[MEMCG_SOCK], nr_pages);
5637+
56345638
if (try_charge(memcg, gfp_mask, nr_pages) == 0)
56355639
return true;
56365640

@@ -5650,6 +5654,8 @@ void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
56505654
return;
56515655
}
56525656

5657+
this_cpu_sub(memcg->stat->count[MEMCG_SOCK], nr_pages);
5658+
56535659
page_counter_uncharge(&memcg->memory, nr_pages);
56545660
css_put_many(&memcg->css, nr_pages);
56555661
}

0 commit comments

Comments
 (0)