Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4173071ioo; Wed, 25 May 2022 17:19:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkmdyEtxRD0lva3+taoV2VtEzqEoDmpdNzmNraiZoQy3cDaXH62ETq9fQiVFY3WDcZrK0T X-Received: by 2002:a17:907:2da6:b0:6fe:b40a:c817 with SMTP id gt38-20020a1709072da600b006feb40ac817mr24908187ejc.365.1653524361523; Wed, 25 May 2022 17:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653524361; cv=none; d=google.com; s=arc-20160816; b=aQZhIpaHZJIe2WrVxmdSlGL6JKlOCZbGpK5R/POrpmEqWxO5oM4x5klvq+YXWcLZ+h rhkyJs5hFLOxRPf6u1t1LQKZalFfHJYsnwFBe3eOp8JyB4aItX69/a0eZ6LZdpfmW2Pi SlPFzt8gHimOzf+U5KZBqbI3UMge6y0BuCRxANqVTXJZwHro7cVSZO6c9XJmLgK5ftYY 8CXRjuhO9gvQBfRyo9TzEakT0s7sC5XTccKHfEqDxMnkRrv2gQiTMtUiiUndqLJma2eh HgrnuRr37b53ON7LhOyszMMPa2B8jOCz2Amv7SzmTcwgSNoj4YKHHIoVn9aK0b/2hnwY uedA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mwbhkmbOQkKuVwJYKsie0YEoqqvQobqGsqV+qfDL6OU=; b=IuFjDb2cewnJLLgWrXUWjmNLQVf8TEzyHEYwv2wFNJ5vl8OMq1scJ71K2oioIYvR8i Qf4PpfbTWjrKrTRdzLACABC/+z2UuEa0/9nI+3GspLNSiysrgY42u8p9Gs1NRo/BtPs5 YGajaISl1K1cpdWKj5B+Xsqrj8MGqebwD1HPps+Knl/1z/O7/Qg8gC+XH4nCndoX0/Qa P3HIKhnW4qFtn1H0owdk+VnD/m8NNLINoNlem/2ItPrrVYZEEH1uvzYG4oQFfRQjr+Id HvJoGSWVyR8pkWNURsKTAgQx3JIxWo3VfYjj24+Y0f/7mniULRc9JFx2ymTFqn4iS1Uc yFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=xtA2d4yq; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht12-20020a170907608c00b006fef7d43e6esi101002ejc.466.2022.05.25.17.18.55; Wed, 25 May 2022 17:19:21 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=xtA2d4yq; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235998AbiEYK3W (ORCPT + 99 others); Wed, 25 May 2022 06:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbiEYK3V (ORCPT ); Wed, 25 May 2022 06:29:21 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45689939B7 for ; Wed, 25 May 2022 03:29:20 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 137so18573713pgb.5 for ; Wed, 25 May 2022 03:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mwbhkmbOQkKuVwJYKsie0YEoqqvQobqGsqV+qfDL6OU=; b=xtA2d4yqOYjJy4H8+xdeaKzfApG+eB/GsavG4nkDp3U04W8EMcQnDrqiTkYeSzj5kE yjW6uCwlJzS4bdpY5KlPyLhELrgvv8+CtOLKvKZEpkq2ij65waqIHUxAkU8O/ejp52mv DKm08hB9XEbWRgaMKTYGPjAhcdfH9jn7cOhxKftwveb0FZrSqq/iQg23GR+B+EEaBqR1 n0RkQvAVqTqarplotOMN8KnAc73zD4/kNAjNQjuSd4vveAhcVlAerGU7oG6ZExe7Xed7 Mi2nHpKYc1rdfX7+Uq52KAXev/lwam+HlrqcndWodP1NqvU8GCNsuDQzI5Ai+MOJF2Fz Oc7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mwbhkmbOQkKuVwJYKsie0YEoqqvQobqGsqV+qfDL6OU=; b=N5pMFcqZxkMUcTcnWCTVu+pBE5dPO416yX9OOPgtKucWhyT8by/N3Oh6SQeFe9V+zn 9xHOKCQAAt82Xej/+zP5udZ1rpqgf1q89yFVPQX+9z752IkF0uaYAqf/rcZ2h7jW7kXi BNbk1l9siyqYvJbv1ngfkk4QoL3J2U6dPpXbMdw3UfmD++9ZdlZCR+J39MdwWE8DMASa B89X7b8Ukh1m7d1C64mNiGlx41oZLra4B2vzXeThWFtCqEKzua+15J71mpZ3pZOA6B+I sVog/HE+bBCKimlmcZZIcSaA3kPVIaFqbLHf/twER5kKSI58OxBfYvt9d3VxADD6DHMy IjYQ== X-Gm-Message-State: AOAM5306Y32ZJBD4Fsr8jIZg9fz+sXDbxEhjUT5IwmLv3eMgI1GllR5T Flf72dn/ZK+REaBuddmw46Ymrw== X-Received: by 2002:a63:5211:0:b0:3db:1c36:fc37 with SMTP id g17-20020a635211000000b003db1c36fc37mr27205801pgb.572.1653474559765; Wed, 25 May 2022 03:29:19 -0700 (PDT) Received: from localhost ([2408:8207:18da:2310:c40f:7b5:4fa8:df3f]) by smtp.gmail.com with ESMTPSA id g3-20020a170902d5c300b0015e8d4eb2b9sm8946714plh.259.2022.05.25.03.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 03:29:19 -0700 (PDT) Date: Wed, 25 May 2022 18:29:14 +0800 From: Muchun Song To: Vlastimil Babka 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 Subject: Re: [PATCH v2] mm: slab: optimize memcg_slab_free_hook() Message-ID: References: <20220429123044.37885-1-songmuchun@bytedance.com> <86fdbde5-a010-9473-2f5d-807c86620509@suse.cz> <970bbb88-3fc7-d2b9-6bb5-9c315888a889@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <970bbb88-3fc7-d2b9-6bb5-9c315888a889@suse.cz> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 Wed, May 25, 2022 at 12:09:19PM +0200, Vlastimil Babka wrote: > 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. > I couldn't agree more. Thanks.