From patchwork Tue Mar 26 18:50:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13604896 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 58143C6FD1F for ; Tue, 26 Mar 2024 19:04:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFBEA6B0093; Tue, 26 Mar 2024 15:04:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D853F6B0095; Tue, 26 Mar 2024 15:04:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB20D6B0096; Tue, 26 Mar 2024 15:04:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 973126B0093 for ; Tue, 26 Mar 2024 15:04:33 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 72A131407E9 for ; Tue, 26 Mar 2024 19:04:33 +0000 (UTC) X-FDA: 81940116426.11.2EA13E8 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf06.hostedemail.com (Postfix) with ESMTP id 95DF3180028 for ; Tue, 26 Mar 2024 19:04:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nNKo5Ota; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.169 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=1711479871; 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=TEv2cY48RN4zMeEfANN3o0TZbotXcFB0DQsGIzjU7dM=; b=udvZKPwDXBdJ3VD/s/rydgq5PJjPSCpYIVWBynIPY/hmroSrPtFZ5skpy33FQCUFEpWyFk MU3F4PlTJphyPAERqOrm4h/JOX/kJn0AgxTW5yjH2jNaCAQPI45t0scDMN+yHMCmZgXKwp KqClioCjC9R649kMlBI31ayczrg2LU0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711479871; a=rsa-sha256; cv=none; b=CUN5NpSCTpqkm/jQwaTFuedrOkjd5zC+JyXVjbQhkOYsFRLQ8yDxe17H2ibVrwrieeE+hu Sak+NsSl0piNyrND7K/9nOM65bAjHyCUFm/pslORUoILuqHRn1tEffqbD9Awj4qTpDJQud v4frk15qyX56UoS0G1V+UWKHgr3FA1M= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nNKo5Ota; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5dbd519bde6so3466422a12.1 for ; Tue, 26 Mar 2024 12:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711479870; x=1712084670; 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=TEv2cY48RN4zMeEfANN3o0TZbotXcFB0DQsGIzjU7dM=; b=nNKo5OtaY9YALhTnCmO0YXvYCxDg0kHaPLtZ+yHAQ67g3UafjovXB21HhckcZ1u8+I JB7EdboJbBj3Kw9r0X7TS0eXTcQP0EAUZAewzgT3GYzlJqxGEkksmRRyDQ7aUJVUGfUR 6cvks8bhbxj8yttpjGMgyVltG4v1etuIjFtiJl4kcy5S2U9Dfum/FuaVmYlW8cpUOrbz mqlvR8l8AdPhiwgw+fgESN75juaM4YcCAohV/A6MqxfwEW+9zIt4HKhVFMc4hpc/54sM 2ENiHWAqJenejKI3/c3i/UzbjMLVMniYCh3K+iS8mLMX3yMbGXoGOoCmj1sAw7v4v8ah dYAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711479870; x=1712084670; 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=TEv2cY48RN4zMeEfANN3o0TZbotXcFB0DQsGIzjU7dM=; b=FjpoBtf8+j4sEW2tZw8zfQE8z+/uIse9bSDycovywfH78de2PK7fk65JGX/pghwIYK UoLKLvW7xlzrgHRzTakW1ZqhFGmzhV9N7Xb3HxfomgZ7Kuc2/BsN8+/lzGnj7eBSE+2U LLXuqTCrq2sKBQLi44KVxWgMbJ/kEVUS4wLpfcUqu6rOly6YOLZU7MZIXo/p4IJKjtBv V4e+W5PyXKMopxLYi9Si7EgD5mMMIkv76Yb3r/UcMA36HkxHWKmZkSrGr1ep3QRt2Zm+ xSrZHF2W7TULB6VMTajB7kJ7bjKY79s0+UJI2vycQgr3sHbjA3UGOwc4HvkwkSLbfKMd bv5g== X-Gm-Message-State: AOJu0Yy+74VW8CIkmo+uw/8TRrMBhx5ZHIwjj81RIkURtJLR8YVL3OVH Sb7M3rMz6fkuwPQnZcTQ17W4TmwIHRGKQj/PhOYFYM13WDlETCCUiC9Z5IIvtK6kS8Xo X-Google-Smtp-Source: AGHT+IEzVu/grUxN8VT3A2w/EHOVk9Am7cvRif7ZTTWBWxDgt7/3PIqhlTfiumnGRYgPCPyofkcdEA== X-Received: by 2002:a05:6a21:398c:b0:1a3:dcdf:13cf with SMTP id ad12-20020a056a21398c00b001a3dcdf13cfmr2102446pzc.56.1711479869865; Tue, 26 Mar 2024 12:04:29 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([115.171.40.106]) by smtp.gmail.com with ESMTPSA id j14-20020aa783ce000000b006ea790c2232sm6298350pfn.79.2024.03.26.12.04.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 26 Mar 2024 12:04:29 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: "Huang, Ying" , Chris Li , Minchan Kim , Barry Song , Ryan Roberts , Yu Zhao , SeongJae Park , David Hildenbrand , Yosry Ahmed , Johannes Weiner , Matthew Wilcox , Nhat Pham , Chengming Zhou , Andrew Morton , linux-kernel@vger.kernel.org, Kairui Song Subject: [RFC PATCH 03/10] mm/swap: convert swapin_readahead to return a folio Date: Wed, 27 Mar 2024 02:50:25 +0800 Message-ID: <20240326185032.72159-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326185032.72159-1-ryncsn@gmail.com> References: <20240326185032.72159-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Queue-Id: 95DF3180028 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 596zjo4737pj9mqo34j4oyd897cznbf7 X-HE-Tag: 1711479871-406997 X-HE-Meta: U2FsdGVkX1+/E25qVPPaSoPbBnJWCyzYGZAuLpOV30OFBjOJ18a+GDBTlCqcJs6SFjn/Kg7ZZ1b+zX8ReLohkVV4mMkdUu+AvSSfG0vgf97o/RhyWgKZfNODGpMGnp5Va0trFgWWxtHeK9MCSLP0oc08SKgynUM6XrtONVqTaf8UtozofTMrt/XiUiydT/r5LZF9Wm9alhv4rNX9BIJ5mWD5JEALX7nXx1mgqHt6mnO1dmFN3EQE1CCYe44IfAo/uQ/RHsfGO1rM2ueFiOcY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kyfApslOyc6EmIoH+uB3pLV1JxfzacXJIqb0nxMX4n6OoliMlVS23P0PDm1GCb9dp0y/wjaF5p1yQFD8XAt0vpevYLwhytti6Ow7ZsOOyWx+wi2jvDWllH8GyGJure9AYamS+pdJWQnLvW/tw1N27TS5NpJKhZjGrKyje250w++28oh65/2XH3l7bijAh2B61oT/59ewoK6hDK5l9qN83h4yktsiq7d5EEAy8XLmYcvJr/v8qyi3CDsiPrSTw0SFpfoGLhWiODnCdE67WETMFgc/bB3CVnag0Z71ndoncOqZD4zUIl3OC6FnVpzTFBXoW8M= 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 Simplify the caller code logic. Signed-off-by: Kairui Song Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 8 +++----- mm/swap.h | 4 ++-- mm/swap_state.c | 6 ++---- mm/swapfile.c | 5 +---- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index e42fadc25268..dfdb620a9123 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4005,12 +4005,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (PTR_ERR(folio) == -EBUSY) goto out; need_clear_cache = true; - page = &folio->page; } else { - page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, - vmf); - if (page) - folio = page_folio(page); + folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf); swapcache = folio; } @@ -4027,6 +4023,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto unlock; } + page = folio_file_page(folio, swp_offset(entry)); + /* Had to read the page from swap area: Major fault */ ret = VM_FAULT_MAJOR; count_vm_event(PGMAJFAULT); diff --git a/mm/swap.h b/mm/swap.h index 40e902812cc5..aee134907a70 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -57,7 +57,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag, struct mempolicy *mpol, pgoff_t ilx); struct folio *swapin_direct(swp_entry_t entry, gfp_t flag, struct vm_fault *vmf); -struct page *swapin_readahead(swp_entry_t entry, gfp_t flag, +struct folio *swapin_readahead(swp_entry_t entry, gfp_t flag, struct vm_fault *vmf); static inline unsigned int folio_swap_flags(struct folio *folio) @@ -95,7 +95,7 @@ static inline struct folio *swapin_direct(swp_entry_t entry, gfp_t flag, return NULL; } -static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask, +static inline struct folio *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask, struct vm_fault *vmf) { return NULL; diff --git a/mm/swap_state.c b/mm/swap_state.c index 0a3fa48b3893..2a9c6bdff5ea 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -951,7 +951,7 @@ struct folio *swapin_direct(swp_entry_t entry, gfp_t gfp_mask, * it will read ahead blocks by cluster-based(ie, physical disk based) * or vma-based(ie, virtual address based on faulty address) readahead. */ -struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, +struct folio *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, struct vm_fault *vmf) { struct mempolicy *mpol; @@ -964,9 +964,7 @@ struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, swap_cluster_readahead(entry, gfp_mask, mpol, ilx); mpol_cond_put(mpol); - if (!folio) - return NULL; - return folio_file_page(folio, swp_offset(entry)); + return folio; } #ifdef CONFIG_SYSFS diff --git a/mm/swapfile.c b/mm/swapfile.c index 4919423cce76..4dd894395a0f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1883,7 +1883,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, folio = swap_cache_get_folio(entry, vma, addr); if (!folio) { - struct page *page; struct vm_fault vmf = { .vma = vma, .address = addr, @@ -1891,10 +1890,8 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, .pmd = pmd, }; - page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, + folio = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, &vmf); - if (page) - folio = page_folio(page); } if (!folio) { swp_count = READ_ONCE(si->swap_map[offset]);