From patchwork Sun Nov 19 19:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460670 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 5317EC072A2 for ; Sun, 19 Nov 2023 19:48:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D94A46B03B0; Sun, 19 Nov 2023 14:48:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D47876B03B2; Sun, 19 Nov 2023 14:48:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBF4A6B03B4; Sun, 19 Nov 2023 14:48:50 -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 A28FA6B03B0 for ; Sun, 19 Nov 2023 14:48:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 814331604AB for ; Sun, 19 Nov 2023 19:48:50 +0000 (UTC) X-FDA: 81475741620.02.E96AF62 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf17.hostedemail.com (Postfix) with ESMTP id A533040015 for ; Sun, 19 Nov 2023 19:48:48 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HMb+JZrX; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423328; a=rsa-sha256; cv=none; b=Yb6elLmDg7sivP8BjAytYy4XzN7Yf0MHE0CE7vPHqEOjMlovcwERis8HAk4Htef4hzI8KA nOcnLCgw/JgmmbpXLqoBn84rcO7dWldRFCx5DC7hxpgf/IQbttfzEXGsO1w76xVJZxZq/w vDfF0Fb6PyBwpN2RSUcS20UJ0g8kR48= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HMb+JZrX; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.181 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=1700423328; 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=VCznjXM2MgFt7+7dcBajlWUiOZC/KHYcLFwrnZNwV5s=; b=pjPVpe0c/2YaLNs92emheMZHVFJOYu0pKW4B60fr1g3F/of645D4CODswBw/HhB4J8nFah dLxwgamWaUzm5MuwFqHCyz5phING9VKGZy158dy8RHsUf5MRQpQT8T9Gk81V4Mb3ScArru wc0FaxCM19ZYNanQHNRacqYkHNzt4Bg= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6b87c1edfd5so2937469b3a.1 for ; Sun, 19 Nov 2023 11:48:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423327; x=1701028127; 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=VCznjXM2MgFt7+7dcBajlWUiOZC/KHYcLFwrnZNwV5s=; b=HMb+JZrXF3g+4usYeBAhQzCqYrX287F4RNuntWEMs9YgikCIWXO7xRKmzVZCoWgyUo zWQ+gLWg7XE0YxM+H0AkN6zo8JSvyDLbGHbhfEHjl7/Cif2tmiP3GfXJNgawbumomRyD QgyNpz4GKIxGCesDxV3V4dVkqNMfqdWpHdc082+zrKCsRdllaJJo3/T5a9XWMWZPMGRt nTJFXXnvyE1NU5OU4JfkToXDdv2TBJfnlI95/qvkY+f6Qp9fMZuKcnJRbCXyzyLfj9CF JZav1BmeEu5ci0kPhGrEr5BVA8YlWRZYoxx2PpmENdNXFflrCXpnwu0akTh/2sw8AxKn 6pCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423327; x=1701028127; 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=VCznjXM2MgFt7+7dcBajlWUiOZC/KHYcLFwrnZNwV5s=; b=pWA1Jkfnqk9BgvM4k9+AguIqL5a7wY2lnn8ASlA/PVk5HdwbJCeh/Rdi4tBQb5YevH BygdDTWejxeNcMm6P98rlFgfbbJ3c/qFUHZeL352WkMq+M8gdN2O6BM6pbefoo9DzoCb Ik058Y1bxy/d5/MvK99VTMM132BBdAAXYcimXcXa747ziHlPNsUv8EsnWWsAGKwLvqjE G5G4uiatjG1tDAkZNL+aMv9Dc5RKE5lq0NZCY65cz9FvdmN84/BQU6N36VCRzj0LJJuH XFGJbtMJ6gsMYXNJ49rt10FBSnry76fg/Cxa/3F7OwvzcPHvjR/fQVeRtd2wOIqiCrVq eVqA== X-Gm-Message-State: AOJu0YxNUKsN6D5VcSGLfnsSReffVBJ8QCl/7Uyu268dcHTQfETyFeW3 e7xxcZwPE6ZZM1CArjstHtFvmSm7uiIVqor3 X-Google-Smtp-Source: AGHT+IGzuAUevQ1XHN3DEflD4nhrPqC3JAr2xo9JJHGah1/1WAAz1GSa8PG8e1ODtV8IMaqzQtkuzA== X-Received: by 2002:a05:6a20:6a1a:b0:189:df1b:6616 with SMTP id p26-20020a056a206a1a00b00189df1b6616mr3107739pzk.15.1700423327040; Sun, 19 Nov 2023 11:48:47 -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.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:46 -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 14/24] mm/swap: do shadow lookup as well when doing swap cache lookup Date: Mon, 20 Nov 2023 03:47:30 +0800 Message-ID: <20231119194740.94101-15-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-Server: rspam08 X-Rspamd-Queue-Id: A533040015 X-Stat-Signature: xrx15ighfwztuh1gtw9c989f1etmd9xj X-Rspam-User: X-HE-Tag: 1700423328-29164 X-HE-Meta: U2FsdGVkX1+LvPGWWRt+ToAake2Wauxhqnwkr1XPzDIsM+espNzsjLl9/hhxxPSuoLcBcuJ3QuE4WwTIvYf++DWRxcOaubFSuavA6KMIwxEtf+UwBxVi3+xnVcoQdVSMJa0wqO5oUJW0+18R5xg5tsfummzOvG4NXNAFqEmbxqVVuVWYp7zLb38nP97Y7HeRPjAG8UuuUt7Vb6T01m/9XhK3hKkyriZLCimViSWs0GmQPUs6SnO89wpinQ7hY8tWXHTatlG/Dkv5bPlcCXxW+GWPWLCuxJtwLe4UgFnkggOVC/PqCcEMgiZ0RsjH1gRV3usfDPMPB07OmpieZcYvKd/ZQHJEfSh6RM3XsDI5lkTTs4EcSvtqLxhfF3m/LhRwTtm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AAtLVnj8aeYjg6Mro+TXl/pSXPuurG4xlkv+uRYkT9A0M6uARz6TEYW9mNhYMN8lbheFWw8vmcphb2KwveTXsMOjKVVLuCXG9fYLFO257qOHED1tCdpXtdkLMFSpyyFbTebgnvB8rMfyZsdMrf1bG+7e4wZi7mRy+CgkkZnO9xp2uZnwLzYo/ 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 Make swap_cache_get_folio capable of returning the shadow value when the xarray contains a shadow instead of a valid folio. Just extend the arguments to be used later. Signed-off-by: Kairui Song --- mm/shmem.c | 2 +- mm/swap.h | 2 +- mm/swap_state.c | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 72239061c655..f9ce4067c742 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1875,7 +1875,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, } /* Look it up and read it in.. */ - folio = swap_cache_get_folio(swap, NULL); + folio = swap_cache_get_folio(swap, NULL, NULL); if (!folio) { /* Or update major stats only when swapin succeeds?? */ if (fault_type) { diff --git a/mm/swap.h b/mm/swap.h index e43e965f123f..da9deb5ba37d 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -47,7 +47,7 @@ void delete_from_swap_cache(struct folio *folio); void clear_shadow_from_swap_cache(int type, unsigned long begin, unsigned long end); struct folio *swap_cache_get_folio(swp_entry_t entry, - struct vm_fault *vmf); + struct vm_fault *vmf, void **shadowp); struct folio *filemap_get_incore_folio(struct address_space *mapping, pgoff_t index); diff --git a/mm/swap_state.c b/mm/swap_state.c index 3b5a34f47192..e057c79fb06f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -334,14 +334,17 @@ static inline bool swap_use_vma_readahead(struct swap_info_struct *si) * * 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_fault *vmf) +struct folio *swap_cache_get_folio(swp_entry_t entry, struct vm_fault *vmf, void **shadowp) { bool vma_ra, readahead; struct folio *folio; - folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); - if (IS_ERR(folio)) + folio = filemap_get_entry(swap_address_space(entry), swp_offset(entry)); + if (xa_is_value(folio)) { + if (shadowp) + *shadowp = folio; return NULL; + } /* * At the moment, we don't support PG_readahead for anon THP @@ -923,7 +926,7 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, struct page *page; pgoff_t ilx; - folio = swap_cache_get_folio(entry, vmf); + folio = swap_cache_get_folio(entry, vmf, NULL); if (folio) { page = folio_file_page(folio, swp_offset(entry)); cache_result = SWAP_CACHE_HIT;