From patchwork Mon Sep 11 09:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379105 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 1E10CEE7FF4 for ; Mon, 11 Sep 2023 09:49:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83DE6B0248; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B342B6B0249; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FC3E6B024A; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9067F6B0248 for ; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 67189B3993 for ; Mon, 11 Sep 2023 09:49:38 +0000 (UTC) X-FDA: 81223844436.13.BD10B47 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf23.hostedemail.com (Postfix) with ESMTP id A7616140022 for ; Mon, 11 Sep 2023 09:49:35 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=J6QrfXv0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425775; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=s3WdlEz9A8r2eLqIECtLyv3xafm5iK0E/pdvpC0WQ+8ejMQjrwjESy8TFJ0Tufi+sTpJt7 nnELEbgCP05sIb5+i6sXKCyNl88C0cJT30qcvIbYpD/K/rqCKdx6RQfHw4xLLCfPx0MOyH M/3Nx99GfyiZA7WbrhnidEq/BwmOT18= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=J6QrfXv0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425775; a=rsa-sha256; cv=none; b=bSIp84BFdDt0zzKI9DmFsOXCywMfwuhgC0JJZLkVC622sNkof2TzVJTA2ZhsRRRvF08qeL oEvJOgKinzCLYugMRF1FvPrtU3ZpkaYYmJJhhgWWHDSvu4MhImJpVWdkYTrNmkbVv/U15g t73oZ4pHK6B/e8KSTzIIzb/eF/tmDIg= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso7703515ad.1 for ; Mon, 11 Sep 2023 02:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425774; x=1695030574; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=J6QrfXv0j8aBrICn8leuggz+7hg0w/wifEzmIFRI9nUBFWjix6XaycAU0An7ETRLsX K5hGAXz9cUS7JuUwRv/Ua/S8K94ElsZB3nmqLxDbVudQ+ei/YVY2PMal0tdGNNtoKSdR RkB6ZeIb57RHzDndz2MzLpunPtwkcGUDZflw1AFWHnWFLGQl2+iwjiZiw5FlZWMxDKNo MFiMNNGcUxRCJaYeqqXEZCZdua/4NP8L8/INBVuAP7F/VWizirBSsWQXsVoWer8GxjNh UxMuraLcQKRdlFvJMsSkQSnKasN0J/VGtk0xqFARoWM8M8MJu8uXy37Wvr4AKb6mA7Ds DXfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425774; x=1695030574; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=JuuCp2Ylvp4fUL2Dmuf/ev8UI2OgrpE969L49P39nPh51PhnbfCbcnUxTuC/Lw2g3b WQjzabgS/1ziCxIzq7LCabSqQWr3izNxyw30esI9vBSbOoJAW2pEASzunNqHt99cZw3N Hbbqow0E1QYmuz509OM0wf25kvgaunKuf8cj2EZ9xEbg4a8kC5S4AloK3Yi9yfvuoUgv EinDWBNUCCqZbOzjnHGTTYrDVzy3+9s0SSLQygeG3d30V8ybjW56NmqRIBexy2FkYOaI /I00xeXeQl+rcDpISKux6iOZghhwHF3n9DsQbn8jg7wjndf99jRKAL3nqOB6r+BeohWu kfkg== X-Gm-Message-State: AOJu0YzYEGvdHWqeJcDWP3Ov+gNBei8qhSct328HWTBCa6U0A18uJkHf oxmLnuRn5XKqjjwHnaYH2/01ug== X-Google-Smtp-Source: AGHT+IGPH5rXG2DhyxB6chvRHKVjx+5Bo9SHNmAMgS3dYgtQNb6hmClqPMLOMBQwFJcONSVD+tzP0w== X-Received: by 2002:a17:903:2448:b0:1c1:ee23:bb75 with SMTP id l8-20020a170903244800b001c1ee23bb75mr10949821pls.1.1694425774641; Mon, 11 Sep 2023 02:49:34 -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.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:34 -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 , Alexander Viro Subject: [PATCH v6 29/45] mbcache: dynamically allocate the mbcache shrinker Date: Mon, 11 Sep 2023 17:44:28 +0800 Message-Id: <20230911094444.68966-30-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A7616140022 X-Stat-Signature: rrn3siac1i6p9d14csza9hsx7x5cd5x1 X-HE-Tag: 1694425775-329227 X-HE-Meta: U2FsdGVkX19awBfYW9V5nxUlBoRfgVnUdry2zdvarWoK8MlXjzVLgAirwiQLAr+5UWXPjDu72n3JfVnBIG8YyJk4ueryExggWHt/Oe1fv7rFsDacMSVt+p8m0f8kxeBHtBcmZUlE9Ldpd0XhvzDhdVP/0lTjkFAflwyNpblzO9F1xbhP4LkxNFDDeguYgOXzOfQ1hgWqCZLNsK6KgRuoXpq3kZEFLY35u318dee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aY11XVdtHHpGPhowbybsWq+oNi1kwvZUeuO/cY1DQ2m0zcATR+WZ4ouGo67VrHyuxQ7NfvH3sag1598IlROG8MLiwZ4vuOtWH4p+01oAEQoY/RwwmGWiduF/hJTtAjFbF1jmMg1nKwZvH6ymQHlMCnAEXL/LQ1h2F2sr7r4mNW4laYqmddS7XeX452xj5htbCfW+TYtIdD1dXAePbxFSOT75fYS1CBLg== 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 mbcache 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 mb_cache. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alexander Viro CC: Christian Brauner --- fs/mbcache.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..82aa7a35db26 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -37,7 +37,7 @@ struct mb_cache { struct list_head c_list; /* Number of entries in cache */ unsigned long c_entry_count; - struct shrinker c_shrink; + struct shrinker *c_shrink; /* Work for shrinking when the cache has too many entries */ struct work_struct c_shrink_work; }; @@ -293,8 +293,7 @@ EXPORT_SYMBOL(mb_cache_entry_touch); static unsigned long mb_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return cache->c_entry_count; } @@ -333,8 +332,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, static unsigned long mb_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return mb_cache_shrink(cache, sc->nr_to_scan); } @@ -377,15 +375,19 @@ struct mb_cache *mb_cache_create(int bucket_bits) for (i = 0; i < bucket_count; i++) INIT_HLIST_BL_HEAD(&cache->c_hash[i]); - cache->c_shrink.count_objects = mb_cache_count; - cache->c_shrink.scan_objects = mb_cache_scan; - cache->c_shrink.seeks = DEFAULT_SEEKS; - if (register_shrinker(&cache->c_shrink, "mbcache-shrinker")) { + cache->c_shrink = shrinker_alloc(0, "mbcache-shrinker"); + if (!cache->c_shrink) { kfree(cache->c_hash); kfree(cache); goto err_out; } + cache->c_shrink->count_objects = mb_cache_count; + cache->c_shrink->scan_objects = mb_cache_scan; + cache->c_shrink->private_data = cache; + + shrinker_register(cache->c_shrink); + INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); return cache; @@ -406,7 +408,7 @@ void mb_cache_destroy(struct mb_cache *cache) { struct mb_cache_entry *entry, *next; - unregister_shrinker(&cache->c_shrink); + shrinker_free(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this