From patchwork Mon Sep 11 09:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379103 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 1E4A7EE7FF4 for ; Mon, 11 Sep 2023 09:49:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83DA6B020E; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B34196B020F; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D6716B0213; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8C3486B020E for ; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6DDB040753 for ; Mon, 11 Sep 2023 09:49:18 +0000 (UTC) X-FDA: 81223843596.06.0DC722E Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf15.hostedemail.com (Postfix) with ESMTP id A5367A0022 for ; Mon, 11 Sep 2023 09:49:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hkmsW81B; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 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=1694425756; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=RrblDNzmkFjhHMzlfXgn6cHiNDEGEJkff30NVa99vkvCvEtRk8OYMuTFtTIhKgFyBAXXsh yZz/YvaxyQ19E/Z5msvScQ7STy/VgXglP1UfZRuLdi1oB3QwyLH+6euZ5sjYiFv8i+80UW QVeH0Fuz2KQr91IkpbPu7Ko+5j32fTk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hkmsW81B; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425756; a=rsa-sha256; cv=none; b=rMrbbVDqWv/PDw4mk8sw0tVhHzresK+DXB7GPLimtG9ozQQrbjH1jCVNkFpPH3b7hirhvB SRoQ/nS0FkMIqlRw8PU2GtCMROZXXPcVTzZsFg9ztuILYLuzOxF9Emz0qQey5Hr16ld/e3 pilDnoG3XLHRM7sot+RddQbYpguJIGY= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1bf1876ef69so11142465ad.1 for ; Mon, 11 Sep 2023 02:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425755; x=1695030555; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=hkmsW81B4YxYNoZmwdtDSKnpCbdum8aP+xRhJG9LPkYn0XUZ60ucqXdbASQegh1v+b Sdt9DFzqo6GoArXZbMMBSOZsHTmro3vcGEIGqwTiDrA5fljBTe/yCu/Barh9UJ47uxfz XxsI9+y8RNkcYX7muQ5Bc8Nc+py99Td2LciDBpBu5hlbPDKquspjET9VJtaoxhmM2jfs 7RzdwZrLNNFhpx49bce20zhsL6G988Gv5C5PlR81EI7jOVew951emMi4Pq8g5LrQkG4x 2BdjUC7eeFO8CP0N2KcLA+tbTIZb9rCUYhYOK4EULQ8ha3vif6cVplgMFFlrnYvfaDIQ Ivhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425755; x=1695030555; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=ISU7mwBML9Ngjettl4c/0lChUPFd4TcksRTscR30sz+dIY82kBHd/3FR156aqQu/wZ JfZi0ZFHqzZg2cwr9+APK/3LqW4Aov4PfbvaOD/cMNavl6UyTR1tL+doJrkIoWi9BMi6 xHpNrZdRp03lFk0XPH+yX/z8YAkOA3RwUEFMvK4u5OUBRiLGa2/RxybRau7CfjgYyV5P ba7038BIUvJUCuJJxusgLcNmfEAYjL+XnFsbyGpLg7atUIYb1op/X7T9FaaaqGKYKCwq kvIewqjYMQGxA6tMQ1iDOynyMqXrOpU2PoE3OhVDKof6nfXva1T5A11HOMKZJTLom+rj 2ZMQ== X-Gm-Message-State: AOJu0Yz5u4q3nBKsCNP6LaCU7qdV9ZgRfWRYHdyUtoKzIgEU43Jp5qzE EXTPzErXerKNB6Y+iqxKEYwrPQ== X-Google-Smtp-Source: AGHT+IEdRnAd72WYbN/lPKVmYN7Gm8oLIBUCIcL/8BMMQo0OE3Z9NszhBcdotvpIkMipjaUIUmLwpA== X-Received: by 2002:a17:902:d508:b0:1c1:fbec:bc32 with SMTP id b8-20020a170902d50800b001c1fbecbc32mr10682658plg.6.1694425755638; Mon, 11 Sep 2023 02:49:15 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:15 -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 , Nadav Amit , VMware PV-Drivers Reviewers , Arnd Bergmann Subject: [PATCH v6 27/45] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Mon, 11 Sep 2023 17:44:26 +0800 Message-Id: <20230911094444.68966-28-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-Stat-Signature: bis8sakgjeohtex85t3hityc3kieu9ju X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A5367A0022 X-HE-Tag: 1694425756-943083 X-HE-Meta: U2FsdGVkX1/HxsO01lMdC+OlXQ9678NT2zfdICCp8HY71bzKsbPdHgVlNJCC/zPVQBuGCTjjh0bhfjWHrUzHDrW7rSLKC/1WIdUFRvso/dnYNXgKFIweNFsMIT8LtyEWe2eTQmpx52fMS1UMVQh/aSiubz1apV1U79nwkXQGdlcyY+1tmR04InhnBCHWuXHfHzcKVn+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pJ8ZVDanY4Cjw8TP01X76nHhK8CbqMYBmtB8TJGuNLyGOwinSY58gJDO0vF1WSNwD+B8MmufGaxSozNU84Q559sG/kUj/reQZYZAh5fb5cKtIG9Kx3v9B20u/IcLEt3w97nCPlU8rjqrhMwI/rRsmNnKAieVrYWrZuJlzVQ4JNmMH1K2IARfkd1fuCgllKvR+W3nR2cFN/EwLcEWIcgcMfFP5OWkuE8VS92Ydn5hIxgJuY/GLJzeKTryGTP7cE= 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 vmw-balloon 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 vmballoon. And we can simply exit vmballoon_init() when registering the shrinker fails. So the shrinker_registered indication is redundant, just remove it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Nadav Amit CC: VMware PV-Drivers Reviewers CC: Arnd Bergmann CC: Greg Kroah-Hartman Acked-by: Nadav Amit --- drivers/misc/vmw_balloon.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index 9ce9b9e0e9b6..c817d8c21641 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -380,16 +380,7 @@ struct vmballoon { /** * @shrinker: shrinker interface that is used to avoid over-inflation. */ - struct shrinker shrinker; - - /** - * @shrinker_registered: whether the shrinker was registered. - * - * The shrinker interface does not handle gracefully the removal of - * shrinker that was not registered before. This indication allows to - * simplify the unregistration process. - */ - bool shrinker_registered; + struct shrinker *shrinker; }; static struct vmballoon balloon; @@ -1568,29 +1559,27 @@ static unsigned long vmballoon_shrinker_count(struct shrinker *shrinker, static void vmballoon_unregister_shrinker(struct vmballoon *b) { - if (b->shrinker_registered) - unregister_shrinker(&b->shrinker); - b->shrinker_registered = false; + shrinker_free(b->shrinker); + b->shrinker = NULL; } static int vmballoon_register_shrinker(struct vmballoon *b) { - int r; - /* Do nothing if the shrinker is not enabled */ if (!vmwballoon_shrinker_enable) return 0; - b->shrinker.scan_objects = vmballoon_shrinker_scan; - b->shrinker.count_objects = vmballoon_shrinker_count; - b->shrinker.seeks = DEFAULT_SEEKS; + b->shrinker = shrinker_alloc(0, "vmw-balloon"); + if (!b->shrinker) + return -ENOMEM; - r = register_shrinker(&b->shrinker, "vmw-balloon"); + b->shrinker->scan_objects = vmballoon_shrinker_scan; + b->shrinker->count_objects = vmballoon_shrinker_count; + b->shrinker->private_data = b; - if (r == 0) - b->shrinker_registered = true; + shrinker_register(b->shrinker); - return r; + return 0; } /* @@ -1883,7 +1872,7 @@ static int __init vmballoon_init(void) error = vmballoon_register_shrinker(&balloon); if (error) - goto fail; + return error; /* * Initialization of compaction must be done after the call to @@ -1905,9 +1894,6 @@ static int __init vmballoon_init(void) vmballoon_debugfs_init(&balloon); return 0; -fail: - vmballoon_unregister_shrinker(&balloon); - return error; } /*