From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E86D8C433B4 for ; Thu, 6 May 2021 15:39:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB00B610A7 for ; Thu, 6 May 2021 15:39:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235841AbhEFPkB (ORCPT ); Thu, 6 May 2021 11:40:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:41890 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236172AbhEFPiY (ORCPT ); Thu, 6 May 2021 11:38:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 45852B207; Thu, 6 May 2021 15:37:25 +0000 (UTC) Subject: Re: [PATCH v4 1/3] mm: memcg/slab: Properly set up gfp flags for objcg pointer array To: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Shakeel Butt Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20210505200610.13943-1-longman@redhat.com> <20210505200610.13943-2-longman@redhat.com> From: Vlastimil Babka Message-ID: <46fb83c8-d875-9f85-da2c-ac2ba4847c07@suse.cz> Date: Thu, 6 May 2021 17:37:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210505200610.13943-2-longman@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/5/21 10:06 PM, Waiman Long wrote: > Since the merging of the new slab memory controller in v5.9, the page > structure may store a pointer to obj_cgroup pointer array for slab pages. > Currently, only the __GFP_ACCOUNT bit is masked off. However, the array > is not readily reclaimable and doesn't need to come from the DMA buffer. > So those GFP bits should be masked off as well. > > Do the flag bit clearing at memcg_alloc_page_obj_cgroups() to make sure > that it is consistently applied no matter where it is called. > > Fixes: 286e04b8ed7a ("mm: memcg/slab: allocate obj_cgroups for non-root slab pages") > Signed-off-by: Waiman Long > Reviewed-by: Shakeel Butt Reviewed-by: Vlastimil Babka > --- > mm/memcontrol.c | 8 ++++++++ > mm/slab.h | 1 - > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c100265dc393..5e3b4f23b830 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2863,6 +2863,13 @@ static struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *objcg) > } > > #ifdef CONFIG_MEMCG_KMEM > +/* > + * The allocated objcg pointers array is not accounted directly. > + * Moreover, it should not come from DMA buffer and is not readily > + * reclaimable. So those GFP bits should be masked off. > + */ > +#define OBJCGS_CLEAR_MASK (__GFP_DMA | __GFP_RECLAIMABLE | __GFP_ACCOUNT) > + > int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s, > gfp_t gfp, bool new_page) > { > @@ -2870,6 +2877,7 @@ int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s, > unsigned long memcg_data; > void *vec; > > + gfp &= ~OBJCGS_CLEAR_MASK; > vec = kcalloc_node(objects, sizeof(struct obj_cgroup *), gfp, > page_to_nid(page)); > if (!vec) > diff --git a/mm/slab.h b/mm/slab.h > index 18c1927cd196..b3294712a686 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -309,7 +309,6 @@ static inline void memcg_slab_post_alloc_hook(struct kmem_cache *s, > if (!memcg_kmem_enabled() || !objcg) > return; > > - flags &= ~__GFP_ACCOUNT; > for (i = 0; i < size; i++) { > if (likely(p[i])) { > page = virt_to_head_page(p[i]); > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vlastimil Babka Subject: Re: [PATCH v4 1/3] mm: memcg/slab: Properly set up gfp flags for objcg pointer array Date: Thu, 6 May 2021 17:37:24 +0200 Message-ID: <46fb83c8-d875-9f85-da2c-ac2ba4847c07@suse.cz> References: <20210505200610.13943-1-longman@redhat.com> <20210505200610.13943-2-longman@redhat.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20210505200610.13943-2-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Content-Language: en-US List-ID: Content-Type: text/plain; charset="us-ascii" To: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Shakeel Butt Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org On 5/5/21 10:06 PM, Waiman Long wrote: > Since the merging of the new slab memory controller in v5.9, the page > structure may store a pointer to obj_cgroup pointer array for slab pages. > Currently, only the __GFP_ACCOUNT bit is masked off. However, the array > is not readily reclaimable and doesn't need to come from the DMA buffer. > So those GFP bits should be masked off as well. > > Do the flag bit clearing at memcg_alloc_page_obj_cgroups() to make sure > that it is consistently applied no matter where it is called. > > Fixes: 286e04b8ed7a ("mm: memcg/slab: allocate obj_cgroups for non-root slab pages") > Signed-off-by: Waiman Long > Reviewed-by: Shakeel Butt Reviewed-by: Vlastimil Babka > --- > mm/memcontrol.c | 8 ++++++++ > mm/slab.h | 1 - > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c100265dc393..5e3b4f23b830 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -2863,6 +2863,13 @@ static struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *objcg) > } > > #ifdef CONFIG_MEMCG_KMEM > +/* > + * The allocated objcg pointers array is not accounted directly. > + * Moreover, it should not come from DMA buffer and is not readily > + * reclaimable. So those GFP bits should be masked off. > + */ > +#define OBJCGS_CLEAR_MASK (__GFP_DMA | __GFP_RECLAIMABLE | __GFP_ACCOUNT) > + > int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s, > gfp_t gfp, bool new_page) > { > @@ -2870,6 +2877,7 @@ int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s, > unsigned long memcg_data; > void *vec; > > + gfp &= ~OBJCGS_CLEAR_MASK; > vec = kcalloc_node(objects, sizeof(struct obj_cgroup *), gfp, > page_to_nid(page)); > if (!vec) > diff --git a/mm/slab.h b/mm/slab.h > index 18c1927cd196..b3294712a686 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -309,7 +309,6 @@ static inline void memcg_slab_post_alloc_hook(struct kmem_cache *s, > if (!memcg_kmem_enabled() || !objcg) > return; > > - flags &= ~__GFP_ACCOUNT; > for (i = 0; i < size; i++) { > if (likely(p[i])) { > page = virt_to_head_page(p[i]); >