From nobody Wed Nov 27 22:36:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445651; cv=none; d=zohomail.com; s=zohoarc; b=cDXK3TiL/zETUYfHzkTbJwbjZvB61QxBaG7JuT34ddrrSqJXyy2t90wdovFF3BYxrEqwY2QrhxYVugvWeIekKPHwEVoueYWyd1liRRb4lbxfjj8jhKY9CJRc45Y7qH66n/g/NhQFVUJVE0ay/5VODSObq86fCLJ7uAr0LQGYy1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445651; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=DIXQGi4855Y880k7y0C84Mz5fh0wCDLpk5sW9R790mULXFSlOr+9kUeEGzUCp20/mt0IpITM4D4Z4jQBehED1Q/zUhSdJlKQ7pRSQNSKOVosGdhUgEN/foXMHFfKIfUD8H3FtS1FSbS8t9Y4oxNxZLe0ldR01I8hPT3dbE99Ly8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445651600190.28261230861926; Thu, 27 Jul 2023 01:14:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570866.893239 (Exim 4.92) (envelope-from ) id 1qOw7t-00033b-Ca; Thu, 27 Jul 2023 08:13:37 +0000 Received: by outflank-mailman (output) from mailman id 570866.893239; Thu, 27 Jul 2023 08:13:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw7t-00033U-9q; Thu, 27 Jul 2023 08:13:37 +0000 Received: by outflank-mailman (input) for mailman id 570866; Thu, 27 Jul 2023 08:13:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw7s-00033O-PD for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:13:36 +0000 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [2607:f8b0:4864:20::42d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7ac84365-2c55-11ee-8613-37d641c3527e; Thu, 27 Jul 2023 10:13:34 +0200 (CEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168716b3a.0 for ; Thu, 27 Jul 2023 01:13:34 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13:32 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7ac84365-2c55-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445613; x=1691050413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=AiXoaCJQdjYD9eYmeEdrfJ7ezATe9Yx6/bwBgW+5G+EPOMCuXYwEAcwi/JFENHTjN3 RLofwFvJd4EkqfH7Ye6KmIjKXgnfjEMN6IQZZPzERz8d2kaa1LDxbOfy1pXfbOXi//fW yPmgpOzP5ISM/DRd0jetvScx//7ssTCBUe2enciakCKenXGhXZrdb9q6vjgbH3ZMQFpH R1cJwZwEOETjjGMipjwgI0l9uWlKWu8vb1MB9swWpnARqP7hyemEh7msGfN9mYd5xYpI D03dkm0FvaoEJlj9bRrg4eXRdtCSaQUY5I5xaJER5wRv+adUsRWUp3ZNy7xFaIahEhPe Q+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445613; x=1691050413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=kISB6xE+hUyre96vvQxRogHnUM1YiwZDygU1kt3sY7WJNRsoOExBS9gBnybWR3l4+T sdGCu6OfkW3DssHhVbBUl8D9wUvGJCfK8YllwNyxL6j3H1SoGUvuoJHJx3OZZY+3Dk1Z QlGk1Q4w5zx/68lMnhRFLx0AdVyK5L1PNPqjP0d5nkJhQMAADNp/A4qPxe75Bnhlcqta oyEC/ebaHuhq15Ii0emc/iAv/3XyDJquY9qA4tXLB0wNFoDsnI/WlvAUqvlJpNy9pFhs IkoibrJgRSmHRvUB9R3se15UZrTBfpMlRNZ6J2g+BSDLksUgB8VVYiPla/E9NI8w3XP8 Ky8Q== X-Gm-Message-State: ABy/qLbAvqNPAbDV+XY4zdI0Hqm+yCf4HxANLzQqotKEs/DnXQ3Nulng sUDY21awajSR7cWEiyhlzGJmLw== X-Google-Smtp-Source: APBJJlG+tRTw+eNG8sDYXmQBYWrWDa50m7E6kRjtDYwVrWUQOS5ovTAWRl9t0zD5rxSD0dIJ86GpuQ== X-Received: by 2002:a05:6a00:2d82:b0:675:8627:a291 with SMTP id fb2-20020a056a002d8200b006758627a291mr4587660pfb.3.1690445613284; Thu, 27 Jul 2023 01:13:33 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng , Muchun Song Subject: [PATCH v3 38/49] xfs: dynamically allocate the xfs-buf shrinker Date: Thu, 27 Jul 2023 16:04:51 +0800 Message-Id: <20230727080502.77895-39-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445653007100001 Content-Type: text/plain; charset="utf-8" In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the xfs-buf shrinker, so that it can be freed asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU read-side critical section when releasing the struct xfs_buftarg. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/xfs/xfs_buf.c | 25 ++++++++++++++----------- fs/xfs/xfs_buf.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 15d1e5a7c2d3..715730fc91cb 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1906,8 +1906,7 @@ xfs_buftarg_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp =3D container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp =3D shrink->private_data; LIST_HEAD(dispose); unsigned long freed; =20 @@ -1929,8 +1928,7 @@ xfs_buftarg_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp =3D container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp =3D shrink->private_data; return list_lru_shrink_count(&btp->bt_lru, sc); } =20 @@ -1938,7 +1936,7 @@ void xfs_free_buftarg( struct xfs_buftarg *btp) { - unregister_shrinker(&btp->bt_shrinker); + shrinker_free(btp->bt_shrinker); ASSERT(percpu_counter_sum(&btp->bt_io_count) =3D=3D 0); percpu_counter_destroy(&btp->bt_io_count); list_lru_destroy(&btp->bt_lru); @@ -2021,13 +2019,18 @@ xfs_alloc_buftarg( if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) goto error_lru; =20 - btp->bt_shrinker.count_objects =3D xfs_buftarg_shrink_count; - btp->bt_shrinker.scan_objects =3D xfs_buftarg_shrink_scan; - btp->bt_shrinker.seeks =3D DEFAULT_SEEKS; - btp->bt_shrinker.flags =3D SHRINKER_NUMA_AWARE; - if (register_shrinker(&btp->bt_shrinker, "xfs-buf:%s", - mp->m_super->s_id)) + btp->bt_shrinker =3D shrinker_alloc(SHRINKER_NUMA_AWARE, "xfs-buf:%s", + mp->m_super->s_id); + if (!btp->bt_shrinker) goto error_pcpu; + + btp->bt_shrinker->count_objects =3D xfs_buftarg_shrink_count; + btp->bt_shrinker->scan_objects =3D xfs_buftarg_shrink_scan; + btp->bt_shrinker->seeks =3D DEFAULT_SEEKS; + btp->bt_shrinker->private_data =3D btp; + + shrinker_register(btp->bt_shrinker); + return btp; =20 error_pcpu: diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 549c60942208..4e6969a675f7 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -102,7 +102,7 @@ typedef struct xfs_buftarg { size_t bt_logical_sectormask; =20 /* LRU control structures */ - struct shrinker bt_shrinker; + struct shrinker *bt_shrinker; struct list_lru bt_lru; =20 struct percpu_counter bt_io_count; --=20 2.30.2