From patchwork Sun Nov 19 19:47:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460671 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 C6AC1C072A2 for ; Sun, 19 Nov 2023 19:48:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5305C6B03B2; Sun, 19 Nov 2023 14:48:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E14B6B03B7; Sun, 19 Nov 2023 14:48:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 381516B03B8; Sun, 19 Nov 2023 14:48:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 21F976B03B2 for ; Sun, 19 Nov 2023 14:48:54 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F0749C0857 for ; Sun, 19 Nov 2023 19:48:53 +0000 (UTC) X-FDA: 81475741746.12.7D8E8D9 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf25.hostedemail.com (Postfix) with ESMTP id 2A2D3A0017 for ; Sun, 19 Nov 2023 19:48:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i3P9BU+B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.181 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=1700423332; 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=aDkLnQICnVgpq4/orPONBtwFkKKcmzZtjb3XACAs/tw=; b=kr2TA+DKCF2iLdT5+eF8WH5hY+lvBroS/rNImEDz7bVLyJNsSEXT+aavZZmZ3o5dw8jDiS yagMR1CAEwOQDBmOsEEDMC9vr40mduB0vLn6QUnc2MMlw0UW8QLk7p7S2ReYewIyP3nmir CTsxI+xGTkHO0OkRtE8K1m7B4DGMdG0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i3P9BU+B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423332; a=rsa-sha256; cv=none; b=Ejamdyq62or8U3+MK7nTlhnFUTN0Gagpv6RLnjIgvntAjfXyLVIYCpA7p6biTXTDZGvGXX kQ7VKrR5JxRYyB8M0FqGDkMLbtD9nEgutan8Zo40r+3Jjt0KeTGGX7PMs9kksCB06XAH+Q A5I6tDS0QlL/0zJiefKjPOcyciOln8c= Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3b82541da51so247147b6e.0 for ; Sun, 19 Nov 2023 11:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423330; x=1701028130; 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=aDkLnQICnVgpq4/orPONBtwFkKKcmzZtjb3XACAs/tw=; b=i3P9BU+BbmO98WEYdtjSb647H5HHPK6t73M4UzpjEyQOnxOI4w4HIC/ySFVUmIVie8 LcyFMsD4HaoadIC9gYULjkaH15NoC0GyfR2Z09rYkyNIC6/PxJg4WSkVsMx9k9EEFBmH 4frNhqN8KLXwq1XhEmvEm92mrTY50aL/0wXrKRBwLcbs7lqkpFKNNla+DqiUD7MwnHk0 w3xFXrFPmphI1baCxrRwvLIYFwKuBxzb9q14nyV65+0idjK4gM3LGaC/9L0Ufw7bLNYN /A/z0b0gC4apLzK5/I393UMqDaKanaVnpPqCrL6m+LKOIy1QmUOXnhEDfqUmen5s3JuH 1VVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423330; x=1701028130; 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=aDkLnQICnVgpq4/orPONBtwFkKKcmzZtjb3XACAs/tw=; b=XnqKIOXJAMof4cHQdGT63yctkEAYQK1MbG7h/9c/qq6ZxibNAce5Y16aIC6lExNgwE wCWdIac2XQFOyFk9wDqIKjrS9wCsL3F8rkH2x3Ij8d7YvW8NA9X7S1xzEr64Qp7b36bg k4dBMu1AckHYFoLNK7BRg077HIgzXBqMnlpK4clQKUd7UGghDJy/owdoLsaVGyb9WzP4 NgHwLAfOOEW/Wn1ilym0CfWbWAcLCr3BsD2S82JvqWUHZ9zw+bdfLz0xRHINTFEff9eu +BNMmBP1F4MFaw6jnAxrEexad0tDfT6CV3eVou3tBpShWTUn7/CgqiNtZ9Z5gmpV3PMC 6pSg== X-Gm-Message-State: AOJu0Ywd+NPj5pjAJspy9Kg8yPIgEBV2HT4dUlRcP6xNw0x47jMqt9D+ GgfeOHIPgi45hrlmmTIdntDfZJUd9NmG+t8s X-Google-Smtp-Source: AGHT+IHnf4WdU+15DFAUt+1f+EUXMBC9sDjxOomJ4RYRSV1AA/+YKlySoWIJz9+C0DlwqbVhK6dXxQ== X-Received: by 2002:a05:6808:1452:b0:3af:983a:8129 with SMTP id x18-20020a056808145200b003af983a8129mr7743023oiv.53.1700423330257; Sun, 19 Nov 2023 11:48:50 -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.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:49 -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 15/24] mm/swap: avoid an duplicated swap cache lookup for SYNCHRONOUS_IO device Date: Mon, 20 Nov 2023 03:47:31 +0800 Message-ID: <20231119194740.94101-16-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: 2A2D3A0017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fyf5d8qmgskufczwmkyj885fw77s4j9o X-HE-Tag: 1700423331-404001 X-HE-Meta: U2FsdGVkX1+uW7pmOU40dSfISjoJ5mC5atf7bhJvvh0+wvxPu+1UxRe3pDa1CzdeueR6Errz7DDdGXUcI9pmmKpYbR6RjLVq8jScSZZgy7F+tY+oFu6ypwF67lhTheXIMG/FFjp3wVlJfj72uA6SFtNNAosh6iFpgGmy4punLPw/d8GDGivdg+rpvcE/IpF5VDEvQ4TODQUy1j33UbEOuHkF7XjKQgtC23WxTPSBn7aYLqbmFInlPQhndpKGOBLO0Q7jIGg4smLOMW5vH8uf8UQ0nU1tJksr+BLkwuvsPfKNwMA73PS/rJtlbZDdevipA+DDs+eVoS27/vESbXfEwR179jWwYiIbmwX7kQHjwmqvObi+agaC7bQXN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ew1QMP8gHMKRjGbtYm8eNxLXwsl9P4zNbmPBxt2iTsG6Cdb9b4PnLC+XLCuLQvZEldyIQ/HhATcWgCESE/+hRjA4dQnOIkten7FKzUTN0cuNNvQJXqsoEYLlqPoKKcI7JYLeSAa3FtUAvqZ45AnV8ZBl1Q3TLVQp3/llAnt5qTxZeL0EdV7DKOORnqpVI0B/duXfxQbTFVBEMnHBj7Fto= 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 When a xa_value is returned by the cache lookup, keep it to be used later for workingset refault check instead of doing the looking up again in swapin_no_readahead. This does have a side effect of making swapoff also triggers workingset check, but should be fine since swapoff does effect the workload in many ways already. Signed-off-by: Kairui Song --- mm/swap_state.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index e057c79fb06f..51de2a0412df 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -872,7 +872,6 @@ static struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, { struct folio *folio; struct page *page; - void *shadow = NULL; page = alloc_pages_mpol(gfp_mask, 0, mpol, ilx, numa_node_id()); folio = (struct folio *)page; @@ -888,10 +887,6 @@ static struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, mem_cgroup_swapin_uncharge_swap(entry); - shadow = get_shadow_from_swap_cache(entry); - if (shadow) - workingset_refault(folio, shadow); - folio_add_lru(folio); /* To provide entry to swap_readpage() */ @@ -922,11 +917,12 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, enum swap_cache_result cache_result; struct swap_info_struct *si; struct mempolicy *mpol; + void *shadow = NULL; struct folio *folio; struct page *page; pgoff_t ilx; - folio = swap_cache_get_folio(entry, vmf, NULL); + folio = swap_cache_get_folio(entry, vmf, &shadow); if (folio) { page = folio_file_page(folio, swp_offset(entry)); cache_result = SWAP_CACHE_HIT; @@ -938,6 +934,8 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, if (swap_use_no_readahead(si, swp_offset(entry))) { page = swapin_no_readahead(entry, gfp_mask, mpol, ilx, vmf->vma->vm_mm); cache_result = SWAP_CACHE_BYPASS; + if (shadow) + workingset_refault(page_folio(page), shadow); } else if (swap_use_vma_readahead(si)) { page = swap_vma_readahead(entry, gfp_mask, mpol, ilx, vmf); cache_result = SWAP_CACHE_MISS;