From patchwork Thu Aug 24 03:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363497 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 9A987C3DA6F for ; Thu, 24 Aug 2023 03:48:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA022800A7; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3634F8E0011; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DDAD2800A7; Wed, 23 Aug 2023 23:48:54 -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 082408E0011 for ; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D81D41A01B9 for ; Thu, 24 Aug 2023 03:48:53 +0000 (UTC) X-FDA: 81157616946.03.A104439 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 2093C40002 for ; Thu, 24 Aug 2023 03:48:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Etg773HE; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 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=1692848932; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=hZ/+CEKmqFbd2DXtWwURqouHRdD1V9N+sGNEKqHuqlaR9r5AmzLDrupnYctx+Ae/jxJJBY YxBjuFORQbfIQ3hJUlJrgzG4rxffdPA/pi3DE+MyHvVTJP/Waz8LADJn5ZWTlnmIO4g7X+ Y7uND1KORdc7h/f5qLquqw8t8WII2aI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848932; a=rsa-sha256; cv=none; b=MYkQqRILvrd412Sc73WmIZK+BUi48m/B4NWxh3c1Y8Gt9WsQH04Qu8MN5rN7yzkHzLetDT FJhvKNcU9T6hzkx8q6OvT69SWihh4TYvNbXF8sPQVTkj1ou87WhxY4FIC+1dRkwgbnjC+k tkC3VIQK+Z2oF6PPUjIvtOJv3oWW2ug= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Etg773HE; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3a8586813cfso655825b6e.0 for ; Wed, 23 Aug 2023 20:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848931; x=1693453731; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=Etg773HEMt6axbPONXeHGSLT51+RdI3dzQiJTfT96NZnFEl37bQIBM8X6mo0sOTo0d 2dGYINCvxlO7NPH+D5RGaTZqETV+0suNEBQUshlRf6R9Z7fNgoXcSjr6zlrjyT7NxVbA rVONX6e+68F+cT0c/emQ6lA8a/TGlO+N4/53pkI2oWnDkzLPDOuqpd7sfIPnNddNcjt9 0vbukc7S0vFSoAGkb3yE/u8zFtdBe/pJpAC0iBfkpaI3MovdpoMhtwtuHo4U7Pnsxdxf 1GF9PbB/mGtRR3mXcIqDFlbcTz7ePkujB41gg7lcY5R6hmxlcHo4GDvhQqafR3/hzexb XeyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848931; x=1693453731; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=bCRmzl1S44E+BUJGhm1m3Q4M+J976cy9VJb+s9fEbQd6E6Y98TkZjT5SSy9jL8ILoN bzrAxsHfnelzjCsB4y27KwgodKsz9nVDD+R+U8pC0ql9IUaDJH8o19YJdEMYD7E4A3kq FGHjFwAdTN1TR6FjSAse9PjKAIqrzZ1jiz15wL6dWLd785ZxoP02v8RW0r9PEniaRMit AAtbcpP2Gf6zEZzqOLvtFEx7P/GjEP6LIZAlsusCV1K9PEvSgD/nA8o8WEd2GXLbl4gU rxsD97R0/8nEaKkB+ke+/p3pFuEnZI8841gj60hgOOQaEI5ghcsHaUdSba73+b/jvAYU C7TQ== X-Gm-Message-State: AOJu0YzjUxWZTcpcBxxPZgZ8YSicfueNKVN+gU3aM+AJ//oamg0BcLSJ p75qLT3NiKyaZVh42zjgfR4eGQ== X-Google-Smtp-Source: AGHT+IHBqdQGZ5Cdz64aUWukdXrVsG9fgeXOAK36erFQqZ4a4LZTcz+AGem6g0p/atv+siUHR5rZkg== X-Received: by 2002:a05:6808:30a7:b0:3a7:2eb4:ce04 with SMTP id bl39-20020a05680830a700b003a72eb4ce04mr17483879oib.5.1692848931041; Wed, 23 Aug 2023 20:48:51 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:50 -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 34/45] xfs: dynamically allocate the xfs-buf shrinker Date: Thu, 24 Aug 2023 11:42:53 +0800 Message-Id: <20230824034304.37411-35-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: 2093C40002 X-Rspam-User: X-Stat-Signature: iinpht3cm1zcsg454jggyp4pfwy53gmf X-Rspamd-Server: rspam03 X-HE-Tag: 1692848931-79267 X-HE-Meta: U2FsdGVkX19oi/24NGMeKuDipaxgbxk8dTl+fF6Qy8YgR22mTPUOZcyjT2v4wtZbUOnPHvABUa8fRNXBAF/cAHYId8Pj93po7Sz0ivKIIGSyywNTgvU/AA+t4ZRU/c1m8aHjYtQZ+OYeThEldYQ70oQYlgupIwAxSa9NPiHns34IRuYYMlt+f5Lcntjau2J/lpi/v9ZAOm+FDeqgx71bC4ZOhPZ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1+i4L3cBKgH2n1ibxnzEsfE1mFw2HQx1fdY3/AbISZbtbG2DsLgBmMVkbLX/ah8WNXdmFVDIIxxcoqOc6Ee7GvIQAcw+HlX8kOlsozAnMRHuuVpR9iJ+Et5WVH0VfZExnUmzlbQehjG2oiOG5H27RP6zsq2VDvYFoiBcFTt+oOOjRentSnQ+8L+6g== 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-buf 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_buftarg. 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_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 c1ece4a08ff4..202d4432d587 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1913,8 +1913,7 @@ xfs_buftarg_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; LIST_HEAD(dispose); unsigned long freed; @@ -1936,8 +1935,7 @@ xfs_buftarg_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; return list_lru_shrink_count(&btp->bt_lru, sc); } @@ -1947,7 +1945,7 @@ xfs_free_buftarg( { struct block_device *bdev = btp->bt_bdev; - unregister_shrinker(&btp->bt_shrinker); + shrinker_free(btp->bt_shrinker); ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0); percpu_counter_destroy(&btp->bt_io_count); list_lru_destroy(&btp->bt_lru); @@ -2031,13 +2029,18 @@ xfs_alloc_buftarg( if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) goto error_lru; - btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; - btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; - btp->bt_shrinker.seeks = DEFAULT_SEEKS; - btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; - if (register_shrinker(&btp->bt_shrinker, "xfs-buf:%s", - mp->m_super->s_id)) + btp->bt_shrinker = 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 = xfs_buftarg_shrink_count; + btp->bt_shrinker->scan_objects = xfs_buftarg_shrink_scan; + btp->bt_shrinker->seeks = DEFAULT_SEEKS; + btp->bt_shrinker->private_data = btp; + + shrinker_register(btp->bt_shrinker); + return btp; error_pcpu: diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index df8f47953bb4..702e7d9ea2ac 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -108,7 +108,7 @@ typedef struct xfs_buftarg { size_t bt_logical_sectormask; /* LRU control structures */ - struct shrinker bt_shrinker; + struct shrinker *bt_shrinker; struct list_lru bt_lru; struct percpu_counter bt_io_count;