From: Roman Gushchin <guro@fb.com>
To: <linux-mm@kvack.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
=Shakeel Butt <shakeelb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>, <kernel-team@fb.com>,
<linux-kernel@vger.kernel.org>, Roman Gushchin <guro@fb.com>
Subject: [PATCH RFC 4/4] mm: kmem: enable kernel memcg accounting from interrupt contexts
Date: Thu, 27 Aug 2020 10:52:15 -0700 [thread overview]
Message-ID: <20200827175215.319780-5-guro@fb.com> (raw)
In-Reply-To: <20200827175215.319780-1-guro@fb.com>
If a memcg to charge can be determined (using remote charging API),
there are no reasons to exclude allocations made from an interrupt
context from the accounting.
Such allocations will pass even if the resulting memcg size will
exceed the hard limit, but it will affect the application of the
memory pressure and an inability to put the workload under the limit
will eventually trigger the OOM.
To use active_memcg() helper, memcg_kmem_bypass() is moved back
to memcontrol.c.
Signed-off-by: Roman Gushchin <guro@fb.com>
---
include/linux/memcontrol.h | 12 ------------
mm/memcontrol.c | 13 +++++++++++++
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index d0b036123c6a..924177502479 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -1528,18 +1528,6 @@ static inline bool memcg_kmem_enabled(void)
return static_branch_likely(&memcg_kmem_enabled_key);
}
-static inline bool memcg_kmem_bypass(void)
-{
- if (in_interrupt())
- return true;
-
- /* Allow remote memcg charging in kthread contexts. */
- if ((!current->mm || (current->flags & PF_KTHREAD)) &&
- !current->active_memcg)
- return true;
- return false;
-}
-
static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
int order)
{
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a51a6066079e..75cd1a1e66c8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1098,6 +1098,19 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
return memcg;
}
+static __always_inline bool memcg_kmem_bypass(void)
+{
+ /* Allow remote memcg charging from any context. */
+ if (unlikely(active_memcg()))
+ return false;
+
+ /* Memcg to charge can't be determined. */
+ if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
+ return true;
+
+ return false;
+}
+
/**
* If active memcg is set, do not fallback to current->mm->memcg.
*/
--
2.26.2
next prev parent reply other threads:[~2020-08-27 17:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 17:52 [PATCH RFC 0/4] mm: kmem: kernel memory accounting in an interrupt context Roman Gushchin
2020-08-27 17:52 ` [PATCH RFC 1/4] mm: kmem: move memcg_kmem_bypass() calls to get_mem/obj_cgroup_from_current() Roman Gushchin
2020-08-27 21:10 ` Shakeel Butt
2020-08-27 17:52 ` [PATCH RFC 2/4] mm: kmem: remove redundant checks from get_obj_cgroup_from_current() Roman Gushchin
2020-08-27 21:10 ` Shakeel Butt
2020-08-27 17:52 ` [PATCH RFC 3/4] mm: kmem: prepare remote memcg charging infra for interrupt contexts Roman Gushchin
2020-08-27 21:58 ` Shakeel Butt
2020-08-27 22:37 ` Roman Gushchin
2020-08-27 17:52 ` Roman Gushchin [this message]
2020-08-27 22:02 ` [PATCH RFC 4/4] mm: kmem: enable kernel memcg accounting from " Shakeel Butt
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=20200827175215.319780-5-guro@fb.com \
--to=guro@fb.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=shakeelb@google.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