From patchwork Sun Nov 19 19:47:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460665 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 F1AF8C54FB9 for ; Sun, 19 Nov 2023 19:48:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83E826B038A; Sun, 19 Nov 2023 14:48:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C48E6B0393; Sun, 19 Nov 2023 14:48:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63F496B0397; Sun, 19 Nov 2023 14:48:35 -0500 (EST) 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 4C98E6B038A for ; Sun, 19 Nov 2023 14:48:35 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 29440B566B for ; Sun, 19 Nov 2023 19:48:35 +0000 (UTC) X-FDA: 81475740990.13.931DECD Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf08.hostedemail.com (Postfix) with ESMTP id 4EA18160003 for ; Sun, 19 Nov 2023 19:48:33 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GMAfQvcA; spf=pass (imf08.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700423313; h=from:from:sender:reply-to: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=7ikH9nPhVAiKzaSXcyZub9ryWf7e3smOr0BN4n2CRJU=; b=taFFVvCgxB/nipJIDsBqrcMCeV7E7vAm3wW+PdfCOiOZe8b+gplIM1T0Ce/+tiHuOQjVob 14W1Ithi+gcYeR7oOtavsi5AMF48G/1lp8n0r0I6qKxyEMc316fbEEEpbj1ZsNxZ0pSW92 gro9Da0tD5RpHFUZ+oq/2SJIRohfplk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423313; a=rsa-sha256; cv=none; b=KKo0EqaoKSSVZ3q0l1OhwD7TcYhFVk0SG5/qa+9ceeWpz3H7z+To75n/Bvu07bhzsxCQ8o itEq+fTnqHRgrbc2U9RZcxyZv/KPgzXj0u9jxSuRgJqCyC+DBCtjVeOAxybTuBO5CbeBtK hMDldrsxURRbllClARFj/rkuLRtDQ70= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GMAfQvcA; spf=pass (imf08.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6cb749044a2so844370b3a.0 for ; Sun, 19 Nov 2023 11:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423311; x=1701028111; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=7ikH9nPhVAiKzaSXcyZub9ryWf7e3smOr0BN4n2CRJU=; b=GMAfQvcA+JXERelm2lnYn6MGW6uAP+yRNulfhHZBJ0vuqbhJdsQwEavIgvDg/iY30k 7AdiKLuhgslGeb3+ix6ubWQHoXdAObOndo38lKLSg9qFMFEDWRYeyOBGy2gwiUuiUOez vKcUfsyi24Q9k/shQiI7Psax1vkaymtEwazLxIVj/biM9nrxOMQwyNBeKreDYHoYLp9h ouh1q/LIKjxbkbmxbQg3hMmmCra9u9ZPryP+EAh6wLklJjGcIgQEpY2U3PmfA8oQb/Ur uATNxSU6KeNcxrEBf5Xm59agiB5KKE2hzFMHv/+okg86lqdD88vCrvgHpZIGovRFrOCc SrHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423311; x=1701028111; h=content-transfer-encoding:mime-version:reply-to: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=7ikH9nPhVAiKzaSXcyZub9ryWf7e3smOr0BN4n2CRJU=; b=XNUbJZe/Ir/sT+HcTyZZQiZxOShRfH6tAfxyDYn/8Ty3ldjpvAM50EpYoB8kyKkFkR PvXSmhai9ybPZ98MxMUFsRJTE7n6NzAnCYcW5Yo+12oVHDcP4ApTKKPExCe70uOTuBaH AtLFJaK/QGlJhF9a2Pmh9a3+HXWiww/ujYYl++bBnX4o5R5dVSumWj8Ood4oSupQXN8N 8sE/ZhvnSKK8Y73yxDCP59UfFap4V4495mJP/w4P84oHwZqZxAPHu8l/gSkSKDfpdMsb 7WnNFJcDWPMoHarrFkrWswfut3yprnM4zUwE6t+ALeEc22/X4Alza03UcU8flVTeGz+4 EAUA== X-Gm-Message-State: AOJu0Ywtx0ANtSTbE7h+j+BIZJHKjNC+PXFWHnrNARDFP0WeHsYb3brL pckQHtkl2Shr6tg1zU2MJOe5rcjbff0zmPqV X-Google-Smtp-Source: AGHT+IH1zxFvtExW3yVn2ffiwyDes1ojQa3pxYWmcyzSBulOiTzqABkc4AI7t2dHHB2qRMn2sfkZdw== X-Received: by 2002:a05:6a20:552a:b0:188:1125:88bd with SMTP id ko42-20020a056a20552a00b00188112588bdmr6787703pzb.43.1700423311039; Sun, 19 Nov 2023 11:48:31 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.48.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:30 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 09/24] mm/swap: inline __swap_count Date: Mon, 20 Nov 2023 03:47:25 +0800 Message-ID: <20231119194740.94101-10-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: 4EA18160003 X-Rspam-User: X-Stat-Signature: 7nhcpeug1rx4oopkjdzseaozpmt4o3jt X-Rspamd-Server: rspam03 X-HE-Tag: 1700423313-579093 X-HE-Meta: U2FsdGVkX1/FYQ5CvjZ7M8m0OxR3WWrCqQd4uDOyV0qGDZLxvimJ+j7ivMkN+TMFHefTPlmCmjNpihNV13pB2AXtfm+5FO8i6w5SQGtDDdAh0nBCfEa1jfz7sJngDD9g9KovRz3dozFPLDuVedQoWEt6mlqlh/8Vt9faQI0yyhJYG/yom+D0QkzgCMqJkWNA0FWmNROkwLS2i+lNQHch6X94QgaDe2k42cniR4XMzU/nNHab4EYk9E51oe1lEfBZ8G6tjtpBN8A5XV9wdaQexJGgUUmEMJeGAvcIXHwlZDyI5TOFmuqDvDKcDJ6PeIeujY283BHEZxxx1LEwH6K5vz/m50a28cOzSJHzdL8ct+7s8sHQB9SFjWPTh/8QlxT8jw6tjEdAh1+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x2Dmti7ztugdwFEziuSMbwvrWqJUfKvmW5QEU0RclAWaNCinWK/BFca9Ce2K1XUCGC3O2DnKJVAZ9TUrUsdzavcORc0dq0AYv9wpAm/oqs/WaTOMwIdfCrIMbnrA8jOwReIyqvFNJ7s1qojEUK3lXDjpHH0xLaDfA099XC6+TISO1IH4wS0aMgzJDWvLLYCMhP/s5NVeFDtQg= 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 There is only one caller in swap subsystem now, where it can be inline smoothly, avoid the memory access and function call overheads. Signed-off-by: Kairui Song --- include/linux/swap.h | 6 ------ mm/swap_state.c | 6 +++--- mm/swapfile.c | 8 -------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 2401990d954d..64a37819a9b3 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -485,7 +485,6 @@ int swap_type_of(dev_t device, sector_t offset); int find_first_swap(dev_t *device); extern unsigned int count_swap_pages(int, int); extern sector_t swapdev_block(int, pgoff_t); -extern int __swap_count(swp_entry_t entry); extern int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry); extern int swp_swapcount(swp_entry_t entry); extern struct swap_info_struct *page_swap_info(struct page *); @@ -559,11 +558,6 @@ static inline void put_swap_folio(struct folio *folio, swp_entry_t swp) { } -static inline int __swap_count(swp_entry_t entry) -{ - return 0; -} - static inline int swap_swapcount(struct swap_info_struct *si, swp_entry_t entry) { return 0; diff --git a/mm/swap_state.c b/mm/swap_state.c index fb78f7f18ed7..d87c20f9f7ec 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -316,9 +316,9 @@ void free_pages_and_swap_cache(struct encoded_page **pages, int nr) release_pages(pages, nr); } -static inline bool swap_use_no_readahead(struct swap_info_struct *si, swp_entry_t entry) +static inline bool swap_use_no_readahead(struct swap_info_struct *si, pgoff_t offset) { - return data_race(si->flags & SWP_SYNCHRONOUS_IO) && __swap_count(entry) == 1; + return data_race(si->flags & SWP_SYNCHRONOUS_IO) && swap_count(si->swap_map[offset]) == 1; } static inline bool swap_use_vma_readahead(struct swap_info_struct *si) @@ -928,7 +928,7 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, si = swp_swap_info(entry); mpol = get_vma_policy(vmf->vma, vmf->address, 0, &ilx); - if (swap_use_no_readahead(si, entry)) { + if (swap_use_no_readahead(si, swp_offset(entry))) { page = swapin_no_readahead(entry, gfp_mask, mpol, ilx, vmf->vma->vm_mm); cached = false; } else if (swap_use_vma_readahead(si)) { diff --git a/mm/swapfile.c b/mm/swapfile.c index a8ae472ed2b6..e15a6c464a38 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1431,14 +1431,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n) spin_unlock(&p->lock); } -int __swap_count(swp_entry_t entry) -{ - struct swap_info_struct *si = swp_swap_info(entry); - pgoff_t offset = swp_offset(entry); - - return swap_count(si->swap_map[offset]); -} - /* * How many references to @entry are currently swapped out? * This does not give an exact answer when swap count is continued,