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=-17.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 18D2EC433B4 for ; Wed, 5 May 2021 16:34:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 822EC6157E for ; Wed, 5 May 2021 16:34:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 822EC6157E 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 F2EB58D0001; Wed, 5 May 2021 12:34:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0D7F6B0072; Wed, 5 May 2021 12:34:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D91238D0001; Wed, 5 May 2021 12:34:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id BF9B96B0071 for ; Wed, 5 May 2021 12:34:02 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7A147180AD837 for ; Wed, 5 May 2021 16:34:02 +0000 (UTC) X-FDA: 78107724324.22.F4EF5BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 65D23200099D for ; Wed, 5 May 2021 16:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620232406; 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=zS3Ldg5vG9J3xehl8TqywjLJpgOH5ZU3rYG0PyHSqeM=; b=QmsVEi2Sok9hBeRTGAhin+LElvZu3t/RaPYi3MNuF6uAj451Np62uB4bF6E0r3GwGR2ov9 JhfrSwi+6f+2JnBxhUwKPcFqsa0iWHZmaK6Dg4H3NeSv1HJPz2aslRd6KYLPJhZQY/Hna3 7WkuJbjUCGrLAJbtKdbMjFDLTj6Ziew= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620232441; 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=zS3Ldg5vG9J3xehl8TqywjLJpgOH5ZU3rYG0PyHSqeM=; b=HtANYrOo87mK11iL++RBxdJ3pAcqrG4uxEv54Ew1pS+b1vKiigRgtob/LgmMvzFWe/TJiW eQTWKRR80qb50xtY3Nfnx8D8NE1QwXdwwKyMPXWYM12dSP82kL/QyAH3g8a0y5Jy7O4Ev6 5JUFzTlaiQlDgvuWHkIKKdGCn1/wwb4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-UJ-Ax8-TOwmvRil1jzlcyw-1; Wed, 05 May 2021 12:32:00 -0400 X-MC-Unique: UJ-Ax8-TOwmvRil1jzlcyw-1 Received: by mail-qv1-f71.google.com with SMTP id x6-20020a0cda060000b02901c4b3f7d3d9so2119498qvj.0 for ; Wed, 05 May 2021 09:32:00 -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=zS3Ldg5vG9J3xehl8TqywjLJpgOH5ZU3rYG0PyHSqeM=; b=aV8ez9RIPLOy3FajhJ1vzfh5xMwFDrEcM4/ZQRYFVaSm8zYQ2Pv3RXgaTizzd3eeZZ vPns32+CiO/llht1nLqmgnvKBgtxcsQNqAvM3l9o7hLSoy+U2ivKSQJnSBiV+7qUYoZF 0qUHvqJ7Fdp3Hezhf06LqmXwBumRO2+Al58XZYx0Cg3vJg199MKz4yrb+dSrq1XRfAL8 GHjvb78smAz9QwnojbycTwWPUTZDW58yNJBjIWS+Al8KKczUxnLpPLbSP+g5c1hsOa1J uPnermHl9FyUqxPjf39V8+EI+hrLyo8OS3yx8PFh0lvlTSPjTsFNd9evWcUR20jxSJ+x 071g== X-Gm-Message-State: AOAM533vIlOlEKa8Mdfm07bY8JHIeDkIZnWAKkjnV7jCIdzHeQno3/5Y T/HZIR5Ffv5gV1u2oMOkSTKHPYAagmpOWFAsnH/qHBNupPfAJ61cRsJNz/258LVDpDTRyyuhuRD 1AT0t0LHHU9A4rUfAB5L6T4dwEJu4mHNKWt0mTzayvdaiV7bmm9U8yeptdEM= X-Received: by 2002:a37:ae04:: with SMTP id x4mr30811452qke.245.1620232319775; Wed, 05 May 2021 09:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzapoUleiXdFkf8r1cnEmwbpWr9agCgZfPPLWunF6QFzhEPni5JL8P9LUWVyMAcGIOFvgnxQ== X-Received: by 2002:a37:ae04:: with SMTP id x4mr30811377qke.245.1620232318969; Wed, 05 May 2021 09:31:58 -0700 (PDT) Received: from llong.remote.csb ([2601:191:8500:76c0::cdbc]) by smtp.gmail.com with ESMTPSA id j9sm6455868qtl.15.2021.05.05.09.31.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 May 2021 09:31:58 -0700 (PDT) From: Waiman Long X-Google-Original-From: Waiman Long Subject: Re: [PATCH v3 2/2] mm: memcg/slab: Create a new set of kmalloc-cg- caches To: Shakeel Butt 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 References: <20210505154613.17214-1-longman@redhat.com> <20210505154613.17214-3-longman@redhat.com> Message-ID: Date: Wed, 5 May 2021 12:31:57 -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: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 65D23200099D X-Stat-Signature: 3w31h9yrrqgr6tnsjgdxmm1mz9dyurpj Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QmsVEi2S; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HtANYrOo; spf=none (imf18.hostedemail.com: domain of llong@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=llong@redhat.com; dmarc=pass (policy=none) header.from=redhat.com Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620232443-826360 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/5/21 12:17 PM, Shakeel Butt wrote: > 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". > Thanks for the suggestion. Will incorporate that. Cheers, Longman