Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp683557rwb; Wed, 26 Jul 2023 00:42:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlG0lzK+jH333q/B1ZKjFE8Zq13bytLU9WxVlzSsJnRz5IMhc0N4EtvfuT+D3l76IsvGYZZ1 X-Received: by 2002:a17:902:cec3:b0:1b7:ffb9:ea85 with SMTP id d3-20020a170902cec300b001b7ffb9ea85mr1610000plg.29.1690357335669; Wed, 26 Jul 2023 00:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690357335; cv=none; d=google.com; s=arc-20160816; b=oJBRKGWwd/0mEhNfmwoJTIoI4pHgEU1J3BiLwy0zIasoCJ5iPwTKCEa+S//Ozy98AA 7hHuMilYiKkNSJAhR+G3cwi+ihNJeBhYd9S70x0dvf08klivS4B0qkESzcClT51k17AR +U+ycNkLfvI68AcfnWAjBFKvAfpzhLXSHVllVoSs5hmencPAhAIvK+NEgu7J3gYjjDhb lN6IMqEpZVYDOej4oc2QJSN7ZeFrdgKvJw6xwy3fF39KzImVGmuvDEsOKg8weYF3Pygd qy/qeETAbiLz80Q/7OvSH1etUWraYGVyf0zl7kocebtt2AflxetuD2Vqttxce/cfsw+8 KUIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+zeJUC9bLKU1rvuVX6lYw88hUmzqKAeHPtzffozeycY=; fh=QAn153OZ9dhECkFENFeyW88wUMQavLbxl7U/+ckxNgY=; b=ospsKk/OmKIoMDEY/dPtRvOgxaG3640+VvUeFanR5ap2CNUTzhiFaCZALpXip4A/ap I++VMQpIOJhlt/eZCXR0xPv7VUg5uDUvsY9Am1XyrJ0tvDbWPoK3R2kBGw8s/LfdK5Ql JCIPLMIJ7WrvUWnW0j3ljmAdD10NstoPWN/g0oyEY6OZYKC+zIpeWyB6wgzOks8YLtw0 Q6CkaDuytUYBxlAm0Jacmn7rYI5khzFpLKx0k9nrTlaofql+5qlNOlbPiS4IGSzkc1MA etQnDDTr6QHCnaslGGlMDWGf7pkKzEUkjiPCKivfGlYaaG1/0BVmcV7VKspR+KC1Udd0 mGtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20221208.gappssmtp.com header.s=20221208 header.b=tq09HWgU; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170902ac8b00b001add2ba445asi11974894plr.259.2023.07.26.00.42.01; Wed, 26 Jul 2023 00:42:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@fromorbit-com.20221208.gappssmtp.com header.s=20221208 header.b=tq09HWgU; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbjGZH2O (ORCPT + 99 others); Wed, 26 Jul 2023 03:28:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231871AbjGZH10 (ORCPT ); Wed, 26 Jul 2023 03:27:26 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8BA3A87 for ; Wed, 26 Jul 2023 00:26:07 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686bd857365so687336b3a.3 for ; Wed, 26 Jul 2023 00:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20221208.gappssmtp.com; s=20221208; t=1690356367; x=1690961167; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+zeJUC9bLKU1rvuVX6lYw88hUmzqKAeHPtzffozeycY=; b=tq09HWgUpDUq6byqrA2ODCQvkmm9az77yWJFeqeVMy0FdFbQydZS+cUOs64uJ2SB3t JVe6zLPb5fssr5t5MVQUOU3aAgE6xxOU2jteEAzPtsSb8VWd+wB8OkrdKfGE1jZhlj5w TjyyAjaB4CZbrKROQT36TogKeOKjWN45v44UiK/0cxwlhI07RMRGs/cyjwVDCOvRwded lUKql7WZYCe6f5lQSR03cISDY6tgj5wgcwRkwmI723xyLURdjFU3QXYzRwiEbnZzpb+Y l5EpmyZiiiT3lVpIPopVTNPz1HtZxyTgaW+3XYB75cUNHtZ/C6Tv2cVXxlw6MGh6VRdH zVDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690356367; x=1690961167; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+zeJUC9bLKU1rvuVX6lYw88hUmzqKAeHPtzffozeycY=; b=Xex7KDSTbdyMNnN2yb14+G1yV89J7laFR27Fgw2+rhhzmSmxntloJd7fX62ir8lGLm bQGTYFe+HebJAl/vIIZRbirlBGWGc6+efIuc7ct2vTBYIo1zRXrci44P/HeqX/MbtKSl NN+ERp5ilSh9hJXEuE0rKhoVB1WE6L7kiQwb7x/sZCvvTKXYamJEc2Pc/eKwTxHHh2Ib 4racTOMtdmSl/5IVjTrJs0xa0Lv/tjvmoIM3MEPZmIIFFluxtyrgjvteBx0wnwlIVNoC 29NjTJDRQBwB8ZmpvQcNt19l+KEJWFyFapjTvblmuSKYaJUcfL9KybU7JVpfdjbmnPxr 7h9Q== X-Gm-Message-State: ABy/qLZnj3V7IjIfnpFGR+pSt0uGUxBuxkQuCaBA6xbSnTI2Jcz+XwDr mqu7wyY5lXNM5sOyQBBcHN6iHA== X-Received: by 2002:a05:6a00:a0d:b0:67a:a906:9edb with SMTP id p13-20020a056a000a0d00b0067aa9069edbmr1921084pfh.30.1690356367307; Wed, 26 Jul 2023 00:26:07 -0700 (PDT) Received: from dread.disaster.area (pa49-186-119-116.pa.vic.optusnet.com.au. [49.186.119.116]) by smtp.gmail.com with ESMTPSA id r5-20020a62e405000000b00666e649ca46sm10751809pfh.101.2023.07.26.00.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 00:26:06 -0700 (PDT) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1qOYuK-00AfFC-0I; Wed, 26 Jul 2023 17:26:04 +1000 Date: Wed, 26 Jul 2023 17:26:04 +1000 From: Dave Chinner To: Qi Zheng Cc: akpm@linux-foundation.org, 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, linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.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-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: Re: [PATCH v2 03/47] mm: shrinker: add infrastructure for dynamically allocating shrinker Message-ID: References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-4-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230724094354.90817-4-zhengqi.arch@bytedance.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, 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-ext4@vger.kernel.org On Mon, Jul 24, 2023 at 05:43:10PM +0800, Qi Zheng wrote: > Currently, the shrinker instances can be divided into the following three > types: > > a) global shrinker instance statically defined in the kernel, such as > workingset_shadow_shrinker. > > b) global shrinker instance statically defined in the kernel modules, such > as mmu_shrinker in x86. > > c) shrinker instance embedded in other structures. > > For case a, the memory of shrinker instance is never freed. For case b, > the memory of shrinker instance will be freed after synchronize_rcu() when > the module is unloaded. For case c, the memory of shrinker instance will > be freed along with the structure it is embedded in. > > In preparation for implementing lockless slab shrink, we need to > dynamically allocate those shrinker instances in case c, then the memory > can be dynamically freed alone by calling kfree_rcu(). > > So this commit adds the following new APIs for dynamically allocating > shrinker, and add a private_data field to struct shrinker to record and > get the original embedded structure. > > 1. shrinker_alloc() > > Used to allocate shrinker instance itself and related memory, it will > return a pointer to the shrinker instance on success and NULL on failure. > > 2. shrinker_free_non_registered() > > Used to destroy the non-registered shrinker instance. This is a bit nasty > > 3. shrinker_register() > > Used to register the shrinker instance, which is same as the current > register_shrinker_prepared(). > > 4. shrinker_unregister() rename this "shrinker_free()" and key the two different freeing cases on the SHRINKER_REGISTERED bit rather than mostly duplicating the two. void shrinker_free(struct shrinker *shrinker) { struct dentry *debugfs_entry = NULL; int debugfs_id; if (!shrinker) return; down_write(&shrinker_rwsem); if (shrinker->flags & SHRINKER_REGISTERED) { list_del(&shrinker->list); debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); } else if (IS_ENABLED(CONFIG_SHRINKER_DEBUG)) { kfree_const(shrinker->name); } if (shrinker->flags & SHRINKER_MEMCG_AWARE) unregister_memcg_shrinker(shrinker); up_write(&shrinker_rwsem); if (debugfs_entry) shrinker_debugfs_remove(debugfs_entry, debugfs_id); kfree(shrinker->nr_deferred); kfree(shrinker); } EXPORT_SYMBOL_GPL(shrinker_free); -- Dave Chinner david@fromorbit.com