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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 2BDA4C433B4 for ; Thu, 6 May 2021 16:07:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 77CBC610C8 for ; Thu, 6 May 2021 16:07:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 77CBC610C8 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 9483C6B006E; Thu, 6 May 2021 12:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 91EDC6B0070; Thu, 6 May 2021 12:07:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 771FF6B0072; Thu, 6 May 2021 12:07:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 585DA6B006E for ; Thu, 6 May 2021 12:07:43 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E9905181AEF1A for ; Thu, 6 May 2021 16:07:42 +0000 (UTC) X-FDA: 78111286764.20.A0BB8E4 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by imf10.hostedemail.com (Postfix) with ESMTP id 86CC54080F63 for ; Thu, 6 May 2021 16:07:23 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id u25so7744397ljg.7 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=Ue7sVovcUV6CmXifOBMTXzEmnUH8IS0ZsqWbdCj3wCSCHpfIYnmBjr3rQOFCvekKrr ecDWYgkOXgYGEWbDdVgY4Y3lx1O0/M+UVz2vdoAxdRCGGbGVPYhUllVXkmer2gx3p7Zi SD+pmBix3jJviZyyIs1ZamaDbott7Ox1tDP0/aSYoBqL2aBEHP7vVos5lQGuPa8F3XTq 8GDrte514Nd3LJvNHnQwXfMdkcURwCTlwwCKeTzntZt33grYI1AflBHDEOLe+ujCUbaU A3SDP5ccZ8F4TY37j6u5vNy27HKsuL+2J/+0CfDTiT3tAlqXn2n/iYg/65KsFg/3dibr q85Q== X-Gm-Message-State: AOAM530oZQ1RpGQveb9oBe9qDlRCPdcY7irLKW6u4DJdC++KwA3kEnap o1GcMt2BKzwODETUL/DDd1sbNnglYEjo3aFDl7hXRw== X-Google-Smtp-Source: ABdhPJzn2EhM7XMXkXkyTxRS57EaFcBBQXV19tsKpHBUxqufilM9fckZn6puZV9zDw22uUMMC4ZL5urO+Urx9IobDGo= 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" X-Rspamd-Queue-Id: 86CC54080F63 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=d+zf6gym; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of shakeelb@google.com designates 209.85.208.182 as permitted sender) smtp.mailfrom=shakeelb@google.com X-Rspamd-Server: rspam04 X-Stat-Signature: q64cqq6hdwawxxpynxgii7oacd1b3x5s Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-lj1-f182.google.com; client-ip=209.85.208.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620317243-953369 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 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