From patchwork Sun Nov 19 19:47:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460669 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 ED4A4C072A2 for ; Sun, 19 Nov 2023 19:48:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CC236B03A7; Sun, 19 Nov 2023 14:48:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 729036B03B0; Sun, 19 Nov 2023 14:48:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5567E6B03B1; Sun, 19 Nov 2023 14:48:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 410B66B03A7 for ; Sun, 19 Nov 2023 14:48:47 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1E7E11CB236 for ; Sun, 19 Nov 2023 19:48:47 +0000 (UTC) X-FDA: 81475741494.22.E65E18F Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) by imf22.hostedemail.com (Postfix) with ESMTP id 4FE11C001B for ; Sun, 19 Nov 2023 19:48:45 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pu5CZpKo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700423325; 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=5hBTip8l+rVWgXZvgeAFfyX4NMH7GqXDBsHUYVWi3uA=; b=JCrHNN1cnGhYB2Vom8BrPL61jz4MJw8Ih9D376b8w4578jh8dFDEQhzkf5caK4EdJ32lVx 9Y+v7PsXndLLCPEe7detv2Bnj4kpA8jKQt+z0UEaOM38oqTNI/LLxh4W2YW2kAA9jTKntD 7/2o5agVOjk3q4LdaQrqLnz9+d9LVdQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Pu5CZpKo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.180 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423325; a=rsa-sha256; cv=none; b=4feeOrP/GoYqIGZL/Hp47H0E9o6vZx5AjZ10wdde1OmkCNP4L7P587fNGsOCpqPybEUFDy dw1LrCbooXwLc/QNuuw+krsJ98uUxz+V3lnNQc8bW2qCJvP5HUbIyVlXIsu8zmg8i/zDAj 9hhTD8O9aEFGfLdH8937mCIe0m2W6j0= Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3b6cb515917so2618926b6e.1 for ; Sun, 19 Nov 2023 11:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423324; x=1701028124; 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=5hBTip8l+rVWgXZvgeAFfyX4NMH7GqXDBsHUYVWi3uA=; b=Pu5CZpKoZVmVvD6+nTbfGEPKYpWY0tf9vztZzPZVKCTbQ3WByAvb/xyVYid1WsyOhE KjkT/CKSOdeoqlyLoIWP1IJYrKg4GEITYUgLrrdMUOFSrWOxPv/hpzp1TYKIrw6a1rss k9c8ce1A/886i2WTeZRg3DfCVKtrlNsf2mvqzH662CBqk6YLLZ/AwgnIvb4pn+JIF0We 3rbPzyJAT7YZt1tT6LIHlO0edwUDTkuk2so57BZ1vU/2u+luL3Lt5UAXKpKg1iHuOs2L ZuO/lKUvS+5DsT1GkEQZ8Z5C5wKx4QgmdLnWyznmjX26VtBbQ7HgRV/jtMRY2KxndF4Q Da2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423324; x=1701028124; 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=5hBTip8l+rVWgXZvgeAFfyX4NMH7GqXDBsHUYVWi3uA=; b=KhjplqRIW8v3+MaRDTG0JQMN6tsM//t1/SCmzz2jGM4O84HuMkpWe7zja+YYZfRZvX /XutQQiiVqrLqZL9EBvFCOjnj1GJY5cU9qjmH4kaOzR/nj0P9VCErpvMT8ZTAAK4jbDv /bAB8NjRJAK4fJfgUVyTlVxusQfbUHsw3d5qALPyq4yKPARzYDzMhfdEaPHM2US0ODc3 3bq3Hw8ydnf/fVAAjwyy+tVLYSNMZom9K21knKkrPa4kJyWtBwdP6an7Hej1MlS16A80 j8ojFce1V07fObkc33B1Ua5T5aZZ7d6PG6vSHLjP6YHbOqC5KK5UnJRChJnk07Rdtxs7 K9QA== X-Gm-Message-State: AOJu0YxRnk/pIpcQmoRlssKpWasps6GncAKv5C7uwdhiNIwbOiVes+Zt JtBtiU4y0NJ8c9vO2I1ZO7pgKx/AzI9l4gVs X-Google-Smtp-Source: AGHT+IEailrfhPaQZQEKYeEqmxWit7bC+nmAWDqCtHjGUNXtOgvTTA/qDqxaYEq3DlyE+hI13556Tg== X-Received: by 2002:a05:6808:3a10:b0:3ae:bae2:fa76 with SMTP id gr16-20020a0568083a1000b003aebae2fa76mr10473632oib.36.1700423323924; Sun, 19 Nov 2023 11:48:43 -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.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:43 -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 13/24] swap: simplify swap_cache_get_folio Date: Mon, 20 Nov 2023 03:47:29 +0800 Message-ID: <20231119194740.94101-14-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4FE11C001B X-Stat-Signature: 8sbrk7w8mjb1346hrwphop5sg3q5mdpu X-HE-Tag: 1700423325-467313 X-HE-Meta: U2FsdGVkX18pnlissI5iy6v1dS5iIwhuqDzypkp5iOZrAyBUWL9SJrV0lYylHd3UiX7+S2is5rhdp+X8bK6dAxrMwL2q94BeKiLpBQbtCMQyEFp0eRjoLJ18NDiJOicr7XVkVIz6LD3WkW/JcDih/g+rz2s8lxV+7YzivCtHTf3P3N2m9lhzwFSWDtJHBEBgsTRFuDOWxAhkyRIIldgnIJ3t7DtW2nNVRoI64v8NreVIFtQ7WctZRoJE/wrpl3G8QU7HdWonYvR9e+Ej9CRRQxvP+Q9Tly6fXKnGaF+AsOs7CQwTOjWN+5Ku36JQkTd/RvK/QfvI7LljMrXOFbcZbTliBZqcFsOhJRaQVF4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Z0WZulEFGGuOQoT0tBynnjzHZ/xjKMxPTsYozWF73ADMVAEJe848Pvfi1rs8R+a+/OMNoKvWNmQ+Al53mD+bgmuFl4Z8rxE7A4QGeTzXS9ulvlv6UkQd0U6VCbWtZEeKwHdukMDCc8RwLvclX/5Di86auBesc0MCg97JyZgWp2ATzMq3LeumXsfI2AO7Cqrk6bImqs4L2xv2Tm2q/eWYTQPeSNEJQjFmisxU0/L/f1NXk= 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 Rearrange the if statement, reduce the code indent, no feature change. Signed-off-by: Kairui Song --- mm/swap_state.c | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 91461e26a8cc..3b5a34f47192 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -336,41 +336,39 @@ static inline bool swap_use_vma_readahead(struct swap_info_struct *si) */ struct folio *swap_cache_get_folio(swp_entry_t entry, struct vm_fault *vmf) { + bool vma_ra, readahead; struct folio *folio; folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); - if (!IS_ERR(folio)) { - bool vma_ra = swap_use_vma_readahead(swp_swap_info(entry)); - bool readahead; + if (IS_ERR(folio)) + return NULL; - /* - * At the moment, we don't support PG_readahead for anon THP - * so let's bail out rather than confusing the readahead stat. - */ - if (unlikely(folio_test_large(folio))) - return folio; - - readahead = folio_test_clear_readahead(folio); - if (vmf && vma_ra) { - unsigned long ra_val; - int win, hits; - - ra_val = GET_SWAP_RA_VAL(vmf->vma); - win = SWAP_RA_WIN(ra_val); - hits = SWAP_RA_HITS(ra_val); - if (readahead) - hits = min_t(int, hits + 1, SWAP_RA_HITS_MAX); - atomic_long_set(&vmf->vma->swap_readahead_info, - SWAP_RA_VAL(vmf->address, win, hits)); - } + /* + * At the moment, we don't support PG_readahead for anon THP + * so let's bail out rather than confusing the readahead stat. + */ + if (unlikely(folio_test_large(folio))) + return folio; - if (readahead) { - count_vm_event(SWAP_RA_HIT); - if (!vmf || !vma_ra) - atomic_inc(&swapin_readahead_hits); - } - } else { - folio = NULL; + vma_ra = swap_use_vma_readahead(swp_swap_info(entry)); + readahead = folio_test_clear_readahead(folio); + if (vmf && vma_ra) { + unsigned long ra_val; + int win, hits; + + ra_val = GET_SWAP_RA_VAL(vmf->vma); + win = SWAP_RA_WIN(ra_val); + hits = SWAP_RA_HITS(ra_val); + if (readahead) + hits = min_t(int, hits + 1, SWAP_RA_HITS_MAX); + atomic_long_set(&vmf->vma->swap_readahead_info, + SWAP_RA_VAL(vmf->address, win, hits)); + } + + if (readahead) { + count_vm_event(SWAP_RA_HIT); + if (!vmf || !vma_ra) + atomic_inc(&swapin_readahead_hits); } return folio;