Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10600354rwd; Thu, 22 Jun 2023 02:06:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61UfOAzmeWxAT4A/82qRchsKihV9iOrXGZUdpT9i9K6hp+0CwoXS15TddOY0Wt7KiDsBtZ X-Received: by 2002:a05:6a00:2351:b0:668:6445:8931 with SMTP id j17-20020a056a00235100b0066864458931mr18842240pfj.29.1687424776557; Thu, 22 Jun 2023 02:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424776; cv=none; d=google.com; s=arc-20160816; b=SEeZ/tHkCtN2qj2rTf72uT2Nk3n/bzhnbgwuCMel8PGhRr4MH0vCo47x5xcW6VBaPT CkBEU6S92LYbiXq0TDPWSG3RtAko7N4Yr6xxJS0SV/wLba6RuxQ4p1uYWs7/L1F5N6gd /OpLqFjtAGtrv+bHQzVdeA3rdt8M7JSrbeyimGbYaU7mtX2LqTZF9lcr67WQU5G+2abx uyeVlYNEjlKHpiB73/NP5v4ZpDledrnuHRL/1Murx3ZynxMgcrae0hiscJV5aIyU24B3 7irijU89TQN80HxddFRxr43HThQDSAigBCv82IYXj8r7H/eOn8xRjhoBp6uc6NcYyocn Lpgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZsvVWwvjCNbIpzLWR+JMbRdqcPMoA6IncSRNtrMJjtk=; b=hTTZwQj1RTyEWci+XWsxr+fAtomhCinH6eFUliwxtIalnMn1TGIbwFpuIaifKl3Dhg LN6d/vKBksShjybxREzLAkqxESk9iX5D0tDyk9LtZJlR9OTiPRDB+HPE66Wk095uto8k QZonj73TsBJtTuRT3UdY4VeQO7TNmYUTATckyHjV3uoJxKIMa2aHFQSi9qbTM7g01ZgE XLDWeBpq67tjECjmT6wGtOqFNpdfXfmoUvPnfQvdceUAVT2dauBPOtulIx+hSCLzJT6W JiXZuVylnvMnWq+jutkdRDr8p9bULz7FAJ+QRqFfBegut7+fuM9MOZrueX5BCjumvRft wCtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=btQFnTi1; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a63aa03000000b0054fdf58c23esi5557756pgf.680.2023.06.22.02.06.02; Thu, 22 Jun 2023 02:06:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=btQFnTi1; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231861AbjFVJE2 (ORCPT + 99 others); Thu, 22 Jun 2023 05:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjFVJDt (ORCPT ); Thu, 22 Jun 2023 05:03:49 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93EE5210D for ; Thu, 22 Jun 2023 01:57:41 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-54fd4a7ce25so1096461a12.0 for ; Thu, 22 Jun 2023 01:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424227; x=1690016227; 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=ZsvVWwvjCNbIpzLWR+JMbRdqcPMoA6IncSRNtrMJjtk=; b=btQFnTi1+Jxgpt9ZEv6SV1CxbtEwEnpYQ1WSSwhfGLNNoz+3LZU80wQIeDEMGJinhi 8+hFjjrmI0Ti2weoui+1nba3fuqZZ6jN3eQN4e+CjSeo0Ggyrqg3j3GGKdGsxTGtEKKB 6n4ntOH8ClqO9PsI9RmJeFYa/h0xYT0vefdwMfx1z83TBiR/mTSXCJDkn82jEtfe964Z +W5pu2WQm5/BmUewzteVLri/ASv79HUROzRO9GvLtgUyAJkwQyVDE/hnKFhVeWh3zZR/ QE/dybVozXXKkm+aMId69JeSrmobjvQPBxgZrNjMENKTPWKUy1hHiQ4+Qa8p1f7rRS3j Hymg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424227; x=1690016227; 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=ZsvVWwvjCNbIpzLWR+JMbRdqcPMoA6IncSRNtrMJjtk=; b=PkmcR4rkKzgi5+8QPLk2WZz8VUbIyWTfWhG6YYBnxlfdRfApKTfEahAELs21PuTBAk bMlxBoTGP3zwTijzV2hjY3aWNo8nlnq7O2pOWQhjBBcyi66VWDHt/OBlyU03nmstf8VP Yiwospav5QLlWMzQ7j8wHik8I8VQPKKw8kOJxJLz3TQccBvfHWn69Q6lPVXH5Of9VvK/ NQbp/Q2uv1ztRYD3hMbyJQsOM0HBBae37GLJ98SQS9R75+74YZqTCYkaIVcyrz3TaiRB 2bTVOuMm0StMhdetmFkUk1Ldw05/RmL+jVDztSc7/w6eD7BpOdQacXtqWF1oK9qQr8Ll KWUQ== X-Gm-Message-State: AC+VfDyYaE62RjZQ1t+B7CayDbYi4CktrIEE7YvRvTfCdARsJQE4Okqg lmckkagBD314x8S+RkP59mxTnQ== X-Received: by 2002:a17:903:1105:b0:1b3:ebda:654e with SMTP id n5-20020a170903110500b001b3ebda654emr20780380plh.5.1687424227653; Thu, 22 Jun 2023 01:57:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:57:07 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.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-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 23/29] mm: shrinker: add refcount and completion_wait fields Date: Thu, 22 Jun 2023 16:53:29 +0800 Message-Id: <20230622085335.77010-24-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This commit introduces refcount and completion_wait fields to struct shrinker to manage the life cycle of shrinker instance. Just a preparation work for implementing the lockless slab shrink, no functional changes. Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 11 +++++++++++ mm/vmscan.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 4094e4c44e80..7bfeb2f25246 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -4,6 +4,8 @@ #include #include +#include +#include /* * This struct is used to pass information from page reclaim to the shrinkers. @@ -70,6 +72,9 @@ struct shrinker { int seeks; /* seeks to recreate an obj */ unsigned flags; + refcount_t refcount; + struct completion completion_wait; + void *private_data; /* These are for internal use */ @@ -118,6 +123,12 @@ struct shrinker *shrinker_alloc_and_init(count_objects_cb count, void shrinker_free(struct shrinker *shrinker); void unregister_and_free_shrinker(struct shrinker *shrinker); +static inline void shrinker_put(struct shrinker *shrinker) +{ + if (refcount_dec_and_test(&shrinker->refcount)) + complete(&shrinker->completion_wait); +} + #ifdef CONFIG_SHRINKER_DEBUG extern int shrinker_debugfs_add(struct shrinker *shrinker); extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, diff --git a/mm/vmscan.c b/mm/vmscan.c index 3a8d50ad6ff6..6f9c4750effa 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -740,6 +740,8 @@ void free_prealloced_shrinker(struct shrinker *shrinker) void register_shrinker_prepared(struct shrinker *shrinker) { down_write(&shrinker_rwsem); + refcount_set(&shrinker->refcount, 1); + init_completion(&shrinker->completion_wait); list_add_tail(&shrinker->list, &shrinker_list); shrinker->flags |= SHRINKER_REGISTERED; shrinker_debugfs_add(shrinker); @@ -794,6 +796,9 @@ void unregister_shrinker(struct shrinker *shrinker) if (!(shrinker->flags & SHRINKER_REGISTERED)) return; + shrinker_put(shrinker); + wait_for_completion(&shrinker->completion_wait); + down_write(&shrinker_rwsem); list_del(&shrinker->list); shrinker->flags &= ~SHRINKER_REGISTERED; -- 2.30.2