From patchwork Thu Aug 24 03:42:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363490 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 E1B7FC71145 for ; Thu, 24 Aug 2023 03:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81F782800A0; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A8518E0011; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6221B2800A0; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4D8FC8E0011 for ; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2E0B9401B4 for ; Thu, 24 Aug 2023 03:47:54 +0000 (UTC) X-FDA: 81157614468.14.088841A Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by imf29.hostedemail.com (Postfix) with ESMTP id 6E5E6120016 for ; Thu, 24 Aug 2023 03:47:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kmtsq//6"; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.50 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=1692848870; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=tRyv8+xIMMB5/qH+n89ipvNN7wnL2cE6HNW33v1BuAiBQwnys+F9FZcw/WO/01uS8T6U8n GAaoF7+igjjP24ZTwhi7XjzgckG0D0JWxGCjdPozxDeYRDOAM4Q6rVvT5ZrIwqpvkv03+v hwjoJKmnslzTJYihHSolgXHJQaypVc4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kmtsq//6"; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848870; a=rsa-sha256; cv=none; b=t2FMMWEnO1HwCoodD3m7cQxeDNfKnMFbeunkvFNR/EpyOHEKGZ1UggPFdbRkA41cM7jgfZ NPS2IZrrrMapaSRb0UW4XsQ/pqY1+Knity1ckLxDKyvHd46PQNFQtna007l5dmkp+XIOjB pGg+Dev68Twg1/KwgDa+5p89ya+zIaw= Received: by mail-io1-f50.google.com with SMTP id ca18e2360f4ac-760dff4b701so60530839f.0 for ; Wed, 23 Aug 2023 20:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848869; x=1693453669; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=kmtsq//68LoSSVsyr/YBBGvDgqmBUsO880HB0D/X0A9lvPp+wiXhpBHLd0cfIsISJ1 WySRAQJbOB7MirqRDUr1lxDBiz4bG14CaKe7yuO/GO7cBBb0YcTM9Y2I3EbKN+nNzPLi GguYtSQnyC5GCZ96dWUb+BUtsgcR3JqmFJQHmDPKX024szPrXCnBPbbW9YCcGmCws6Ag O3VqAcSntA5bd88T594vNGXtnhYJdlTyYo/z8+mucyI7RsSPbvZ9Tlk5oJv0m0ggTdMc 0VdvEN/SRUhc+98mEttt+2USPb5pXEEKX1ITu4ac2rdVGkAruMTdyg9H0mmnNrZt4fBx MFQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848869; x=1693453669; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=G5th1bFWF7h/OA29DcZXlaXpQ/Yk1tWpxNRBplP9y5GrKM1COV6BK0lZAlG1U0PmAG uIqqh2e+nSj1C6Qs+SRBdDpHHz/KUHmoYrixTi2SZP7ubrsXNPsHCn3hAJD7+95P2vIg 3HM+q2gQfEjzTrR1ZOLQHeQICDrkSRxJPoN0A0H9OGNnZuHHlCjb+9q9e5L5eFLjgqVG MsFCc1tXrew9259ExVESeQrH8FlF2UzUtV7Vp/gKo4IGKk0DL8UqtjtKt6gb+DZ6Q4L7 xynlpDQocJ7r0jojrVELggattJFAzMQTqrYUOooTIyihdfDcjK3h5GbDvgCjmfiKkLtF 5o0Q== X-Gm-Message-State: AOJu0YytpQndWNrvSc6oECnMbMILwzPOgY/VXt65JEpBCw/0xA786niL hexh+3sYXvXkK/XGoRy8qIYZPw== X-Google-Smtp-Source: AGHT+IEQ6BDL0ShOsvxn7MkRzNY4X27PtjN7dkB9TSd0YJiI2pZEQO2zVH6oQz1kCHFDDwRb6mYVFQ== X-Received: by 2002:a92:4b0d:0:b0:345:e438:7381 with SMTP id m13-20020a924b0d000000b00345e4387381mr14623814ilg.2.1692848869651; Wed, 23 Aug 2023 20:47:49 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:49 -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 v5 27/45] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Thu, 24 Aug 2023 11:42:46 +0800 Message-Id: <20230824034304.37411-28-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6E5E6120016 X-Rspam-User: X-Stat-Signature: c3nbfsp18hmsobk1d1fsigjzdfiphnsy X-Rspamd-Server: rspam01 X-HE-Tag: 1692848870-535203 X-HE-Meta: U2FsdGVkX19iLgtLJK+MLlhcRVVRDURtB4HIzJmu/0oABTCNZjpo0fupp6w3wpk0hGwpiaiUUEv2hGAow+2UgYR0u8JWIq4RJDAMIRM80YTOs/bbk0xFYoFgN3F3q4VJ1GDtghpktgO9Al8RPsfSgWuCNPgmMVw4JmS9Lh7qQFTb/FzWTvM/VPCMSIg0JLDS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59zAAn4XTqqCD3rmD/Ff+evpXZ29pWegJ3ABaF1Y20ILV0vadBF1A8KRN4ktfjkcNsuULvgGdh/TfkJfglW7xikoIvG6okmVtmQeYGCypg5HPFChr9NfxYIMIGyPnZQmxevGY7DWgKpHfrPlwfJujd7K88EisYhAUIz4Mm2Rj2Sd5eo9MMGOfLOl5M0P+wn2rZwOTaLu23Z15ZCMC5iefP0QIIW3q/JJ2+OhIYsCoier/6S1paXXy113sBeiZuKzRppP151Nz7Wjpm3M1tj+hv8RM= 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 --- 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..ac2cdb6cdf74 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); } 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->seeks = DEFAULT_SEEKS; + 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; } /*