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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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=ham 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 85586C433B4 for ; Wed, 12 May 2021 14:54:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 13A8C61434 for ; Wed, 12 May 2021 14:54:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13A8C61434 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 72F956B0036; Wed, 12 May 2021 10:54:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DDB56B006E; Wed, 12 May 2021 10:54:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5579F6B0070; Wed, 12 May 2021 10:54:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 201056B0036 for ; Wed, 12 May 2021 10:54:28 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B4071180219EB for ; Wed, 12 May 2021 14:54:27 +0000 (UTC) X-FDA: 78132874974.01.403C2A0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf03.hostedemail.com (Postfix) with ESMTP id DD5E9C0007CA for ; Wed, 12 May 2021 14:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620831266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SWpKC9JIophhOJfSAOpwo9ri4mX92NQqXeS4GIIdLL0=; b=gXhD6TJnCys8o1nXL2b3ZiAt1U4OuiXDL5LqIGy6C1yGTw0LU0qRNwzNtd/WDzySSARGDc jsgk/JeoM2SIVgc4+VpVTowsWR53rlTEGMiA0kZHrMq2JVw3i5mCDHgxfjNxYJ3wPac7aH RgrCYmDLjVb+11Th6g8VwCJZmKQqfoo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-iNyMsuTXMAu-4Yegm8886Q-1; Wed, 12 May 2021 10:54:25 -0400 X-MC-Unique: iNyMsuTXMAu-4Yegm8886Q-1 Received: by mail-qk1-f198.google.com with SMTP id n142-20020a3727940000b02902fa8eadfa9eso3810290qkn.7 for ; Wed, 12 May 2021 07:54:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=SWpKC9JIophhOJfSAOpwo9ri4mX92NQqXeS4GIIdLL0=; b=lX9rD5rpvRLMkntiYS6jtZ6y1sxFq0WEBK0PdrJNOSMQNJr5PaFCLHOkbwqhTgrj2R XeR8S8fY4narFNFcLXdYGyQGVP21094YdtoaTSSDcJLq/qa6x3QB9IIpzTj/Q4Ys4ePL C1/zCRGXTMNlS1hDjTwYdwQr/km6atwMuKQsrKF6XG+DACF8mtuPnU2dHQksECX9dpR5 /xBXGJhW1XhiEiDSiQ7r22hCvs6A/s2shiH62Vdx+UE0jXLTkSBKyx8b/QaNtnDEqEK5 l7xNvZ5hNDAmkXecTBk18pyYRr7QEF+JfbLc+WbVZxgetcH0TsWlHmg2PRJZXaeFDL56 U6Yw== X-Gm-Message-State: AOAM533xshW8kYwXpunK5bJu5QcmvywDflRpygm1C39bVL6ONchtFZnW 1xZmng/J5xcxLdvRe1aBHMxmLZXv2JgWpB4XJw46Kpuxo/wVLEbICGukiximVOnHzvT3ZV/0eR2 AGXzcKwAKFCy2uKKDJILagJES8YFWnP2klk/anvpUMzXBFzEJDKmS8ug1GWI= X-Received: by 2002:a05:620a:c0e:: with SMTP id l14mr24851162qki.412.1620831264264; Wed, 12 May 2021 07:54:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH+jPwrKP0yv0MxyEF1dPob8sCiBz+ZLYo2X8hu2Y0zomLvphdBaJMFhPfkm2N3VNTozX87A== X-Received: by 2002:a05:620a:c0e:: with SMTP id l14mr24851118qki.412.1620831263957; Wed, 12 May 2021 07:54:23 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id r125sm214893qkf.24.2021.05.12.07.54.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 May 2021 07:54:23 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v5 2/3] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , 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> <20210512145107.6208-1-longman@redhat.com> Message-ID: <0919aaab-cc08-f86d-1f9a-8ddfeed7bb31@redhat.com> Date: Wed, 12 May 2021 10:54:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210512145107.6208-1-longman@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gXhD6TJn; spf=none (imf03.hostedemail.com: domain of llong@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=llong@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: DD5E9C0007CA X-Stat-Signature: c3zbyi1c9cpgdjy3ttmanf69s1m1e476 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620831258-757579 Content-Transfer-Encoding: quoted-printable 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 5/12/21 10:51 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 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. > > Signed-off-by: Waiman Long > Suggested-by: Vlastimil Babka > Reviewed-by: Shakeel Butt > Acked-by: Roman Gushchin > --- > include/linux/slab.h | 42 +++++++++++++++++++++++++++++++++--------- > mm/slab_common.c | 25 +++++++++++++++++-------- > 2 files changed, 50 insertions(+), 17 deletions(-) The following are the diff's from previous version. It turns out that=20 the previous patch doesn't work if CONFIG_ZONE_DMA isn't defined. diff --git a/include/linux/slab.h b/include/linux/slab.h index a51cad5f561c..aa7f6c222a60 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -312,16 +312,17 @@ static inline void __check_heap_object(const void=20 *ptr, un signed long n, =C2=A0 */ =C2=A0enum kmalloc_cache_type { =C2=A0=C2=A0=C2=A0=C2=A0 KMALLOC_NORMAL =3D 0, -#ifdef CONFIG_MEMCG_KMEM -=C2=A0=C2=A0=C2=A0 KMALLOC_CGROUP, -#else +#ifndef CONFIG_ZONE_DMA +=C2=A0=C2=A0=C2=A0 KMALLOC_DMA =3D KMALLOC_NORMAL, +#endif +#ifndef CONFIG_MEMCG_KMEM =C2=A0=C2=A0=C2=A0=C2=A0 KMALLOC_CGROUP =3D KMALLOC_NORMAL, +#else +=C2=A0=C2=A0=C2=A0 KMALLOC_CGROUP, =C2=A0#endif =C2=A0=C2=A0=C2=A0=C2=A0 KMALLOC_RECLAIM, =C2=A0#ifdef CONFIG_ZONE_DMA =C2=A0=C2=A0=C2=A0=C2=A0 KMALLOC_DMA, -#else -=C2=A0=C2=A0=C2=A0 KMALLOC_DMA =3D KMALLOC_NORMAL, =C2=A0#endif =C2=A0=C2=A0=C2=A0=C2=A0 NR_KMALLOC_TYPES =C2=A0}; Cheers, Longman