From patchwork Thu Jun 22 08:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288589 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 E0B5FEB64DA for ; Thu, 22 Jun 2023 08:55:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E4618D0005; Thu, 22 Jun 2023 04:55:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76CEB8D0001; Thu, 22 Jun 2023 04:55:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60DD58D0005; Thu, 22 Jun 2023 04:55:26 -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 516608D0001 for ; Thu, 22 Jun 2023 04:55:26 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 31CD180761 for ; Thu, 22 Jun 2023 08:55:26 +0000 (UTC) X-FDA: 80929775052.22.C4E8B86 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf22.hostedemail.com (Postfix) with ESMTP id 4BF6BC0017 for ; Thu, 22 Jun 2023 08:55:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="f9niG/1n"; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 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=1687424124; 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=u/vExFBLW3qTniAw4XeP9KQ69i9zow/4wwrpInqlwjM=; b=JP07DisFoDa/vWCMd2yUfGwzzqM94sGZz59GpmZsB6tc6w6aAma4rNqHMBI0lkFRWiY7ll UivuZhSdeZfwjx52Cm11sPMx39+mqNspdbSXZcd9b23nTEL1gM7PW1VgmaijVo8Y2tZujr fNM8SxIiup96iWIh/Aj3n+DACmMrjbY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424124; a=rsa-sha256; cv=none; b=eBD83Q1i4AlrvJmB0OcwSCVSF0zgjvam4uc5VcBWuPhClSuuoABLLrCc4pTnlHgxmPTmca hV3EbC2fq4zbBVD+w+JYnQaNbe3ehqoIbrIiisVCD9vsmAltRrdaMzwplNRl6IZeETlDf3 +zncEWiJhTU/YmJM9GKeJa4e6y5zDRI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="f9niG/1n"; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1b52418c25bso12032625ad.0 for ; Thu, 22 Jun 2023 01:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424123; x=1690016123; 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=u/vExFBLW3qTniAw4XeP9KQ69i9zow/4wwrpInqlwjM=; b=f9niG/1nDZCnLyGAdmXOPnr0UhYRgdnlIknKHTp5fpAvQQctnSzqFRWkCf20Ww177d QG9jeeQWMuTex/IwaFDMA8vXlH6fpJPO6Zn2dpmhMfbdqmxsLU2UIGO2NDOzTGYWiDw7 ywIPFwnvUTjEHuZeccmcjrjEkLsXSYquHahbHd6ZdjnzqEP2RHdSMNMWgiY9L8TVZ0lC G4aVTSqjJ5NrWtnVCJTDf1mbR/bEFK3aai4gwzFQmPA34Ikuzxs8i6IqNfr5Nxc5N0yO /Hq8+LGyQI4XHPCqHbrNX4k2UTVR4h1zk7vD27aNaHUnKMeOkCqJba/XQtzAGJZToHzN Aj7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424123; x=1690016123; 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=u/vExFBLW3qTniAw4XeP9KQ69i9zow/4wwrpInqlwjM=; b=XbZ/YUBKLe1eioC+a7tyAiX4A6bIm7Xw3CGutwtClPANOiCSM3Zpt6Bhwoez/2t18Z TDUXqQw70jBxr7DLILofbod1d3Tf6mhuR3PrMuO4A1VdG/t2dE7HYqE+HnmlnTYDY90m FZGiOYQaRPNWtMANNSoVnipMLtujZUDCFjXccAFWI6l2vIDQZ39773Bs6K5/HEr6qdkC uW6x0rTG8/qxi2Uiy+r6PjlQTIUKmrop4i8ROL4g2246UQNgxBSc45vLCgfEGHt5iXsU LgiO8gA7MpKlMJCw/FvV5vMXkS6mnPTSOc8MDfEEpZWTyrWq7ewlFFtF/+ppqIqQe1Et CL8g== X-Gm-Message-State: AC+VfDyVtDZzbMg2972AFtBitJVl+ofSJtdU/Fz64YZq5ZiGVS6cI0ia tkBAjS9m3dENGqsS/GOEAHyBGQ== X-Google-Smtp-Source: ACHHUZ4R6XsCch8DMbBn2ilzIIAPskFMWcDdECndDXpbpwroXAZTFBoXbn8TaLTiXdt1Xz94/St+OA== X-Received: by 2002:a17:902:dac6:b0:1a1:956d:2281 with SMTP id q6-20020a170902dac600b001a1956d2281mr22035085plx.3.1687424123198; Thu, 22 Jun 2023 01:55:23 -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.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:55:22 -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 10/29] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Thu, 22 Jun 2023 16:53:16 +0800 Message-Id: <20230622085335.77010-11-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 X-Rspamd-Queue-Id: 4BF6BC0017 X-Rspam-User: X-Stat-Signature: tkw3eyurjjion1eqgf67gr717jbu9qxx X-Rspamd-Server: rspam03 X-HE-Tag: 1687424124-718913 X-HE-Meta: U2FsdGVkX19CjhVa93HxTtha6vcbGCN+UW4bP2oYSJN+tO3l3rbqZ9tsvigCCEbE/uf7RagY4US1lGI8wLXqSdFqTLwH3fgFO9MHuAvUOReCr7x5i/s+j0swkDurgQwoMiV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vK0CoETEBcIt8N6Za+Fe0Ylj+LFBjFIbT5mr5rP2EMt/kloyoYsrGji8foozXLWt+tAvrmZiTTb4NwlS+Lrr8qveYQLf30WSeOnTCFvXtuOplDMfDDnUO0OsLt67z14CFpIHgxHlnnfQJEs8NiJPcMWEnMaGQ3xYLgE4Zi7RfteDMGdPRCwoea86CdUf9+1wGOvSiMxt4jV64XfvGrYinsErRhpM2Ji+nGhx5Ki1I0pSKly1BoeY/zt7fJQ== 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, we need to dynamically allocate the vmw-balloon shrinker, so that it can be freed asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU read-side critical section when releasing the struct vmballoon. Signed-off-by: Qi Zheng --- drivers/misc/vmw_balloon.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index 9ce9b9e0e9b6..2f86f666b476 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -380,7 +380,7 @@ struct vmballoon { /** * @shrinker: shrinker interface that is used to avoid over-inflation. */ - struct shrinker shrinker; + struct shrinker *shrinker; /** * @shrinker_registered: whether the shrinker was registered. @@ -1569,7 +1569,7 @@ 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); + unregister_and_free_shrinker(b->shrinker); b->shrinker_registered = false; } @@ -1581,14 +1581,18 @@ static int vmballoon_register_shrinker(struct vmballoon *b) 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_and_init(vmballoon_shrinker_count, + vmballoon_shrinker_scan, + 0, DEFAULT_SEEKS, 0, b); + if (!b->shrinker) + return -ENOMEM; - r = register_shrinker(&b->shrinker, "vmw-balloon"); + r = register_shrinker(b->shrinker, "vmw-balloon"); if (r == 0) b->shrinker_registered = true; + else + shrinker_free(b->shrinker); return r; }