From patchwork Mon Jan 29 17:54:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13536160 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 3769EC48285 for ; Mon, 29 Jan 2024 17:55:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B5B46B0089; Mon, 29 Jan 2024 12:55:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 966336B008C; Mon, 29 Jan 2024 12:55:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DF056B008A; Mon, 29 Jan 2024 12:55:32 -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 699E66B0087 for ; Mon, 29 Jan 2024 12:55:32 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 392181402EE for ; Mon, 29 Jan 2024 17:55:32 +0000 (UTC) X-FDA: 81733100904.23.F41F5DF Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf02.hostedemail.com (Postfix) with ESMTP id 4D8B98001A for ; Mon, 29 Jan 2024 17:55:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KwBTVHiE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706550930; a=rsa-sha256; cv=none; b=IbwRF2paQzXT/k+cfxLePsLQJdAw0Y6yTD7WUyPC90wtca+ZJGiYXiq5o3+G70PDgNh5p5 pHpo7MWiZ2OqRNIPsn5BmyReixnvTTHeX3Im8b+beRox9ZULurx7BYjV+Npavyk/A55ONW 8iKYMcnOnt6kXtbIEYBZI08YOQV/BiY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KwBTVHiE; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.175 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=1706550930; 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=GjZwqrF+fUuAybg+YCS1CGFEH6Sivr26PLz3uMvjpFw=; b=XPBgDbqj7Eds1BN3LPBVXHpXoA+JZXz3EOaQz7rvAwBhaKSO+tM4nYdsd9GmaoGvUauB3o qrfGWswGq5SbjsnICj3D4jI2H9Nfds1UrdCAUOD3k9PMGefygtBU8wKdC8idsNbMkfor3Y KJvgfw9WmbI+qr+mcCDf6wBPpWdWXrE= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6de24201aa6so811331b3a.2 for ; Mon, 29 Jan 2024 09:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706550928; x=1707155728; 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=GjZwqrF+fUuAybg+YCS1CGFEH6Sivr26PLz3uMvjpFw=; b=KwBTVHiEZO1o+ntOJ4T5YYzY3sGLuxslUDnB79VzGSFfapMe9OrvloxnX48MWREB5x J6GFWIKH9PpGDbHLBt2L/LU2a6anw8U67QSkHWLEuKtQPtlZrbocjP4x+ppnzNAmSJhL E2la8sq8Z4eafomD8E+qdDnbSVdjTIxGEfrnr7uJtny0Qf4C1vMKx5LiftpLUPIdrfFM UTjAc2C82AZFxlaid5+dUiEKUtlNjyWLxAPWZiZ2NRIk9vjYydrEfuz7nchQ+jOR3BOt YjbJYb9hxhiRXSm8gYsyFmy6ss0G5du6ZHNKUn/GTj1y4kNbDpZWsnw29qe1jsQT5ael Pzng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706550928; x=1707155728; 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=GjZwqrF+fUuAybg+YCS1CGFEH6Sivr26PLz3uMvjpFw=; b=oqMS9mXtUe7MLRYo5ToCnpXTJvHDPjDVfgNjOifFGOvFt5pJr/vgrbX+AapZ4f2Ebr PVeyoqj4Y55B3pb1uO64Bmtq+PXdgWOcwNfSmlnKvKBCx3fDT04+B0Bm67p3C8hzluPt qf+vbe75GqnKRh3r+y8PnqshNb8ReTbXgA7qyf/DKAnvNyoXASjIBkr47ayRJW1iPb8b 4/dBYPPjOJNg86uoHT4CUkHtw+zWMDed3q0cI2uD0Uth+hAecxdqnXZIeu3xK604lDGW 1M/LX8MJsUHnG9tbqHD1hn6+WL3wGs90MqP41lhRSCt35wAeA87LHxcKTTFa49F5NEc1 1fdg== X-Gm-Message-State: AOJu0YyhCSYAxuq8zhHyvIZHigON1pntliZBTudurbMF4evbhYBy3n3S 511ih0c/68yo7bCrHoY6T/SJFYfc1serCFVJwNlEL8ou9nmO1HHe/gBBwku+Udy+WQ== X-Google-Smtp-Source: AGHT+IFDh6I0Kp5R4i/kVA2C7S+t5BD4PS3SEfvTVBoyIvP27FzIislYT+FaobErhwcJx+cp8D2QWA== X-Received: by 2002:a05:6a00:4fc4:b0:6dd:a24b:b5f3 with SMTP id le4-20020a056a004fc400b006dda24bb5f3mr5025963pfb.12.1706550928614; Mon, 29 Jan 2024 09:55:28 -0800 (PST) Received: from KASONG-MB2.tencent.com ([1.203.117.98]) by smtp.gmail.com with ESMTPSA id h8-20020aa79f48000000b006ddcadb1e2csm6116676pfr.29.2024.01.29.09.55.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jan 2024 09:55:28 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Chris Li , "Huang, Ying" , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v3 7/7] mm/swap: refactor swap_cache_get_folio Date: Tue, 30 Jan 2024 01:54:22 +0800 Message-ID: <20240129175423.1987-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129175423.1987-1-ryncsn@gmail.com> References: <20240129175423.1987-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4D8B98001A X-Stat-Signature: oossb7kdgmftimfkr8sacquyj7tgdoxo X-HE-Tag: 1706550930-899196 X-HE-Meta: U2FsdGVkX1/igfGVMao6wrf6iAKJk1MopvAdUc3xQdRWJI29FEqWZ8rV9/kQ7ft7dhKz8X2gi0w7nsFFssDtomuUtZjSwwUuonLpSKHP9pI7xS023hBeko/uJoXIrRyOt+A/U/ax2U1uQZSUelgItHzraDK95eZZHW7hK8t/kXaO4DIA/ZuCib1eAZ8mhBbx/oQ+wJuKAVB96nocHJujhtaFQ7jt/GS2ZcBcJuTX0iaSBux8ICb8toeFDuTxYQtFhxvevbeKyrns95HVYKVWGLCuY3Wmt/4PKnxBkwdk0kNFPoGzyhzFcRT68+A8OkKSz1qN31kvUnk7cBP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TPFI20y/b52E2zNA8p8OrN5Ml+gyd4HVO2DTyKAtnLyZn2ZFHr04xZl5/pq8nABmI9W+oQzByYA0lIFY8i6k9hsyuGCdql601JORqOrO1QkMbqccH/fSGTUD8SXpqN+SIsRUp1ymg7Zj0D5KrcW+CwzGO17frcP3l9HYlAW43BVI0L0tR4BYwa9gpEoEzLnDx5oBjvm+IjeXlHgFD1QWgZM2D4yYHgLerl7LzcCsZu3SJoPkCMvigmWO9oAY8CBo= 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 No feature change, change the code layout to reduce object size and kill redundant indent. With gcc 13.2.1: ./scripts/bloat-o-meter mm/swap_state.o.old mm/swap_state.o add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-35 (-35) Function old new delta swap_cache_get_folio 380 345 -35 Total: Before=8785, After=8750, chg -0.40% Signed-off-by: Kairui Song --- mm/swap_state.c | 59 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 20c206149be4..2f809b69b65a 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -341,9 +341,10 @@ static inline bool swap_use_vma_readahead(void) * * Caller must lock the swap device or hold a reference to keep it valid. */ -struct folio *swap_cache_get_folio(swp_entry_t entry, - struct vm_area_struct *vma, unsigned long addr, void **shadowp) +struct folio *swap_cache_get_folio(swp_entry_t entry, struct vm_area_struct *vma, + unsigned long addr, void **shadowp) { + bool vma_ra, readahead; struct folio *folio; folio = filemap_get_entry(swap_address_space(entry), swp_offset(entry)); @@ -352,37 +353,35 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, *shadowp = folio; return NULL; } + if (!folio) + return NULL; - if (folio) { - bool vma_ra = swap_use_vma_readahead(); - bool readahead; + /* + * 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; - /* - * 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 (vma && vma_ra) { - unsigned long ra_val; - int win, hits; - - ra_val = GET_SWAP_RA_VAL(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(&vma->swap_readahead_info, - SWAP_RA_VAL(addr, win, hits)); - } + vma_ra = swap_use_vma_readahead(); + readahead = folio_test_clear_readahead(folio); + if (vma && vma_ra) { + unsigned long ra_val; + int win, hits; + + ra_val = GET_SWAP_RA_VAL(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(&vma->swap_readahead_info, + SWAP_RA_VAL(addr, win, hits)); + } - if (readahead) { - count_vm_event(SWAP_RA_HIT); - if (!vma || !vma_ra) - atomic_inc(&swapin_readahead_hits); - } + if (readahead) { + count_vm_event(SWAP_RA_HIT); + if (!vma || !vma_ra) + atomic_inc(&swapin_readahead_hits); } return folio;