From patchwork Thu Aug 24 03:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363498 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 30098C71145 for ; Thu, 24 Aug 2023 03:49:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C40792800A8; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEF1A8E0011; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A68AE2800A8; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9377E8E0011 for ; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6FD161401B1 for ; Thu, 24 Aug 2023 03:49:02 +0000 (UTC) X-FDA: 81157617324.01.8C91596 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf19.hostedemail.com (Postfix) with ESMTP id B65FA1A0006 for ; Thu, 24 Aug 2023 03:49:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RUQ+uBY1; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848940; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=BLBfuVIlvqLTV1NpcSgdf1IZba0bCwIRib9gRQrC0dsr/ifstSWelllZBtPsj3mEkQD0ut VhUMFbmRV/IesX5DKbKYkk8KEPYS2d9lXfreccc9jM9z5wcIiNUSc+djXbwkBKoOsznScQ EvrXMHuaCPilc0srmPdxrSSCmUm96Ik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848940; a=rsa-sha256; cv=none; b=uC9IEgSHBMzOXsdmX+S8tO5mZQxDvEfcCInHuXZgeHKFoSvZvGC/uMcNURgtUMCcWWYWPu TpXUo7cYplYDJyEZPlRquR/ExE3x24z/ujSDy5DHosL8+kXMCNT7EX3p4v7Dtq3otmoUIZ BDzIOFhOQRwOqLLbGos3jDzl2s21/nU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RUQ+uBY1; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so756376b3a.0 for ; Wed, 23 Aug 2023 20:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848939; x=1693453739; 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=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=RUQ+uBY1HAkfCuT5ESlCEEytul9G5hnDaEVThHfRmA0LYTVOc7WWLKd9hCsS1rFFHa mc0eH/7dbqdo9EHUE6UmTighkCrSbumK03htQygf67qHe27shmRyY9JK85wG49kiZv2z 8oDCaIHdONUv8zGek6e3NspoTl+vC5Qq39AmSoZP1rBLnuHQgP5BJHtoJVHrZETVj2Kd egVF4zYA6OPsk/LsQqBBw1iTIY44FdHii7ecD8x2+R4p3ld0ut8Qk1kr8FgQOf8sZhM2 fnGgLEb2c03dR+jZvgTtYnp33H09H+otZtQe2aqa0mDWv5FhBJgI53BmsuMQs8rFkhal gCGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848940; x=1693453740; 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=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=gW/T7fk3yQUOwO1HXJK4GSuCScTmEVBCzBHrqb8R07D5M+LxXgUB3TMhqK1S3VzfRA LC7XAESUnZkXSoEha+FZkEx4WTUrh5QtOEx2ZztNTacKA6O+2QVCf7jUO3NeYpJM1EZl 1WeEFLz/pPK+bno+YK/2onyR6NDiTlkyYWJGtbLXxzrWW+v5nIGChI84uR0u+++I14mY uQWQNjxY1Peg92W/GOgrLReDVm/IR2+PUAg/EmtbS5iN9NO35Yu9SPa1kAWAxJvA+BR9 /cmOFpbvtSemIQ1AwNIkr/9YoIMb/ejeLk5sbd2oQy3j5p3q2arDl3UeMuXAP0f08ncg rcLA== X-Gm-Message-State: AOJu0YzsvEsoojL2wxjMKncSbFzO/RQDYgpmFtFuiOQxtpYrJY2tIfXr KzMWuygYLnXEYYgaKoVoAKndWA== X-Google-Smtp-Source: AGHT+IFx2iJ97bW+6mvf322k3W+3GQwieeJP9La15RA3gyZWBJ7q6L8OZOACecxW0xeTb1cw72OuKQ== X-Received: by 2002:a05:6a00:418f:b0:68b:c562:da46 with SMTP id ca15-20020a056a00418f00b0068bc562da46mr3997585pfb.1.1692848939719; Wed, 23 Aug 2023 20:48:59 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:59 -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, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v5 35/45] xfs: dynamically allocate the xfs-inodegc shrinker Date: Thu, 24 Aug 2023 11:42:54 +0800 Message-Id: <20230824034304.37411-36-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B65FA1A0006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pbam7ky8773x78f5c8j9pkusrazskqgw X-HE-Tag: 1692848940-112610 X-HE-Meta: U2FsdGVkX19I+poe8yVNEeeZtmRts/iwgC/jRqFJh6sU63oPVjdW7L+BFl83fJJjjp8FO414hAS9a/D0IF7bnXbLn4crU2hOnHtrXbHLKD100IMwFTqYKg7kmx+/j1Rr9Y4cGjQK3gMClE83bqFgUT9iLimzdgpowUyLWCJaXxtl6UfJItqoJDimJcV1A7WsbJZwrqrmmSqc+r4oAMH+TxM0u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ozHPhggEcqMB6Q3V/+9LnV1j3IbynFTkYEePHlHIybZQAn15wh/eQ5N1dBV7AJUfel5hhKvK+Losy1F/N8M6t1eSrBqZr/TiPPk0+ACJ8z6pgLmIAqR2i+WOFKiUoCAC/j4eoUVUyShInhAwCj5nTww5MqDOgLN3DuDuX9aLVbCp2Ipma7xyS1N0OQC5iHhXBLTGm3Ufbn9flqBcYKQeg== 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: In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the xfs-inodegc shrinker, so that it can be freed asynchronously via RCU. Then it doesn't need to wait for RCU read-side critical section when releasing the struct xfs_mount. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chandan Babu R CC: "Darrick J. Wong" CC: linux-xfs@vger.kernel.org --- fs/xfs/xfs_icache.c | 26 +++++++++++++++----------- fs/xfs/xfs_mount.c | 4 ++-- fs/xfs/xfs_mount.h | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index e541f5c0bc25..aacc7eec2497 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -2187,8 +2187,7 @@ xfs_inodegc_shrinker_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; @@ -2209,8 +2208,7 @@ xfs_inodegc_shrinker_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; bool no_items = true; @@ -2246,13 +2244,19 @@ int xfs_inodegc_register_shrinker( struct xfs_mount *mp) { - struct shrinker *shrink = &mp->m_inodegc_shrinker; + mp->m_inodegc_shrinker = shrinker_alloc(SHRINKER_NONSLAB, + "xfs-inodegc:%s", + mp->m_super->s_id); + if (!mp->m_inodegc_shrinker) + return -ENOMEM; + + mp->m_inodegc_shrinker->count_objects = xfs_inodegc_shrinker_count; + mp->m_inodegc_shrinker->scan_objects = xfs_inodegc_shrinker_scan; + mp->m_inodegc_shrinker->seeks = 0; + mp->m_inodegc_shrinker->batch = XFS_INODEGC_SHRINKER_BATCH; + mp->m_inodegc_shrinker->private_data = mp; - shrink->count_objects = xfs_inodegc_shrinker_count; - shrink->scan_objects = xfs_inodegc_shrinker_scan; - shrink->seeks = 0; - shrink->flags = SHRINKER_NONSLAB; - shrink->batch = XFS_INODEGC_SHRINKER_BATCH; + shrinker_register(mp->m_inodegc_shrinker); - return register_shrinker(shrink, "xfs-inodegc:%s", mp->m_super->s_id); + return 0; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 0a0fd19573d8..aed5be5508fe 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1021,7 +1021,7 @@ xfs_mountfs( out_log_dealloc: xfs_log_mount_cancel(mp); out_inodegc_shrinker: - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); out_fail_wait: if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) xfs_buftarg_drain(mp->m_logdev_targp); @@ -1104,7 +1104,7 @@ xfs_unmountfs( #if defined(DEBUG) xfs_errortag_clearall(mp); #endif - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); xfs_free_perag(mp); xfs_errortag_del(mp); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index a25eece3be2b..b8796bfc9ba4 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -221,7 +221,7 @@ typedef struct xfs_mount { atomic_t m_agirotor; /* last ag dir inode alloced */ /* Memory shrinker to throttle and reprioritize inodegc */ - struct shrinker m_inodegc_shrinker; + struct shrinker *m_inodegc_shrinker; /* * Workqueue item so that we can coalesce multiple inode flush attempts * into a single flush.