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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 19F30C433B4 for ; Wed, 5 May 2021 16:51:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ADC6B6141B for ; Wed, 5 May 2021 16:51:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADC6B6141B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE8276B006E; Wed, 5 May 2021 12:51:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8F366B0070; Wed, 5 May 2021 12:51:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 622396B0071; Wed, 5 May 2021 12:51:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 398F76B006E for ; Wed, 5 May 2021 12:51:22 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E1C5581E1 for ; Wed, 5 May 2021 16:51:21 +0000 (UTC) X-FDA: 78107767962.25.18F73D3 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf28.hostedemail.com (Postfix) with ESMTP id DC24620003BB for ; Wed, 5 May 2021 16:51:15 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id h10so2812390edt.13 for ; Wed, 05 May 2021 09:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LojNw03jpaoud1mN08MPpxuRhcuj9lI3TX5RGXeehmg=; b=wTlp9K2Q2Xv96007PiwKY/jru+Ohb3ch0S/6t2XIXDw2ODe5lvi2gLwnlyZ1rNwbMF LcFb4/KZU7VRn9Lse/8MH+ZjWdIAuiaUzAy1mYYrRKi5qtTPami9sMXMeFkwYp8YCiL8 eKhMPDV97PAo+Hrk9y7J2aEKPWjWDdPP33k/wP65eQZHotMsX4y+hr3TYYZROJqaIrTW e/Iu6vKI5XqcRhhmQAY74O7PoKpxQvoan3HZC3UQVblxTIVo0k1s9tLuRFiM02Wcxb3A 8Iy1pcbvqIBUNV59LRcj8hhHEuWGjsM3va3L+E1duQ4dIRQfoiJY/Ap2Qtid4cRc+fK5 ozqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LojNw03jpaoud1mN08MPpxuRhcuj9lI3TX5RGXeehmg=; b=FlIK3L75lIscOtgrsiGMES9L06j6AzdYT3ZvazawGCUipdfdKUcSIUckC0c+H+Fovc zNfkHh1KewbLfva7I+Y4x2jaHT85gOJztXWTvc648QTAmYHVx4Wx7rg+XeQmsEYPl63F 6MIjNZJ6PUl6rTXT7nTIutKmQBNT+1+E0BPFE8n9BEsQL1Ce9wVGWRqWnXSgBsRzk/H/ hmrcg1A2O6XIZ6V04oV0bwYlWzJujZiA3CZZyT/RGXgwcNo3xG5AOtqcZXoepBtNJoKQ 3CZXPzW7q+ejiEA1CH5nmMQJlNfGy3hZRiSqXm4nlr2SLjz4W3HvkP0wgx4h9Ge9T+Jb 9SPw== X-Gm-Message-State: AOAM530X7IvedD4O6WKjw3ROt1y3/kyPjRtmgWr1F8dTYtnF/ScIBCpY eNRTQX76J+47BGbsflLZhrBxUEJWlOIj4xqqo1ah80+P0wE= X-Google-Smtp-Source: ABdhPJzt0jB5rpAfTkUGxSG0noTVNMqIGE9U9VfWYa56x36a9dRYqTexkv3u2OLCm0zFG50xfKlKC4uRRYgkx01kxIo= X-Received: by 2002:a2e:a607:: with SMTP id v7mr22447523ljp.81.1620231470970; Wed, 05 May 2021 09:17:50 -0700 (PDT) MIME-Version: 1.0 References: <20210505154613.17214-1-longman@redhat.com> <20210505154613.17214-3-longman@redhat.com> In-Reply-To: <20210505154613.17214-3-longman@redhat.com> From: Shakeel Butt Date: Wed, 5 May 2021 09:17:40 -0700 Message-ID: Subject: Re: [PATCH v3 2/2] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Waiman Long Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , LKML , Cgroups , Linux MM Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=wTlp9K2Q; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of shakeelb@google.com designates 209.85.208.46 as permitted sender) smtp.mailfrom=shakeelb@google.com X-Rspamd-Server: rspam03 X-Stat-Signature: jiyrsr56gooznk75yy1e3xc6mwzrgh8f X-Rspamd-Queue-Id: DC24620003BB Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mail-ed1-f46.google.com; client-ip=209.85.208.46 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620233475-365326 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, May 5, 2021 at 8:47 AM Waiman Long wrote: > > There are currently two problems in the way the objcg pointer array > (memcg_data) in the page structure is being allocated and freed. > > On its allocation, it is possible that the allocated objcg pointer > array comes from the same slab that requires memory accounting. If this > happens, the slab will never become empty again as there is at least > one object left (the obj_cgroup array) in the slab. > > When it is freed, the objcg pointer array object may be the last one > in its slab and hence causes kfree() to be called again. With the > right workload, the slab cache may be set up in a way that allows the > recursive kfree() calling loop to nest deep enough to cause a kernel > stack overflow and panic the system. > > One way to solve this problem is to split the kmalloc- caches > (KMALLOC_NORMAL) into two separate sets - a new set of kmalloc- > (KMALLOC_NORMAL) caches for non-accounted objects only and a new set of > kmalloc-cg- (KMALLOC_CGROUP) caches for accounted objects only. All > the other caches can still allow a mix of accounted and non-accounted > objects. > > With this change, all the objcg pointer array objects will come from > KMALLOC_NORMAL caches which won't have their objcg pointer arrays. So > both the recursive kfree() problem and non-freeable slab problem are > gone. Since both the KMALLOC_NORMAL and KMALLOC_CGROUP caches no longer > have mixed accounted and unaccounted objects, this will slightly reduce > the number of objcg pointer arrays that need to be allocated and save > a bit of memory. > > The new KMALLOC_CGROUP is added between KMALLOC_NORMAL and > KMALLOC_RECLAIM so that the first for loop in create_kmalloc_caches() > will include the newly added caches without change. > > Suggested-by: Vlastimil Babka > Signed-off-by: Waiman Long One nit below and after incorporating Vlastimil's suggestions: Reviewed-by: Shakeel Butt > --- > include/linux/slab.h | 42 ++++++++++++++++++++++++++++++++++-------- > mm/slab_common.c | 23 +++++++++++++++-------- > 2 files changed, 49 insertions(+), 16 deletions(-) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 0c97d788762c..f2d9ebc34f5c 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -305,9 +305,16 @@ static inline void __check_heap_object(const void *ptr, unsigned long n, > /* > * Whenever changing this, take care of that kmalloc_type() and > * create_kmalloc_caches() still work as intended. > + * > + * KMALLOC_NORMAL is for non-accounted objects only whereas KMALLOC_CGROUP > + * is for accounted objects only. I think you can say "KMALLOC_CGROUP is for accounted and unreclaimable objects only".