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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8692AC433EF for ; Thu, 9 Jun 2022 06:34:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2A5D6B0073; Thu, 9 Jun 2022 02:34:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B2EC6B0074; Thu, 9 Jun 2022 02:34:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 854486B0075; Thu, 9 Jun 2022 02:34:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6FB8C6B0073 for ; Thu, 9 Jun 2022 02:34:31 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 424DD330BE for ; Thu, 9 Jun 2022 06:34:31 +0000 (UTC) X-FDA: 79557733542.13.20F880A Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf17.hostedemail.com (Postfix) with ESMTP id 28D2E4004D for ; Thu, 9 Jun 2022 06:34:29 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id f8so466631plo.9 for ; Wed, 08 Jun 2022 23:34:29 -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=6j98NSoKnUr9VnwQS2PEzCXDhqhV9EXqhkIDqAKCugY=; b=FIHP8e4looCFOxHpTEaOYxAwDT9jQDecl2TPThxKGZfkp5wuldi/YzCt9hjYONbF1Q dC/ttLvcJqiAlMYmaJWMFKrwU+YLAvTbL4Iw/0c7p21w2/hT1vTfP8rclmGQ2kMTdNpj 8/nkmty3vfxS1A1MxmWbd6ZvJjBC9yLePbi6vzs6ILJSHNpBESBXGzrokNkDrRUFbTdP gkpBc1RE5I+7B2Xk8creW4U0N2Jgh9FkctcUiNpkmY9Yxz/vQ5a5IEFYIHcflonzfMxS GUYtJD1uNxpSuHYlgedXXnjYrm2KbRa/adn9aeyebPZdwXVufK1b90Af5uIsD2vTewvQ a6IA== 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=6j98NSoKnUr9VnwQS2PEzCXDhqhV9EXqhkIDqAKCugY=; b=2IS+moPVO9oFN6lsJfw3qoGMAIU2BqwTl8AJUZgRjZB35UlVbNrVZsGQNWqJdSMfBI e1DbNbDa61G5LQQ6iQEnqMfFfqJyQJC60NyA2AoLFOMLhYDWL6Lm41GvsCXFjBU1HrNy S+KtTaGWPlOxvFqG8cz/04zRI4S+BX+j8TcQApdca0RDotTgWk6EwcBCzkKZ1WE8uIiY 3E22VATuLVOL6d91iC2vF1/cPY6OQKHD5VlVhpe5wyfaA/liAvPCzsk0ak5jcjXEp2XM Cd5D1PZMEybOmSJfkGU/kOtGok1/8LFmRBNHixRt9JyAh7aLg1ttgdXqfP/cDwX9KSNf BGxw== X-Gm-Message-State: AOAM533IEv+xtWJruAewq26jZpaIldY4kDWQ1lVLeq1GUgd+YmbHJPxz UEPW28UtGq//jcobKZI8bf2ZWg== X-Google-Smtp-Source: ABdhPJzr1mZzXcfCMQrT0ISITKrFNsB2jvroULWWEPJkOrwyOfKOn7ksOdfXBq5UD59hmzwFDap5PQ== X-Received: by 2002:a17:902:f353:b0:167:7bc1:b1b9 with SMTP id q19-20020a170902f35300b001677bc1b1b9mr19710778ple.117.1654756468878; Wed, 08 Jun 2022 23:34:28 -0700 (PDT) Received: from localhost ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id 187-20020a6204c4000000b0051bc721b838sm14553742pfe.188.2022.06.08.23.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 23:34:28 -0700 (PDT) Date: Thu, 9 Jun 2022 14:34:23 +0800 From: Muchun Song To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev Cc: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220429123044.37885-1-songmuchun@bytedance.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654756471; a=rsa-sha256; cv=none; b=D89MNk1rfvWrD6fkIxkHQPzgzW7PLIO5VQVqa6VBaYlcGhQU5YepYYeuAMMy76VVtSC3O9 CzLcBYYzZ1IenuJDpCLV+XWMBTzsuZlxWt1mK+izDLgsubxHXMb6dVs5QbDdP+X8HbIklK E/ime7IbW67cn2ubgyMWHKSYmSFYzY8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=FIHP8e4l; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654756471; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6j98NSoKnUr9VnwQS2PEzCXDhqhV9EXqhkIDqAKCugY=; b=TAvmprWa0Nsvw+M2wKdd3xL3jYvrGnchr14hmFnqrIrCU7MxfrYE98+4xNsplRR1J0GW2F KTllrs4IfdtKON9eSraTD3sKwvQDahpQffNICnR/AdrmQ3Vx80Adak1QpVsqgwmd0FK17N yu8EgzZi49s7oah5FjBOEyidGa8VMtE= X-Stat-Signature: p59we58su3pb7jee19rzumqekh511fs1 X-Rspam-User: X-Rspamd-Queue-Id: 28D2E4004D X-Rspamd-Server: rspam07 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=FIHP8e4l; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1654756469-729858 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 Fri, Apr 29, 2022 at 08:30:44PM +0800, 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") > > This optimization is mainly for bulk objects freeing. The following numbers > is shown for 16-object freeing. > > before after > kmem_cache_free_bulk: ~430 ns ~400 ns > > The overhead is reduced by about 7% for 16-object freeing. > > Signed-off-by: Muchun Song Hi Vlastimil, Wolud you mind picking it up? I did not see this patch on the slab tree. Thanks.