Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp659891ioo; Thu, 26 May 2022 11:32:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ6SxNV28I/b9Yc4AxsZDSUkbrKVzyi7g6fTJ//2E/G19txREKzRs1o4xrW1+HIktRzC2j X-Received: by 2002:a17:907:72c1:b0:6ff:c5f:6b7d with SMTP id du1-20020a17090772c100b006ff0c5f6b7dmr10261578ejc.676.1653589974263; Thu, 26 May 2022 11:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653589974; cv=none; d=google.com; s=arc-20160816; b=hcTtafhWUJlvGu7pVRY8VRDodwlg1RDL8QXNt1iswbTHpekkcwiMVll9HT9vyQOFqV kwA2ywaVX2bKZBzIMoEwP24r9fQHbcn90BMYU8RTh2JYZpDcGGbXlXLpXszDmOsFGmZm h7T+dYjan5mGDLgwXqCO4diww0xMlwBR1Ftdlr/6u5ovYj20AnDwT7UFqJ30iuChVKmr /e3jklCev5NQnX8n7hY5vvOm+OSNEjOvNp1U/7jOJjMIrUVmP3DVdEZl58vyP4tsKYSg BrSLU3RpAt+OrnROtrJ7172UcIku52tTLzcSv9aK4YoXtqPd0sHYUMg0fjFCjhHc49GG elRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=Yo7FzjtiZvDRd+DFH4BFUlGj/8Afe054Q8uURtbD0/M=; b=FiBk/QhxkmzKLJgQlYkkfqJanZvETnHSplAD8lCt7zMEJBcOx+TKIFW1BPPjKdrqrV 70AdaQp/z2I2pfi/OvPJWutzEw5go3b4D+mIIRiCidneb772Ma3fb6yiC0iSCmrsy78X r4w8+lvYpnVJn9nUf8AJDhXgFKcVOHXucQEesCy32zZVCZ6MP8m7uzjc1EVpJAjhb0Zy nQ9Jn8hWki4Yrvf/1roXsCoZSaLUQQlMYBzPqw77dxoNhsMEAVy9wuiXJWpVbaRclRZo k40b7DASgV4SYeXml6OuJreHKETcM2mEgCOhw024ZftuAzn+rTpuqHnjbAJm5jQtFf2r 118w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=yU1ERtij; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=9UlVVBrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a1709063b4300b006e874b9da7fsi1960938ejf.28.2022.05.26.11.32.25; Thu, 26 May 2022 11:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=yU1ERtij; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=9UlVVBrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbiEYKJY (ORCPT + 99 others); Wed, 25 May 2022 06:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237600AbiEYKJX (ORCPT ); Wed, 25 May 2022 06:09:23 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AD8590CE1 for ; Wed, 25 May 2022 03:09:21 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BFD651F905; Wed, 25 May 2022 10:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1653473359; h=from:from:reply-to: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=Yo7FzjtiZvDRd+DFH4BFUlGj/8Afe054Q8uURtbD0/M=; b=yU1ERtijKkn5EuG/gZIGlqcfJroUdwuBP/DWW24Q8bFamTS94hSBnyf2otDMBLWttde2p1 sikqfxNe9h/t5OU0uA3UXUkY+/gfGLipuXHizn9i2MpapG92QawYl8T1ATFrUoe08Q74i1 g68K3irHsjIr4UEDL89hzQtFupVtWvE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1653473359; h=from:from:reply-to: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=Yo7FzjtiZvDRd+DFH4BFUlGj/8Afe054Q8uURtbD0/M=; b=9UlVVBrNvELvqaYdmefU30TxErcxGeb/i0zJI+CI5pqSa0GNnANIJE37ZMNNFFfAvWamqK lLPCFJ12a1J33lDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9DD3413487; Wed, 25 May 2022 10:09:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id q0z1JU8AjmJgZwAAMHmgww (envelope-from ); Wed, 25 May 2022 10:09:19 +0000 Message-ID: <970bbb88-3fc7-d2b9-6bb5-9c315888a889@suse.cz> Date: Wed, 25 May 2022 12:09:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v2] mm: slab: optimize memcg_slab_free_hook() Content-Language: en-US To: Muchun Song Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, smuchun@gmail.com References: <20220429123044.37885-1-songmuchun@bytedance.com> <86fdbde5-a010-9473-2f5d-807c86620509@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/25/22 11:15, Muchun Song wrote: > On Wed, May 25, 2022 at 09:34:58AM +0200, Vlastimil Babka wrote: >> On 5/25/22 04:18, Muchun Song wrote: >> > On Tue, May 24, 2022 at 07:05:31PM +0200, Vlastimil Babka wrote: >> >> On 4/29/22 14:30, Muchun Song wrote: >> >> > Most callers of memcg_slab_free_hook() already know the slab, which could >> >> > be passed to memcg_slab_free_hook() directly to reduce the overhead of an >> >> > another call of virt_to_slab(). For bulk freeing of objects, the call of >> >> > slab_objcgs() in the loop in memcg_slab_free_hook() is redundant as well. >> >> > Rework memcg_slab_free_hook() and build_detached_freelist() to reduce >> >> > those unnecessary overhead and make memcg_slab_free_hook() can handle bulk >> >> > freeing in slab_free(). >> >> > >> >> > Move the calling site of memcg_slab_free_hook() from do_slab_free() to >> >> > slab_free() for slub to make the code clearer since the logic is weird >> >> > (e.g. the caller need to judge whether it needs to call >> >> > memcg_slab_free_hook()). It is easy to make mistakes like missing calling >> >> > of memcg_slab_free_hook() like fixes of: >> >> > >> >> > commit d1b2cf6cb84a ("mm: memcg/slab: uncharge during kmem_cache_free_bulk()") >> >> > commit ae085d7f9365 ("mm: kfence: fix missing objcg housekeeping for SLAB") >> >> >> >> Hm is this commit also fixing such bug? in mm/slab.c __cache_free(): >> >> > > Sorry, I think I have misread it and misled you here. I mean commit My bad, I should have said "this patch" referring to yours, not "this commit" which could refer to ae085d7f9365. > ae085d7f9365 ("mm: kfence: fix missing objcg housekeeping for SLAB") > is a bug fix, this commit does not fix any issue since __cache_free() > will be called from qlink_free() and __cache_free() will call > memcg_slab_free_hook(), so there is no issues. This commit is totally > an improvements for memcg_slab_free_hook(). Ah, I see, indeed. The un-quarantining in kasan went through memcg_slab_free_hook() before your patch. But yeah it's better to do it earlier as the freed object's user is who charged it to the memcg, and is no longer using it - no reason to keep it accounted while in kasan's quarantine.