linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Balbir Singh <bsingharora@gmail.com>
To: linux-mm@kvack.org, mhocko@kernel.org
Cc: hannes@cmpxchg.org, vdavydov.dev@gmail.com,
	Balbir Singh <bsingharora@gmail.com>
Subject: [PATCH] mm/list_lru: dont make them memcg aware if kmem is disabled
Date: Thu, 26 Nov 2020 15:30:23 +1100	[thread overview]
Message-ID: <20201126043023.377343-1-bsingharora@gmail.com> (raw)

When alloc_super() allocates list_lrus for dentries and inodes
they are made memcg aware if KMEM is compiled in, we should
also check if kmem was disabled at runtime.

This overhead is about 32 bytes extra per possible nodes per caller
of list_lru_init()

Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
 include/linux/memcontrol.h | 6 ++++++
 mm/list_lru.c              | 9 +++++++++
 mm/memcontrol.c            | 9 +++++++++
 3 files changed, 24 insertions(+)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 4a4df9a23a8b..4285741a855d 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1636,6 +1636,7 @@ static inline bool memcg_kmem_enabled(void)
 	return static_branch_likely(&memcg_kmem_enabled_key);
 }
 
+extern bool cgroup_kmem_disabled(void);
 static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
 					 int order)
 {
@@ -1691,6 +1692,11 @@ static inline bool memcg_kmem_enabled(void)
 	return false;
 }
 
+static inline bool cgroup_kmem_disabled(void)
+{
+	return false;
+}
+
 static inline int memcg_cache_id(struct mem_cgroup *memcg)
 {
 	return -1;
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 5aa6e44bc2ae..478386aa9852 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -439,6 +439,15 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware)
 {
 	int i;
 
+	/*
+	 * Override memcg_aware  here, otherwise callers
+	 * will allocate memcg aware lru's and that wastes
+	 * memory and the amount can scale with the number of
+	 * nodes and caller contexts.
+	 */
+	if (cgroup_kmem_disabled())
+		memcg_aware = false;
+
 	lru->memcg_aware = memcg_aware;
 
 	if (!memcg_aware)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 15f2396f1605..8edf3ada8f4e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -99,6 +99,15 @@ static bool do_memsw_account(void)
 	return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_noswap;
 }
 
+/*
+ * NOTE: This is not the logical opposite of what
+ * memcg_kmem_enabled() does
+ */
+bool cgroup_kmem_disabled(void)
+{
+	return cgroup_memory_nokmem;
+}
+
 #define THRESHOLDS_EVENTS_TARGET 128
 #define SOFTLIMIT_EVENTS_TARGET 1024
 
-- 
2.25.1



             reply	other threads:[~2020-11-26  4:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26  4:30 Balbir Singh [this message]
2020-11-26 12:10 ` Vlastimil Babka
2020-11-27  9:21   ` Balbir Singh
2020-11-28  3:49     ` Andrew Morton
2020-11-28 11:47       ` Balbir Singh

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=20201126043023.377343-1-bsingharora@gmail.com \
    --to=bsingharora@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=vdavydov.dev@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