Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1503945pxy; Thu, 6 May 2021 09:12:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaOq4tyOzYn9q2CUV6S9Td26Tvyjh1L66YGmSD1rHZp4C0O+tNUO7rvwfkGI/Cn10DhL1M X-Received: by 2002:aa7:cb52:: with SMTP id w18mr6156390edt.294.1620317529301; Thu, 06 May 2021 09:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620317529; cv=none; d=google.com; s=arc-20160816; b=y8ZtoPPYC8hwBKsdsLreI0UA4PeKXDrf2SxggXwAbpAgL1edJczRgH83aZWIJ4UgFp fbE39YE2vzka6hwgMitzHSr3ulG8CJpLaezQAdipOHNUaxIEd3G7/psVhYB+UCq+GWZW khB7i4LCFW/61TU0dmGt55nEwiEOC1sDpPD8Z1l/BibByaBZ7kOwFHr+UypTgFk0qCZ6 k3hHHC18PXzK+8BOO/dNLaP2PFYxywYOzs12YHyihUhio1oH1zfOY0kJ2tR4EznkllVT IiMYZNW3vgZw1jmTV3UmZ1jSoqifa8h5REvmMFU4bVm+dHMTTRwREzZGI8V0pb9nKnzE qMWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=6hHJ2if4WJkg2du4T57AGBZ6P/jf0214NaTU4kr7th0=; b=wo5nus83bgHDtLRpTGbljovj7t9vwdyt4DmdanfVctw4MP1g8RiZYyhLV7fKIxlS93 7Jq4CntoMBmVq7d2Udk6+gSfRSX5dx1cx/sTI2nfYK3xTukho1iJkDxfIyqi0N6xcwcT 85wgwbBr2FopJdJya2P/AXtVORP4y1QWcthfqcRPMDiDd51Xr6V+cPKOdArVnoAXdRce a5CX4oQFxJ3JUJDEXqwE7QmdFbB7Y3LxfpV4YjL4eo0jw1yhdzeTC4H6s2ydnxWfQuuA 4E+pcQa3rafkLzru2uGvB0Kodnzqy/biB9eUzShgwMR2oYb6iD2PiYXJGCDTWFhwWi3y 56oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d+zf6gym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si2540346eds.577.2021.05.06.09.11.43; Thu, 06 May 2021 09:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d+zf6gym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235583AbhEFQIi (ORCPT + 99 others); Thu, 6 May 2021 12:08:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235156AbhEFQIf (ORCPT ); Thu, 6 May 2021 12:08:35 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FC21C061574 for ; Thu, 6 May 2021 09:07:37 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id s25so7782021lji.0 for ; Thu, 06 May 2021 09:07:37 -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=6hHJ2if4WJkg2du4T57AGBZ6P/jf0214NaTU4kr7th0=; b=d+zf6gym8dKCyDd+UW2gOZhjv9TbxL+FJK8ovpix4foAPy8PgxTh8HkOnZDMQ/cd26 WGRoTUYFIYN69v5oodnGIbj20EyykcmxDgIZWoyp/1w0l9muEsYf9Uk/tfZiHoYJCBfi BCjZKZ5gq0Lxjohp3E8Pr6WYBt4oIh+6lw6uTaWaQZ2aBWi1SzUaRWklhTvAAPD58Zvj V5yJrXUENoSbELQPDjZoCE1TVtfzCVleSru6ZHEl5Txc5G5XcRPl/Lha+BpLumBgd911 uZnYv10zevCWk1djhUDzkakEUnhG6oLg7C6aFXvvUQ38kSYeZxkWHaU6gaPF22aPGCmt KSBw== 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=6hHJ2if4WJkg2du4T57AGBZ6P/jf0214NaTU4kr7th0=; b=ZDWQrth1wVJruiNoSrrtJGqzhHInhuneoHyvOGieO7B5ZNtpHJBSKIb6bY+28MGGt5 4mWkedXk0WtEY86dreZICIo0dyVO5AQd1i7IKfrKI3Z5ehrPW2aADB7nk22/WsbIYtQH Moned8ipEwi5KUrOeLHaynH/lGNkHiLO1uQOI3mHo/XiupC0vTJAKASd1s3eK5y+JqmX wydAtVGOHRrbNrxSFID/iN2lYLp67Vu/fUrjKnea4O2l4iFnngUHwk71twqiwlL6VXPd Qzj3CABm0t5AqGHp8SQ2N0WIHaJ3BgZsq2hTpd57v1RtGDBGiadRq+5eXDBl33uF6etN 3ukA== X-Gm-Message-State: AOAM530OJA8Nf89y5B78eW5my8ZWa/gRX24DPVmVfS6jLhuRjxWoZPtq UaQR9FUadagSIHY5kqcsJ64VdTVp8l1xQimmuQFgNA== X-Received: by 2002:a2e:a491:: with SMTP id h17mr4203019lji.34.1620317255566; Thu, 06 May 2021 09:07:35 -0700 (PDT) MIME-Version: 1.0 References: <20210505200610.13943-1-longman@redhat.com> <20210505200610.13943-3-longman@redhat.com> <3344a04c-0cff-b997-f357-2ffc8e3de242@suse.cz> In-Reply-To: <3344a04c-0cff-b997-f357-2ffc8e3de242@suse.cz> From: Shakeel Butt Date: Thu, 6 May 2021 09:07:24 -0700 Message-ID: Subject: Re: [PATCH v4 2/3] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Vlastimil Babka Cc: Waiman Long , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , LKML , Cgroups , Linux MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 6, 2021 at 9:00 AM Vlastimil Babka wrote: > > > On 5/5/21 10:06 PM, 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 unaccounted 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 unaccounted > > 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. On the other hand, creating a new set of kmalloc caches does > > have the effect of reducing cache utilization. So it is properly a wash. > > > > 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 > > Reviewed-by: Shakeel Butt > > Reviewed-by: Vlastimil Babka > > I still believe the cgroup.memory=nokmem parameter should be respected, > otherwise the caches are not only created, but also used. I offer this followup > for squashing into your patch if you and Andrew agree: > > ----8<---- > From c87378d437d9a59b8757033485431b4721c74173 Mon Sep 17 00:00:00 2001 > From: Vlastimil Babka > Date: Thu, 6 May 2021 17:53:21 +0200 > Subject: [PATCH] mm: memcg/slab: don't create kmalloc-cg caches with > cgroup.memory=nokmem > > The caches should not be created when kmemcg is disabled on boot, otherwise > they are also filled by kmalloc(__GFP_ACCOUNT) allocations. When booted with > cgroup.memory=nokmem, link the kmalloc_caches[KMALLOC_CGROUP] entries to > KMALLOC_NORMAL entries instead. > > Signed-off-by: Vlastimil Babka Yes this makes sense: Reviewed-by: Shakeel Butt