From: Waiman Long <longman@redhat.com> To: Johannes Weiner <hannes@cmpxchg.org>, Michal Hocko <mhocko@kernel.org>, Vladimir Davydov <vdavydov.dev@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, Vlastimil Babka <vbabka@suse.cz>, Roman Gushchin <guro@fb.com> Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt <shakeelb@google.com>, Muchun Song <songmuchun@bytedance.com>, Waiman Long <longman@redhat.com> Subject: [PATCH 1/3] mm, memcg: Don't put offlined memcg into local stock Date: Fri, 1 Oct 2021 15:09:36 -0400 [thread overview] Message-ID: <20211001190938.14050-2-longman@redhat.com> (raw) In-Reply-To: <20211001190938.14050-1-longman@redhat.com> When freeing a page associated with an offlined memcg, refill_stock() will put it into local stock delaying its demise until another memcg comes in to take its place in the stock. To avoid that, we now check for offlined memcg and go directly in this case to the slowpath for the uncharge via the repurposed cancel_charge() function. Signed-off-by: Waiman Long <longman@redhat.com> --- mm/memcontrol.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4b32896d87a2..4568363062c1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2167,6 +2167,8 @@ static bool consume_stock(struct mem_cgroup *memcg, unsigned int nr_pages) return ret; } +static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages); + /* * Returns stocks cached in percpu and reset cached information. */ @@ -2178,9 +2180,7 @@ static void drain_stock(struct memcg_stock_pcp *stock) return; if (stock->nr_pages) { - page_counter_uncharge(&old->memory, stock->nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&old->memsw, stock->nr_pages); + cancel_charge(old, stock->nr_pages); stock->nr_pages = 0; } @@ -2219,6 +2219,14 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) struct memcg_stock_pcp *stock; unsigned long flags; + /* + * An offlined memcg shouldn't be put into stock. + */ + if (unlikely(memcg->kmem_state != KMEM_ONLINE)) { + cancel_charge(memcg, nr_pages); + return; + } + local_irq_save(flags); stock = this_cpu_ptr(&memcg_stock); @@ -2732,7 +2740,6 @@ static inline int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, return try_charge_memcg(memcg, gfp_mask, nr_pages); } -#if defined(CONFIG_MEMCG_KMEM) || defined(CONFIG_MMU) static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) { if (mem_cgroup_is_root(memcg)) @@ -2742,7 +2749,6 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) if (do_memsw_account()) page_counter_uncharge(&memcg->memsw, nr_pages); } -#endif static void commit_charge(struct folio *folio, struct mem_cgroup *memcg) { -- 2.18.1
WARNING: multiple messages have this Message-ID (diff)
From: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> To: Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>, Michal Hocko <mhocko-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, Vladimir Davydov <vdavydov.dev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>, Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>, Vlastimil Babka <vbabka-AlSwsSmVLrQ@public.gmane.org>, Roman Gushchin <guro-b10kYP2dOMg@public.gmane.org> Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Shakeel Butt <shakeelb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>, Muchun Song <songmuchun-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org>, Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Subject: [PATCH 1/3] mm, memcg: Don't put offlined memcg into local stock Date: Fri, 1 Oct 2021 15:09:36 -0400 [thread overview] Message-ID: <20211001190938.14050-2-longman@redhat.com> (raw) In-Reply-To: <20211001190938.14050-1-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> When freeing a page associated with an offlined memcg, refill_stock() will put it into local stock delaying its demise until another memcg comes in to take its place in the stock. To avoid that, we now check for offlined memcg and go directly in this case to the slowpath for the uncharge via the repurposed cancel_charge() function. Signed-off-by: Waiman Long <longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> --- mm/memcontrol.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4b32896d87a2..4568363062c1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2167,6 +2167,8 @@ static bool consume_stock(struct mem_cgroup *memcg, unsigned int nr_pages) return ret; } +static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages); + /* * Returns stocks cached in percpu and reset cached information. */ @@ -2178,9 +2180,7 @@ static void drain_stock(struct memcg_stock_pcp *stock) return; if (stock->nr_pages) { - page_counter_uncharge(&old->memory, stock->nr_pages); - if (do_memsw_account()) - page_counter_uncharge(&old->memsw, stock->nr_pages); + cancel_charge(old, stock->nr_pages); stock->nr_pages = 0; } @@ -2219,6 +2219,14 @@ static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages) struct memcg_stock_pcp *stock; unsigned long flags; + /* + * An offlined memcg shouldn't be put into stock. + */ + if (unlikely(memcg->kmem_state != KMEM_ONLINE)) { + cancel_charge(memcg, nr_pages); + return; + } + local_irq_save(flags); stock = this_cpu_ptr(&memcg_stock); @@ -2732,7 +2740,6 @@ static inline int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, return try_charge_memcg(memcg, gfp_mask, nr_pages); } -#if defined(CONFIG_MEMCG_KMEM) || defined(CONFIG_MMU) static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) { if (mem_cgroup_is_root(memcg)) @@ -2742,7 +2749,6 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) if (do_memsw_account()) page_counter_uncharge(&memcg->memsw, nr_pages); } -#endif static void commit_charge(struct folio *folio, struct mem_cgroup *memcg) { -- 2.18.1
next prev parent reply other threads:[~2021-10-01 19:10 UTC|newest] Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-01 19:09 [PATCH 0/3] mm, memcg: Miscellaneous cleanups Waiman Long 2021-10-01 19:09 ` Waiman Long 2021-10-01 19:09 ` Waiman Long [this message] 2021-10-01 19:09 ` [PATCH 1/3] mm, memcg: Don't put offlined memcg into local stock Waiman Long 2021-10-01 21:17 ` kernel test robot 2021-10-01 21:17 ` kernel test robot 2021-10-01 21:17 ` kernel test robot 2021-10-01 23:06 ` kernel test robot 2021-10-01 23:06 ` kernel test robot 2021-10-01 23:06 ` kernel test robot 2021-10-01 23:51 ` Roman Gushchin 2021-10-01 23:51 ` Roman Gushchin 2021-10-02 1:54 ` Waiman Long 2021-10-02 1:54 ` Waiman Long 2022-01-31 3:55 ` Waiman Long 2022-01-31 3:55 ` Waiman Long 2022-01-31 17:01 ` Roman Gushchin 2022-01-31 17:01 ` Roman Gushchin 2022-01-31 17:09 ` Waiman Long 2022-01-31 17:15 ` Waiman Long 2022-01-31 17:19 ` Roman Gushchin 2022-01-31 17:19 ` Roman Gushchin 2022-01-31 17:25 ` Waiman Long 2022-01-31 17:25 ` Waiman Long 2022-01-31 18:00 ` Shakeel Butt 2022-01-31 18:00 ` Shakeel Butt 2022-01-31 17:15 ` Roman Gushchin 2022-01-31 17:15 ` Roman Gushchin 2021-10-01 19:09 ` [PATCH 2/3] mm, memcg: Remove obsolete memcg_free_kmem() Waiman Long 2021-10-01 19:09 ` Waiman Long 2021-10-02 0:01 ` Roman Gushchin 2021-10-02 0:01 ` Roman Gushchin 2021-10-02 2:03 ` Waiman Long 2021-10-01 19:09 ` [PATCH 3/3] mm, memcg: Ensure valid memcg from objcg within a RCU critical section Waiman Long 2021-10-01 19:09 ` Waiman Long 2021-10-01 20:24 ` Shakeel Butt 2021-10-01 20:24 ` Shakeel Butt 2021-10-01 20:24 ` Shakeel Butt 2021-10-01 20:34 ` Waiman Long
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=20211001190938.14050-2-longman@redhat.com \ --to=longman@redhat.com \ --cc=akpm@linux-foundation.org \ --cc=cgroups@vger.kernel.org \ --cc=guro@fb.com \ --cc=hannes@cmpxchg.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@kernel.org \ --cc=shakeelb@google.com \ --cc=songmuchun@bytedance.com \ --cc=vbabka@suse.cz \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.