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 CFAC6ECAAD5 for ; Fri, 2 Sep 2022 19:47:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B7E9800E9; Fri, 2 Sep 2022 15:47:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16768800EA; Fri, 2 Sep 2022 15:47:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00836800E9; Fri, 2 Sep 2022 15:46:59 -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 E64D7800DD for ; Fri, 2 Sep 2022 15:46:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B874380580 for ; Fri, 2 Sep 2022 19:46:59 +0000 (UTC) X-FDA: 79868178558.09.DD40B1B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 0AEF020055 for ; Fri, 2 Sep 2022 19:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=rZ9tiYok3CmkdoKC4u5YlyBJYtd4IGvFvqCkTZC9NJA=; b=NLAaWMQ3kbvkMLsNmzgQY/1ZZ3 jDprBftjPzcJ4/jZsFohyU9o8k/lGo6qmREWhgjd8OHxAhW+uqd1XjZfd2ZGYjKf5ee/eK/yUL0sK LjaE+iFT4SgcldJx0kYAe5ESWNLetyvaVNf7gYL02nuZdg3ACoUp2hbRM1tBDBir6PYKy/uUdkAEx 6ADo61JdA+t5Dx6F3KbP3PQ1QqmO1qDmzNFFWlqrH51T4jhRYtEgZXQNRHC4ZY2AEQgsEHcB1M4x6 sjDkBP4Gx8fk8ARFRNaBAwJTpIcUuxVDspjlYqhNu/TSl+8ppQqLqgHFYbRTgv22L0FdPazOZaYCv 7TeQaFSQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oUCd0-007Ibt-LG; Fri, 02 Sep 2022 19:46:58 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 09/57] mm/swapfile: Remove page_swapcount() Date: Fri, 2 Sep 2022 20:46:05 +0100 Message-Id: <20220902194653.1739778-10-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220902194653.1739778-1-willy@infradead.org> References: <20220902194653.1739778-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662148019; 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=rZ9tiYok3CmkdoKC4u5YlyBJYtd4IGvFvqCkTZC9NJA=; b=hL+maF08M280zrdPIgMoHq8XRfEKzeWmj8A58eI/wMfpW94hCkIJfBcS4GrJNe+sZTNzVF x2NBoSCR6mH335Hr+Wf3ZVB4hKiQmS7vJJfy3H4OT4vtGOXTmc30psd0ENLrVWbLrcWG3H SSUParU10Z4klhX57Rg3YK5ndZzeZXE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NLAaWMQ3; dmarc=none; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662148019; a=rsa-sha256; cv=none; b=XS7KqZjP2BS6oUZFnIRyrLyTtXB3M4fHGvblZEEoxENE3tX5Wj84NBP49CHQ/n92NK/lwf jdTFxPTWaoMtwpO9SPh1Y2179AKqqNI+0h1svW+s7Z9Bv233QM1vji68mnDqPx75ccSD2O YKSk6J5fEicNnbnssUJZnXI9sKTRczg= X-Rspamd-Queue-Id: 0AEF020055 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NLAaWMQ3; dmarc=none; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: r84s8qejq3wx3t3r3d19c6oj49zs8sih X-HE-Tag: 1662148018-706935 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: By restructuring folio_swapped(), it can use swap_swapcount() instead of page_swapcount(). It's even a little more efficient. Signed-off-by: Matthew Wilcox (Oracle) --- mm/swapfile.c | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 1fdccd2f1422..c042fd71de02 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1427,30 +1427,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n) spin_unlock(&p->lock); } -/* - * How many references to page are currently swapped out? - * This does not give an exact answer when swap count is continued, - * but does include the high COUNT_CONTINUED flag to allow for that. - */ -static int page_swapcount(struct page *page) -{ - int count = 0; - struct swap_info_struct *p; - struct swap_cluster_info *ci; - swp_entry_t entry; - unsigned long offset; - - entry.val = page_private(page); - p = _swap_info_get(entry); - if (p) { - offset = swp_offset(entry); - ci = lock_cluster_or_swap_info(p, offset); - count = swap_count(p->swap_map[offset]); - unlock_cluster_or_swap_info(p, ci); - } - return count; -} - int __swap_count(swp_entry_t entry) { struct swap_info_struct *si; @@ -1465,11 +1441,16 @@ int __swap_count(swp_entry_t entry) return count; } +/* + * How many references to @entry are currently swapped out? + * This does not give an exact answer when swap count is continued, + * but does include the high COUNT_CONTINUED flag to allow for that. + */ static int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry) { - int count = 0; pgoff_t offset = swp_offset(entry); struct swap_cluster_info *ci; + int count; ci = lock_cluster_or_swap_info(si, offset); count = swap_count(si->swap_map[offset]); @@ -1570,17 +1551,16 @@ static bool swap_page_trans_huge_swapped(struct swap_info_struct *si, static bool folio_swapped(struct folio *folio) { - swp_entry_t entry; - struct swap_info_struct *si; + swp_entry_t entry = folio_swap_entry(folio); + struct swap_info_struct *si = _swap_info_get(entry); + + if (!si) + return false; if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio))) - return page_swapcount(&folio->page) != 0; + return swap_swapcount(si, entry) != 0; - entry = folio_swap_entry(folio); - si = _swap_info_get(entry); - if (si) - return swap_page_trans_huge_swapped(si, entry); - return false; + return swap_page_trans_huge_swapped(si, entry); } /* -- 2.35.1