From patchwork Wed Jul 31 06:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Li X-Patchwork-Id: 13748188 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 EC702C3DA7F for ; Wed, 31 Jul 2024 06:49:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21DE26B0095; Wed, 31 Jul 2024 02:49:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1566B6B008A; Wed, 31 Jul 2024 02:49:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E00866B0095; Wed, 31 Jul 2024 02:49:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 95FEE6B0088 for ; Wed, 31 Jul 2024 02:49:26 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 48CE91A017F for ; Wed, 31 Jul 2024 06:49:26 +0000 (UTC) X-FDA: 82399121532.05.076C200 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 8DF21180003 for ; Wed, 31 Jul 2024 06:49:23 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QI85PgWk; spf=pass (imf06.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722408508; 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=XNHUxihQ6L0RDgCA95Q8Li1qX6ValIVmUiuixGOIno4=; b=FQZtw5qKjVgKUuP4ap0YnmQl0TAHF1taf28qwoIZxuHsWT/D3nuHpPL0q+MOcDcVc6i2SN HoeIeyD5V+j9DHJLhnf6RP6ys2wqcLolPAeltcuAHrgs3LaK48hHh1a1aKvyx93vSbUm2n lcPYKO2SKOWbuVkeE02AYhZVCmkOB6A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722408508; a=rsa-sha256; cv=none; b=f1yX5l5Ga1lN41FH/5txghIW+q/N6iBv9nvoGA1MdzYS8mxVVQrPPzFlz8+CR1OySJOoyw ipq+8dpe7yJLKAp9PUMVNJ3EU5TqYEB8EeVBXtqHPYaGx9jr12J7Yph1YP+euoIfITtb44 Cg5chUmkYc3ZtwenNunHcckL/GzaZXE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QI85PgWk; spf=pass (imf06.hostedemail.com: domain of chrisl@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=chrisl@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C92A1621F8; Wed, 31 Jul 2024 06:49:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4669AC116B1; Wed, 31 Jul 2024 06:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722408562; bh=mFTpCV7XNA0Q39wY6mTWVaq5W4nsa4d0OkBcY1l+IsU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QI85PgWkPs/n+4oHRNul+S2Hb87b9WfYCiP9KF36fh0yy05RRPF8RDd0RTg6h8e0T hmx6DVEUupfOip8hPEYA30Lq0l5BlASGFYOBVjFfAc+HU2dM0cLqdExkqi/LAfwuPJ 5bri/GYwmerEpO9awQlnLQf6o/74Tnt5u3b4XpL37eEs+2npF3NDP/BJ58Jy77hnuq V/d8r9A2ezC3fjXGp+1XXZXLwT1PrLLBKjrnyxIeD+rTAIhHFVSsgOJZB9+NdjuDMv XcRqv/SkuTbN30JM+64812/Ic5yUn7Hb6zLh4PCNxjjWcRvbXGlO4vddrsIh7Fx4Ff iKCuUz8yS1o1Q== From: chrisl@kernel.org Date: Tue, 30 Jul 2024 23:49:16 -0700 Subject: [PATCH v5 4/9] mm: swap: clean up initialization helper MIME-Version: 1.0 Message-Id: <20240730-swap-allocator-v5-4-cb9c148b9297@kernel.org> References: <20240730-swap-allocator-v5-0-cb9c148b9297@kernel.org> In-Reply-To: <20240730-swap-allocator-v5-0-cb9c148b9297@kernel.org> To: Andrew Morton Cc: Kairui Song , Hugh Dickins , Ryan Roberts , "Huang, Ying" , Kalesh Singh , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chris Li , Barry Song X-Mailer: b4 0.13.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8DF21180003 X-Stat-Signature: pu5dgiefmdebjttxea71ay9bxfk4gqab X-HE-Tag: 1722408563-628302 X-HE-Meta: U2FsdGVkX184W1oNSAOa26v3SNM+fD7C9pcR7GAtMMpJ4FJcuK2mn+p7WAD4GvkF+tmELph2FGbGgfxWaYy649lPIucE87kZ1+mBQ+efhCA3oWy9oenQWqhfFa17Mkzaaw5GmYEjPQhlU2Qvef2FRQn7tuADWxjOOOUocAVs8Xt8R9rN2X+QZkRVoBABt27NnF8ntkslxNwvkhztqCloGXGeXQJmgS7WJ2mpL3reu74EdAQEhlBgRfUgzJwoZ8w+AlSwj7WyM+ZoLhrIYxxOacRt+7Cs6nrUejTXKOU8e9SZUnl+So4se5zeLg9EGxKX1YaO/QFwMC8zKQn+Kviqp7qKXPz/hiycq18QQnOltyY23qDIiotGDk34E7Zo8I2vs1FKVczUSEpBOgdQGXpAlJ5SXlc8TXQLy12GAth0lDK7AAcL6c7B1SuEQ0FIBbI0nUIBMTJLJxUfJKd6Kny5kwfhT4M4U4JByzpSsAEbRMniZh6tlwiVMCPCjSn08WAAzfTBA/fhr0C66/RS9dVX+ixDbWqZV8Reh1b8SSX3opdEYk8YGiYXNiuSERR3wK4Lr9aa/uVDckCBqXEujoln5j46U8Am5BhcDt1FtYkhZdRHuZFuZycxMyv+yz8qsRbcSPnFMPbaEp6CzW6Y8Br+mLQTZhy2wLeHCOsuxH4KGMPKL9UwOBt3rOeNnmOUC0ye7VnH1AcCEQ4MNyz0qzpOaPhs3+vlrSJ+zVbuJHd3LfoPNZVbWTEaRuJp33QQo4k+UMpNnlMQ6FvJMWmPf0iz3TE/3oFZtFyf0i6+MKvRj8cwI9hw1a2cVUPgNEx1WbuFPLAt9Gl42IDYsUFGeRkMbcMJXrLRCmVoPYygIt/IFrGlsOUiyZkiP/xuvYue74zKh2UoB45lo6lt8jSdKsGUbvYTjyEJximv4J15MncNkHJ9m8cOMm/of1GzGjkufx7SJEbu5u4KgK2EAtehZhF J4WN/oul p/M8KzD9EmTLVTkhVlritpyClJIOoMczKUYbFWishNwHlrvUWbBfhreekLKcv4qUerq2jl4lBM0IdtRpJxkBtE0F/JzXnn6vDUJ6LqDzBu2QhIBHiIeaqUOoEPeHv0+0A0L4cx3ak4ryENt1Kex2qoxInK0SgF+UA3YIWPXiMY7snF/cI0cC446arxRnaGIv2UPHybbyPEtl0qoOsc6zHngbeCr8oWzCGblA59tqH20h6v/y6QhMkZebogQ== 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: List-Subscribe: List-Unsubscribe: From: Kairui Song At this point, alloc_cluster is never called already, and inc_cluster_info_page is called by initialization only, a lot of dead code can be dropped. Signed-off-by: Kairui Song --- mm/swapfile.c | 44 ++++++++++---------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 8a72c8a9aafd..34e6ea13e8e4 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -438,20 +438,6 @@ static void swap_users_ref_free(struct percpu_ref *ref) complete(&si->comp); } -static struct swap_cluster_info *alloc_cluster(struct swap_info_struct *si, unsigned long idx) -{ - struct swap_cluster_info *ci = list_first_entry(&si->free_clusters, - struct swap_cluster_info, list); - - lockdep_assert_held(&si->lock); - lockdep_assert_held(&ci->lock); - VM_BUG_ON(cluster_index(si, ci) != idx); - VM_BUG_ON(ci->count); - list_del(&ci->list); - ci->flags = 0; - return ci; -} - static void free_cluster(struct swap_info_struct *si, struct swap_cluster_info *ci) { VM_BUG_ON(ci->count != 0); @@ -472,34 +458,24 @@ static void free_cluster(struct swap_info_struct *si, struct swap_cluster_info * } /* - * The cluster corresponding to page_nr will be used. The cluster will be - * removed from free cluster list and its usage counter will be increased by - * count. + * The cluster corresponding to page_nr will be used. The cluster will not be + * added to free cluster list and its usage counter will be increased by 1. + * Only used for initialization. */ -static void add_cluster_info_page(struct swap_info_struct *p, - struct swap_cluster_info *cluster_info, unsigned long page_nr, - unsigned long count) +static void inc_cluster_info_page(struct swap_info_struct *p, + struct swap_cluster_info *cluster_info, unsigned long page_nr) { unsigned long idx = page_nr / SWAPFILE_CLUSTER; - struct swap_cluster_info *ci = cluster_info + idx; + struct swap_cluster_info *ci; if (!cluster_info) return; - if (cluster_is_free(ci)) - alloc_cluster(p, idx); - VM_BUG_ON(ci->count + count > SWAPFILE_CLUSTER); - ci->count += count; -} + ci = cluster_info + idx; + ci->count++; -/* - * The cluster corresponding to page_nr will be used. The cluster will be - * removed from free cluster list and its usage counter will be increased by 1. - */ -static void inc_cluster_info_page(struct swap_info_struct *p, - struct swap_cluster_info *cluster_info, unsigned long page_nr) -{ - add_cluster_info_page(p, cluster_info, page_nr, 1); + VM_BUG_ON(ci->count > SWAPFILE_CLUSTER); + VM_BUG_ON(ci->flags); } /*