From patchwork Mon Sep 11 09:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379110 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 2F36AEE57DF for ; Mon, 11 Sep 2023 09:50:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C47D56B0252; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8856B0253; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABFE76B0254; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9C7136B0252 for ; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6BC00140915 for ; Mon, 11 Sep 2023 09:50:23 +0000 (UTC) X-FDA: 81223846326.14.2A57048 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf05.hostedemail.com (Postfix) with ESMTP id 9D75C10000E for ; Mon, 11 Sep 2023 09:50:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BDA57x2O; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425821; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=yHeskCihNVbVdLtY6w7x00eKv1zqLoTQqay4WzKuvalSYHLq+ZeKxbmzd6+nKNL7ni7r8g 3g56ouIcKw0zkOn7F2LU5zD+IaJ62QXE3EmQtsLvWEzlYylEOm5GJspdl1l2FiO+ALm9un TPsfD7CEiql6513t7su8UfVujqU3n3Q= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BDA57x2O; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425821; a=rsa-sha256; cv=none; b=ytoI1/+65ZdTiDqFmt9lqpuVcsMMIjuGcmh2CR8DU2ZMcgoZq1WjLHc0ag/3vzVKOHJ0ta kxzXllq88RsHR+cqyF7/Zj1dc4n36e/Zi4ARywn0Hfbfd/XwB3DrWKhYROG7ly3R/emhUw vuZKcXz2/XM+Sdd7ulDpTEXhMLl7Ihw= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c39500767aso6236915ad.0 for ; Mon, 11 Sep 2023 02:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425820; x=1695030620; darn=kvack.org; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=BDA57x2OWmE7J1N6Z/CuLaYHgt3Vo9U+K5Ns+fpzRSRtpXqIdVEtuioE07SybT6T4T 2Wxfnpa2CG4sGEqCmvfQ+1RwXV2IkZ1+yAdGpXi1KCCA1QljgLtQHLNhT0EdqH/iCJ2g mbynfruRJA5qvtJ85aNk4vr1OmUTm52bRe4wx+1PBcjiLTvL991ql7NjRgDJ+ontna4Q 6JJnEg2TfRZbEKSpqIpteFsLMBlx0H5vwDqQUFvoPfbgv0nHgTCW9CIw4z/XewD3LM9D h2c0n6f5feY/GDmOSaVrl0prTVWhurmIK5kgZedKZ9wiuZ2E+IrGfBBdgCcmK5kXvYG8 FHBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425820; x=1695030620; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=oR4+6pz922oitLXZrN6zBOLMQ5Tpw5AanqEUkszokDe0FqK8fem/eGwbc+1j2YDpbQ EHHZFVjHc0NnOmuwjCKBoa1vPtmo6f+yKy6esC1usXTSg6cRI2r/Qx3wRPpLlIeALXCn r1KqfYJi2Etjnhb9IjJEV0pRtVbVsjvxsGZrVCqeLiwG+MrSDUAP/UqLDUUV3O9ISBPw St4rL5l9WTthFU24aBaAXoGy5B6fCfQehIn9+fTBmS+/TjnHVq2qXV1JkOCq9MfhIRgC vAfGtNYVG6qE3vJIMEQKtahhR9R2qh6ZAJ3VtvD9IbFu2LEY3TyH3PgERS/CfaPcsB5l iRSg== X-Gm-Message-State: AOJu0YwU1gQnYGkEGQaCsDCwdzZtnu1IXp+8ncQBsRZW8BXYuGzn4Yvq 7OqWfUfSDKj76SALz2sgxnLahg== X-Google-Smtp-Source: AGHT+IEvj565qWnkofccC8hLFXJuQMn8WbyJUnUdIWHGtU6d/4Mn9yJ5j8IFsYM+kWtEVXfSyuocaw== X-Received: by 2002:a17:902:e5c7:b0:1c1:fc5c:b34a with SMTP id u7-20020a170902e5c700b001c1fc5cb34amr10661836plf.3.1694425820591; Mon, 11 Sep 2023 02:50:20 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:20 -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 v6 34/45] xfs: dynamically allocate the xfs-buf shrinker Date: Mon, 11 Sep 2023 17:44:33 +0800 Message-Id: <20230911094444.68966-35-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9D75C10000E X-Rspam-User: X-Stat-Signature: og8kba3sqpgj6x1mut6ahqf7gf6bb9jj X-Rspamd-Server: rspam01 X-HE-Tag: 1694425821-423244 X-HE-Meta: U2FsdGVkX19uESgkNBkB016dep0acuBPwacWVTNakiJBwrI27h3sFJCWcMqS3nZONLUNRs4ZCBBMDNbkZYuofdZg1JLdbA923NlIx/UR13c45IVXVOT8C0QF29voMztJfWlc3NxDohZiTEHrBmPirDnk4bcb7CgwcutaAxVlC9jl7dEIXLT42ZcwlhBFrdyiRj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2jLUo82HUeJLmouJ2QQtcTmaEA0aIYJtPnRnLE+50Qa+6wI+dI1U+XIYRvf71N5kOpIZXETGtERIbjalSCLX+LCzfA62upSDywaZIbAR6pB5UofyGTw7ek3mHaNwXnWW3ExCgoxQ9aDoKpEj9lk9nf+h4dxLXOOWrIm6KBZZEu24qzvDnMEkCdhbMdAt3CTCHrY7Ah9iLhoZmOabKanBOJ0indYrwQ== 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 | 24 +++++++++++++----------- fs/xfs/xfs_buf.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index c1ece4a08ff4..9e7ba04572db 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,17 @@ 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->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;