Skip to content

Commit 4d5c8ae

Browse files
rgushchindennisszhou
authored andcommitted
mm, memcg: introduce mem_cgroup_kmem_disabled()
Introduce a new mem_cgroup_kmem_disabled() helper, similar to mem_cgroup_disabled(), to check whether the kernel memory accounting is off. A user could disable it using a boot option to eliminate some associated costs. The helper can be used outside of memcontrol.c to dynamically disable the kmem-related code. The returned value is stable after the kernel initialization is finished. Signed-off-by: Roman Gushchin <[email protected]> Signed-off-by: Dennis Zhou <[email protected]>
1 parent 0f0cace commit 4d5c8ae

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/linux/memcontrol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,7 @@ static inline void memcg_set_shrinker_bit(struct mem_cgroup *memcg,
15831583
#endif
15841584

15851585
#ifdef CONFIG_MEMCG_KMEM
1586+
bool mem_cgroup_kmem_disabled(void);
15861587
int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order);
15871588
void __memcg_kmem_uncharge_page(struct page *page, int order);
15881589

@@ -1636,6 +1637,10 @@ static inline int memcg_cache_id(struct mem_cgroup *memcg)
16361637
struct mem_cgroup *mem_cgroup_from_obj(void *p);
16371638

16381639
#else
1640+
static inline bool mem_cgroup_kmem_disabled(void)
1641+
{
1642+
return true;
1643+
}
16391644

16401645
static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
16411646
int order)

mm/memcontrol.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ struct cgroup_subsys_state *vmpressure_to_css(struct vmpressure *vmpr)
255255
#ifdef CONFIG_MEMCG_KMEM
256256
extern spinlock_t css_set_lock;
257257

258+
bool mem_cgroup_kmem_disabled(void)
259+
{
260+
return cgroup_memory_nokmem;
261+
}
262+
258263
static int __memcg_kmem_charge(struct mem_cgroup *memcg, gfp_t gfp,
259264
unsigned int nr_pages);
260265
static void __memcg_kmem_uncharge(struct mem_cgroup *memcg,

0 commit comments

Comments
 (0)