From mboxrd@z Thu Jan 1 00:00:00 1970 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 542FDC04A6A for ; Sat, 29 Jul 2023 08:48:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA1FC8D0002; Sat, 29 Jul 2023 04:48:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2B608D0001; Sat, 29 Jul 2023 04:48:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A6B08D0002; Sat, 29 Jul 2023 04:48:12 -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 760B78D0001 for ; Sat, 29 Jul 2023 04:48:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 29FECC0583 for ; Sat, 29 Jul 2023 08:48:12 +0000 (UTC) X-FDA: 81064022424.29.AF5796C Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf18.hostedemail.com (Postfix) with ESMTP id 78B8A1C000F for ; Sat, 29 Jul 2023 08:48:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DZFLwwmJ; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 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=1690620490; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AbdgPGpGzwv3Ba9ss/qbC8w4dcIJ6EfJ8tT9+ztVBsQ=; b=wpOtnqoTixDjnR10TNIxzmjlrdWhY4BSUr7MX6lTRbyAytLz6B/fgB4bJMAXSmdxjjRHXs ota4bjTVWbaUry5TTafZK+iiiSIXJd1h8t7atVqqu3d/laThVobyYDSZuLQtxkHKmejd6u GBJZ7rGc/3oAmI07jKP1GLfQSNeB8VI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690620490; a=rsa-sha256; cv=none; b=C+QTZ+0WmaBp5NXlOJuN52yWqwrI+z+9IFngQlBBY950/cEHKbXsdHIruCneXrgjFTx1OD s8MCW8xmk/nHkxUf3XbHEWWbuj3IC1rSWnkPQtbIDWTQLeH82vR5Rx48mlHMGVhDROKUuV ZM4UWrocEMNC9BJPVbJ1PO6MClWxMiM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DZFLwwmJ; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-682b1768a0bso692005b3a.0 for ; Sat, 29 Jul 2023 01:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690620488; x=1691225288; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AbdgPGpGzwv3Ba9ss/qbC8w4dcIJ6EfJ8tT9+ztVBsQ=; b=DZFLwwmJndUW6zfnORbYzoucbeb9saaQKrl/QBur5VgS6P58gRgdpp8MYduMN550+T ThpBMQd+wqwbcBoSGmvKI7V9Ma4LCpYLWFunl5NiegFEHJNTQE3HPx1j7Fgc5gNqx8Iq YHUiWta6/cfbGMyg9gyEl8Eynz728/mHaw1lMQy+t/GfUp9Wqb7L9kJmHKg93SZhln4L nQEOOjCm3XtItdkVREm8m6+qA283u73jSwvq4ou9Fha1ZKE4dHZmspSiYw7ywEJDGstN q98qzRnKmdM4q9DzoCiLAmxpMakkQvrAM25zQsh718wYNXYSnABRZn4Jdwg4vno9Osq9 PVdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690620488; x=1691225288; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AbdgPGpGzwv3Ba9ss/qbC8w4dcIJ6EfJ8tT9+ztVBsQ=; b=jXBsHmLVLO6q5fLk3e/AnHKkdobq12ucENKwVg+19e4TkS6XrVt7QmpRmlcg0+Hefn 2/ME7+4TeYMBB90CZhQ0j9LfUmsWBKMu1ijHPpM8SQtfVUEIZgNWDGBYRG3jb8yVeJw2 iudyvMlRMbM61OK8CYRv7sKuIUOT8A7GFUpq5qgGhih3fHE6POrYfk1jrqn1Z2Ilwp4K Zxc8b3DbU5jFH9vHduZYNYKIXgrxMzBSyYjb+kMWednXpPjcMxKadHM1P/T9uR6+UoTS LQB3dBkHBXiRoQwbEusMdkqNCeWzUSeu2v8sd2DIpYFFopxw+JGyMztGDOB8P+MfBc8M qLxw== X-Gm-Message-State: ABy/qLaSMdvUiqUh10FtryvAtA0WMLlCiRfD7iQMsOsqQT78Bzg1bVRN jdKTM3qsyxdduo0bDODyqIuyjA== X-Google-Smtp-Source: APBJJlGU4WvDtIE3roPXfr2RIP3jnPqKjXBKgd99me7vK4BYh3P3V9BBkMbm8JQkpcQK7ib8McexOg== X-Received: by 2002:a05:6a00:32c8:b0:67f:7403:1fe8 with SMTP id cl8-20020a056a0032c800b0067f74031fe8mr1763906pfb.3.1690620488142; Sat, 29 Jul 2023 01:48:08 -0700 (PDT) Received: from ?IPV6:fdbd:ff1:ce00:1c25:884:3ed:e1db:b610? ([240e:694:e21:b::2]) by smtp.gmail.com with ESMTPSA id s1-20020a62e701000000b00687087d8bc3sm2935245pfh.141.2023.07.29.01.47.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Jul 2023 01:48:07 -0700 (PDT) Message-ID: <5e50711c-a616-f95f-d6d2-c69627ac3cf0@bytedance.com> Date: Sat, 29 Jul 2023 16:47:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v3 05/49] mm: shrinker: add infrastructure for dynamically allocating shrinker Content-Language: en-US To: Simon Horman Cc: 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, 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 References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> <20230727080502.77895-6-zhengqi.arch@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: uyazi4iy39sr48ahtqjbnbpkcxw63yt1 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 78B8A1C000F X-Rspam-User: X-HE-Tag: 1690620489-315659 X-HE-Meta: U2FsdGVkX18HoGRnsd8eX8f+xc7f6l18AYF8UoglKO4BOx9HspG9I6yW9Fn5enm4hy430FzjViqkwT8jAqQY9VqNeGJamZAnaRavAz+wrWZvPEHPHfJT2pE9UxNVki4WAzLtgXr8+0vQueuRViKBaMpIIC4uaF+kH/YOMXqOSe1bBGujCMNuPexSkHMjFbKl0roRl6C/HCTataPoxRe2I+LWM12+L/NnDSieMJmB0kwPN4Tn+HFMqbwXCWkDXj7cbGn1UeHx9wf8bbKyZT9J08Z5rq2sYvmo+bfxITYcZyGTW2Q6zvr4fyOnjYGgBHhXHb/F6qpuc/K2k3PgrCJKmTvLiWNmeSSshBWVFbmNk93PHtoZdJASlbv7vrfIBI/t3NAwqzITTCOQlJzHL0hH9JpS9yOTvOngk7sHSv9v5xNttHKUl6OsV+Kf8+B/URYg/Ok458SGRvM1iEuxRtRer0MwjpiXmigRKhWtr/o/kqlD6T1BhePc5g7wvmr+yXJ/6kV43N/opWBaFZXaVn1hQv9pLkkudus8MwGhSmYoncgKN/7nTV8zEERIZEWKqLqvusnfi27rb0I/FenUEcFVseJ943zpi324v9MDfxp1LWLdUBetdE+wyqPPJkFk96qJZeVXV0Cr2uvpPleX5POIe+oFBzywp7e9yK8I2Bee4/dfdxQdecGU7Zk6UKql9RNtej+yiZ48M9kKZk5MKwxnFFpbrCnYHuiziyHr1ZSBb4MRix+DNuLlKIBsXSMRRBZnxz1gOs+Nsl8OzNHJwAgUl+Po99XQ76nvJSR1V4nzPy+sEjbN5q3Iyem+4hyfBZDWcAUDDJDO2sQBQZwpxyicpylpWUDGmsf3h5fZTHiEAducpJm4SknJ7xjeP2qu7k8ROLhdIdDeN1+hvxuqAbFSW/zChrKe61azW4oZsAHdkwpjDC8eA00XUlwkfktlldQYDV640f0p/NgDuCWMwyT nL9lht6B ig1+KY67sT6L2378NEHWJynf4ZG8YtznLhv6aidzXj6vT1JdBOoaDXV/9um0sA6QLfwYjURHeebNnZ0W/O1iCM1qWgXelp6QdYNjVQHvfxD8pm5oqrtW+jez5u8PDTk6ITMGo529XjC3HQIJ6//n9tTNnTW1Q2mNHLAW7JCxLZbPJKE/qzwtCCvW46JGBg2WCfoqV33BLPlh3Y7WayfUNu2paDV2B4MMBRl7uulA3vwxUvnqnv7uDO88s5OeUaj42ttawENUBzDMsUyzdJR03cjxqER88oaMKoNWkjiXqnRux2z2y3OfYjbrB2aT4W57HsupozF4pa1z+QBZLGMRWKr3mwoAl26XZ3TjLC9I6aE1fPKGqSImrxvhE9dwfv5g54vyIq+KNQuMk+ELvh7HkgPu37bQBzoq6G37NALpVe54e55Wm30WmNH0CoA== 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: Hi Simon, On 2023/7/28 20:17, Simon Horman wrote: > On Thu, Jul 27, 2023 at 04:04:18PM +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_register() >> >> Used to register the shrinker instance, which is same as the current >> register_shrinker_prepared(). >> >> 3. shrinker_free() >> >> Used to unregister (if needed) and free the shrinker instance. >> >> In order to simplify shrinker-related APIs and make shrinker more >> independent of other kernel mechanisms, subsequent submissions will use >> the above API to convert all shrinkers (including case a and b) to >> dynamically allocated, and then remove all existing APIs. >> >> This will also have another advantage mentioned by Dave Chinner: >> >> ``` >> The other advantage of this is that it will break all the existing >> out of tree code and third party modules using the old API and will >> no longer work with a kernel using lockless slab shrinkers. They >> need to break (both at the source and binary levels) to stop bad >> things from happening due to using uncoverted shrinkers in the new > > nit: uncoverted -> unconverted Thanks. Will fix. > >> setup. >> ``` >> >> Signed-off-by: Qi Zheng > > ... > >> diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c >> index f1becfd45853..506257585408 100644 >> --- a/mm/shrinker_debug.c >> +++ b/mm/shrinker_debug.c >> @@ -191,6 +191,20 @@ int shrinker_debugfs_add(struct shrinker *shrinker) >> return 0; >> } >> >> +int shrinker_debugfs_name_alloc(struct shrinker *shrinker, const char *fmt, >> + va_list ap) >> +{ >> + shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); >> + >> + return shrinker->name ? 0 : -ENOMEM; >> +} >> + >> +void shrinker_debugfs_name_free(struct shrinker *shrinker) >> +{ >> + kfree_const(shrinker->name); >> + shrinker->name = NULL; >> +} >> + > > These functions have no prototype in this file, > perhaps internal.h should be included? The compiler can find these implementations, so I don't think there is a need to include internal.h here? Thanks, Qi > >> int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) >> { >> struct dentry *entry; > > ...