From patchwork Fri May 10 11:47:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661450 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98A3B16F0E5; Fri, 10 May 2024 11:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341795; cv=none; b=CmSvlK8saG1/hMuBE8Ayf+DmFiAJvRZS92lILqS+Ne8yOdEGm4IbyiTuyGif4qGhMnccl4mIj9e768wtylRHB/qddCHtBkVbFWdXlaso+JcitlbUYwvdjG2NFYQ1wJx77YEwF/zDjU4RX0lQI3XFOXKS5QJHIfIfk9mquAw9Q/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341795; c=relaxed/simple; bh=ku8t2GgilDn0tasewSdg0prSSx3qEczJXd6flM0DvOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jb13GjZzu0SJMANwWccWe7IXLWj9PYXZVt2antRhC0MJvKpby0WGUvHiOmLbMRT1LfXmWLjwkd9Ga6m4gkiRM+A5XIOCFtc0gfu0N/mB8WmzhED3dUQX0XApjwvBW8Y5E9cLc6NfDP641J4EzsrtlURhmjTV8TPMunV1KwHUQZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IeADq1sJ; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IeADq1sJ" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1e651a9f3ffso12280735ad.1; Fri, 10 May 2024 04:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341794; x=1715946594; darn=vger.kernel.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=R7lhdO5v0hVN0l2qTLtMelKVtmq+aBFR854K3Ld5uQo=; b=IeADq1sJD9vGYIb0awDEs3HywevfGQFJAEO/WNxXMgkEAvcljbBRK3Kgi/gtq2clMn fUGSS4/zRKF8tzlEhpVeWXU0B/u9Vfp/5Vs/ufAE+jPs0cEBAEVW7/Fr2F12jKr4PxOR 9vGSbz5vbvUyosvJ1nN5sql7xMiF4tkNCFJQdLmAkCjB6bCMq5gM3zbvEUfBkBm3T3Vs 4GbRsAd0aefRrst42XBlKcQ0PnXYLqBh6ju2XMKYCBhAvP1kioWaP7Hr5jGF0bnemWrn 1RTzDo+1VKjYK1j7edhqipKYJdPST1RHw7hYfE96NjRSElom6YOrQtWTk9UxTDzkdSVz C/bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341794; x=1715946594; 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=R7lhdO5v0hVN0l2qTLtMelKVtmq+aBFR854K3Ld5uQo=; b=PfSK8D02zJicnsUaePzuII8ulkbciL/V2W6bfvMxouXS3LWO2g0cuCCV1qbMdQbJGK Zh3cEjZ7E5CYB+qvKfbtQprhot1VdIc5URgGq4TIKuViM596SAtaz88/BgQxxT1CvJsy K1yKiSnG8t7PPfDlF4qaNwuRQPRZyclzgI3uLeJ7VT30zhj7mXVBya/RSjb/Qd1+NHIY 6PKPX6me73myTL1HFpMYLGqNWVj6wVYZYsC8pBFzxuZNaYoRp3uH5jv2kQLi0p4k4PYO HQfYO31YaOXXYYpiSQAfnQUtcbAuGRuwYDsPhgMGxOnc7lSmAghMTuejI+WwRvgGnyGF rw4w== X-Forwarded-Encrypted: i=1; AJvYcCWd3LMdNn2wPsOWpMisWHVna33d9SY11xKpE/DK3U4GYsvhptpvy6pJjdMiKFFvHHswEKoZ9zlCz5gyps7q3O4iMBMqg6Yl3PNh4fqOt1yIiwgn/GnE8cQhZRacGnFGPPhvkO0kaHQAEhKkeg== X-Gm-Message-State: AOJu0YyK6heI0Un9o8PtfbuNjCvHlxaox4ZszyASfRcR+reQEQn67492 Lh/3/ZbjJ9+TdsMCTJNT85fhB6GeTRgvrqkaBSnHwzGS+ayyvJL5 X-Google-Smtp-Source: AGHT+IFE2MX7TpHnes9SKnTNrFmEbBsmeG5v6bapWIi2SW3d+oyDfBCDoaA4IMTDGi9eLDl7rTjLlw== X-Received: by 2002:a17:902:d506:b0:1e4:24cc:e021 with SMTP id d9443c01a7336-1ef44050595mr28789215ad.50.1715341793856; Fri, 10 May 2024 04:49:53 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.49.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:49:53 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Chao Yu , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v5 01/12] f2fs: drop usage of page_index Date: Fri, 10 May 2024 19:47:36 +0800 Message-ID: <20240510114747.21548-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song page_index is needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use page->index instead. It can't be a swap cache page here, so just drop it. [ This commit will not be needed once f2fs converted f2fs_mpage_readpages() to use folio] Signed-off-by: Kairui Song Cc: Chao Yu Cc: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 961e6ff77c72..c0e1459702e6 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2057,7 +2057,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, sector_t block_nr; int ret = 0; - block_in_file = (sector_t)page_index(page); + block_in_file = (sector_t)page->index; last_block = block_in_file + nr_pages; last_block_in_file = bytes_to_blks(inode, f2fs_readpage_limit(inode) + blocksize - 1); From patchwork Fri May 10 11:47:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661451 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DE0C16F911; Fri, 10 May 2024 11:49:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341800; cv=none; b=M/odq1Jyn78iUcRodU/Bd9eTAJslMcOFMEey9ihmhcQXTWJmd7vcRWBM6yaAKdmw3IZABi75Xnd9Nuur75sxH7cx21G3b/ayiJi8ygCQk9IRY03NRN25Nh4KaGV0F/HGALrbo0cD7svuIB14ATiijxaO0dZZ9wfmWS92FzTHsmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341800; c=relaxed/simple; bh=J7ZhPE4n1TNebqti4ceg9RBUgnFcG5UzDJV9uxEpxbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pd3fYv2MjIKB/OHQflgFo2enKyQBW66a1OyZxvwXVl+H0P84bXXBuuOlfJLmTLoJ04m6v2hpH/WxvLggIt3uUlNmAgw9qhN5/a8qpKNBoDDaqHeQENBkRlzT/rkfcXBXA4YUxzfdb+2x3ttRRXLGGajUaHIGH7429dJLSWONFNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RdHmK+eE; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RdHmK+eE" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e651a9f3ffso12281415ad.1; Fri, 10 May 2024 04:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341798; x=1715946598; darn=vger.kernel.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=AlJsO7PWN4Jf79ghcMCVByM1+QjN19p/5hJE9J581cg=; b=RdHmK+eE22GvcFOO0YWliqxAvHM43g5E6LQC6iQlCPMGtXUQ137SyuLxaV03W0oc/n BXt9GUZUYciREyd2xPDPQ/dCSbYsODtFnqtnO9s0Ie5uILn1vbq9CgqNJkm7PNib84L4 COwR3CAwt8XtbKFJdrUwwIHoSAf1SibeIVG0uXW1vS6NvWozE6KehvzREf+ArvjJMt4g hZUIfPHZkZpqmbUMVB7s8R1xpJrciJQr01HL9aSHkhaW4aZkqECo1axgoBZMCMbmEtvC W0aUyfSKqLf2W/xQlkcTWvD5wExDnj3vlUrAQaDWqrbXqPT7w4wYX8Mdn5NHOvRSIUXc ctmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341798; x=1715946598; 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=AlJsO7PWN4Jf79ghcMCVByM1+QjN19p/5hJE9J581cg=; b=igzcJ/UOQvP9z3vz/So8P+YINBmPu8JOYccP/eOG/Gmitoasz/xSL28pY9J2qDlaNg 2MowrSX+13f3A7vM29nlbRSHQP4+7SdNusVGvA0SQ7SHG5omq+oEwLp7I5gLsW3lwnOv NqSDUvw9x/Y/qnoduAAioWXk9lW1Ao1C5Pa+ot2DbYNpduPHhwYBu74sKYz6K1Xdtqh9 JtaOeH/kxo9Qw0MKiSfUfnhC2Yh17mqVKyuFHTm2f9meOuc04BSD8k/gf+OUA6jotxGc 1/dC56C/JIYKooMMX3usRR/vWNPUBAKXaTub2tVxZqag/2y3tmuN3l7Q2KTPzPmsUkHF d42w== X-Forwarded-Encrypted: i=1; AJvYcCUqAGISDLzKpWMZY/Fg43sWUSRaQ5PjNokVBe+6Y0JJFEjh5owouDpyhwy5ETM6ZTd2QgpMAbdiznnrcA4weBrIdkoAAkn2uxGyH8rTZiivBGxDbMzk/oBx5p534zllv2WeCVeWd1tw0ErgX99PEdqubqh5GpCcgcE6YCI3dCxoc9mJbTqFlcnB X-Gm-Message-State: AOJu0YzfwAtHPUOSA8EbjipTLLc+7fb7/MYFKVgZADFaan7Rq3Fu/TFE 5vhH8qOirp5QQquvajTxdrjbeNQvHnnn3zp58icFaLYne8GpCbsf X-Google-Smtp-Source: AGHT+IEgC/5PItwGLdBO3mEfXM0RAVpswT1aq1A3QBfgABXJzBC0a91j/oU3l3ssnynmf+QFhY0xNQ== X-Received: by 2002:a17:902:c145:b0:1ec:659c:95fb with SMTP id d9443c01a7336-1ef43e25e5cmr22881935ad.32.1715341798221; Fri, 10 May 2024 04:49:58 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.49.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:49:57 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v5 02/12] nilfs2: drop usage of page_index Date: Fri, 10 May 2024 19:47:37 +0800 Message-ID: <20240510114747.21548-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song page_index is only for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use page->index instead. It can't be a swap cache page here (being part of buffer head), so just drop it. And while we are at it, optimize the code by retrieving the offset of the buffer head within the folio directly using bh_offset, and get rid of the loop and usage of page helpers. Suggested-by: Matthew Wilcox Signed-off-by: Kairui Song Cc: Ryusuke Konishi Cc: linux-nilfs@vger.kernel.org Acked-by: Ryusuke Konishi --- fs/nilfs2/bmap.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c index 383f0afa2cea..cd14ea25968c 100644 --- a/fs/nilfs2/bmap.c +++ b/fs/nilfs2/bmap.c @@ -450,15 +450,9 @@ int nilfs_bmap_test_and_clear_dirty(struct nilfs_bmap *bmap) __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap, const struct buffer_head *bh) { - struct buffer_head *pbh; - __u64 key; + loff_t pos = folio_pos(bh->b_folio) + bh_offset(bh); - key = page_index(bh->b_page) << (PAGE_SHIFT - - bmap->b_inode->i_blkbits); - for (pbh = page_buffers(bh->b_page); pbh != bh; pbh = pbh->b_this_page) - key++; - - return key; + return pos >> bmap->b_inode->i_blkbits; } __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *bmap, __u64 key) From patchwork Fri May 10 11:47:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661452 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCA9A170849; Fri, 10 May 2024 11:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341805; cv=none; b=A9eU0YossiSObRR+r2q4lThDkZd0hEvQd86szCKhTCz55o5n2f64ymiIf2cTSpD0FIQiTVqAHpTf3JN91yF2VNJKpvCmw6+J7H9dQdJhr+QALyLubKIut3at3FV9I8k2YZD/bikR5p9qzY1kgCPM4EQIIVu7+FV8m0gEYYqqmnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341805; c=relaxed/simple; bh=4l5Ap/GQGcYF0sHhsyCYu2fRIWgnQn2r2DT/zqLBNUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBJR51I7sGtU5HaxxpbCh64fWcodZ3yW3tY0xuwFsKudebHkwlwQIco+xmud8cvVsMq0+F7mxKnLSEfqYMSMRemK68fcpjnfMh6ooptmk6/TH6a8np9yXfSQcIoYba14HLN7hSqAVxPc3+fndaa9cujYdx6iM5bcbSVtuicIfyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FaGM2Fto; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FaGM2Fto" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6edc61d0ff6so1692283b3a.2; Fri, 10 May 2024 04:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341803; x=1715946603; darn=vger.kernel.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=7WZK1EC9ikQfyuHFTfKb94AiIKSPD5K2lma7no+Kt3Y=; b=FaGM2FtoNu1aXaqPgls9vgfcmriY7CifDQP5C/9J9eI2Oup2Am4RnXz3AxoFsleeIO bA49p1B1lczIJuVn2a/rwHkO5rA+qSzmTlYzx43CC9SHo5YNQVqm1Np8MOMetbw+Y9BI /8av+/8JVsmGlqoDFeYTTUPnBzHlnbvG1BsXySqUkrpRUCHJcUaADjfJsBiR8+MVLddL d3AxRdFEbC76JtuSxJ4T0LxFCeZR0z/ISVYKikxq5p1UG30Po3RV9zLe9c/8suWoNohd F7qkHOWJkXadnfr6Yn2F+1EJMBWWfho4bhvvto4qtaCNCSwOq5L68ng0A+yrSfIrOU2s uvVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341803; x=1715946603; 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=7WZK1EC9ikQfyuHFTfKb94AiIKSPD5K2lma7no+Kt3Y=; b=WYRN7XDt4rRkZyLoAdZMjA4u9uACCQU52s9MT36B2vaaVZiWW22ng1N6mBmXy09Lbu lkzNTZHm7VOaFGC6PzyHBZFbDKjr5EgWWu2qAlxJdXFPhLqBSUR0UWd68KN6nVThshEg GzW/8V/lYHA+8jGjtTYeHkPSbt786I+QzKGQzmqDzvrqVaAvrxm1ySFVnnsBKdYeos36 PYRJUq7vJ2KDHWqfRDUHKN6su3dlD6BY1mLPFV+/9fzFwke6/0T17oI/Py7Zj1jJsStH JNkdvtOaDrV6iqdtyDaaXagvwrtwMvTPi+bme3VUFBW4tFD0ngy51UVVoW46dzcH4zwf isrA== X-Forwarded-Encrypted: i=1; AJvYcCWfyZAr41Ye8HoAwFPik1qEllQht963t6R2w7QRNXnZofz8jv4AiYYVsG731hq2GZkX2d6ulmVBkRMXtKXHT579LdsdWwyr1N86kWlnNte8EM9+gUYBu7OkXRH+1P4Q/Sw2oI0wJFqPMv3itSqy+AEyRCI7/3dPAULJGqrWEFBRWuq8MWMAs4I= X-Gm-Message-State: AOJu0YwgUEurn5hwnaEuk2sNQGIQDUGOn+lxd2GSg6UILIMi1QGhrQtL yxXl8BgdVpLBhNZE4YgXRvanWfxWOmhfs0vhJXIzCbUIdA5dKi5H X-Google-Smtp-Source: AGHT+IGzJePUE/u2//e0nGqK25e74fSzzO7KZJDptjk5/1bik27/+5woaxZ+Rq3FhnwvPq89SZQajQ== X-Received: by 2002:a05:6a21:339f:b0:1af:dbe7:ccbe with SMTP id adf61e73a8af0-1afde103d87mr3133457637.28.1715341803002; Fri, 10 May 2024 04:50:03 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.49.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:02 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Xiubo Li , Ilya Dryomov , Jeff Layton , ceph-devel@vger.kernel.org Subject: [PATCH v5 03/12] ceph: drop usage of page_index Date: Fri, 10 May 2024 19:47:38 +0800 Message-ID: <20240510114747.21548-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song page_index is needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use page->index instead. It can't be a swap cache page here, so just drop it. Signed-off-by: Kairui Song Cc: Xiubo Li Cc: Ilya Dryomov Cc: Jeff Layton Cc: ceph-devel@vger.kernel.org --- fs/ceph/dir.c | 2 +- fs/ceph/inode.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 0e9f56eaba1e..570a9d634cc5 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -141,7 +141,7 @@ __dcache_find_get_entry(struct dentry *parent, u64 idx, if (ptr_pos >= i_size_read(dir)) return NULL; - if (!cache_ctl->page || ptr_pgoff != page_index(cache_ctl->page)) { + if (!cache_ctl->page || ptr_pgoff != cache_ctl->page->index) { ceph_readdir_cache_release(cache_ctl); cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff); if (!cache_ctl->page) { diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 7b2e77517f23..1f92d3faaa6b 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1861,7 +1861,7 @@ static int fill_readdir_cache(struct inode *dir, struct dentry *dn, unsigned idx = ctl->index % nsize; pgoff_t pgoff = ctl->index / nsize; - if (!ctl->page || pgoff != page_index(ctl->page)) { + if (!ctl->page || pgoff != ctl->page->index) { ceph_readdir_cache_release(ctl); if (idx == 0) ctl->page = grab_cache_page(&dir->i_data, pgoff); From patchwork Fri May 10 11:47:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661453 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C8E91708A8; Fri, 10 May 2024 11:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341809; cv=none; b=SPkt4YBjgCChitNX5Y7ocKIwCz7MIW2+evrweN7OdbOdEqj3ZxyjxEBtSvWbe0H1vOQ/oBrwK+8KZ8Fi+9kEKzjw+sPZXV1ToWIC7Zw8fHFfW0gG2CQ6uIJLCZoa9aIFWGFKXjW7/rAFfXUUZW+81ZE5qaFI5nTSL7trcA9ujbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341809; c=relaxed/simple; bh=ShAn5fhCYPl8qlhBHZU43ypZj6BFHQvlTb/1BJsqubw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TF/knX2Je4hkThBV+YMCux9npwXbwSaFYdSwRD0f7i7fC/VLXjDWdzL0Sm9rtkJtShpwp+TXDgDoqQ0p0wB4+6MMVXU496k5RkfW/3WCgn2vgoptcoRjw4Ixs7x9K53wTFBBp534TasdqqRLANFOHq8DQNpPGmMqTTQbJkU3bF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Z7JmxddO; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z7JmxddO" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ee5235f5c9so16379115ad.2; Fri, 10 May 2024 04:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341807; x=1715946607; darn=vger.kernel.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=T/Y01wUoc8GqRpvXAplln3XTaKFYbBI0hlcfHL66MPg=; b=Z7JmxddOeFmyIqyuuUHxZWbKUBhPVsXdz7rrc/DQO+hWvucrWFEHiiaqMoyIdVkjV/ wE74Y6IrgmWARCErVqGjN6F7jEEnAAqU0yf2j2HVyLpJCnIJ9gB3X9UwIyt0YUSN2nXo XNU2TrBvmchACbrP5XPeQpj483FON6xMVm/Xosuk4HXM2XjpMf3fR5TxSHCvdjNgoqsc Sbbs2lmyy6bZU6PUN85/YwNBoWVuoan1TiuBnMXo1WJqKVZT/sqGEQEQlfAHNTkXlYAA IenA9jUydjU/lo42kqtmXC2Z1zM0Pu4VcJzFYRMPTENlwHCGgPCVbtY7wbSZIcvdup6h WB1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341807; x=1715946607; 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=T/Y01wUoc8GqRpvXAplln3XTaKFYbBI0hlcfHL66MPg=; b=hT3g/y4hGKP67CRcyt9XaGVPILddiI3SpcTEwKlm88HzlredXd73d0oy5FtXjYLyt3 tdny78vw9ChAcRHefP7au1l2XT2AWfYZi5aq7Eaa1qzD4CDDlC7yTmld5CjakEkM+Qau 44FG3m0aZ7YSVxcf7GJe4TBkBWiksGxMYLr9K2M3K3wTNfMPUnGi4vcDTAsy4cEC+tYh 5ob7FzEPF0EU4ptvIRilNDQNHEiELR/naRRlR+Hka+1yp2OylmnxkgGTJUDiL2xALENz /JH8UHxxK2OHQK28kJCMXSruZ+sxhOyTWSin7t+g1vV7QN6iWgX8Gk6/fBW1JgIs2+Aa 4R2g== X-Forwarded-Encrypted: i=1; AJvYcCVUbaodkwUxyOMDpVdgcQtL59/DkrCCLqa9XKRao1KUIjCL1oVH65xixHf4P2RZYLZj7ZdC0yBd7cU3aSSeJSvutlLa7DqxSv81hzQreKSuSv9KDAHD0pF8WyYQUhT5gO4/u6KAeAQL191vuUzs5lsVmiDge0TD3Eu7ULm9Vbb9CIoE6GRMfA== X-Gm-Message-State: AOJu0YzPJtL+srdFM6SZLsPAbx5mY/FBFnnQ2OFlVjT36hc1H3w4aa99 89MCn5ezKTWw/xRaDvHesmCFZW+e8VHyVkm3bccij56IHHFXJCiT X-Google-Smtp-Source: AGHT+IFzfIkLucPk4sXxl+wOh9wZthAGLSllywtwnMpoejVUjDeq2V0rnDLW1ag2irzlv9JXvgqNKA== X-Received: by 2002:a17:902:8307:b0:1e7:b7ea:2d61 with SMTP id d9443c01a7336-1ef43e26bc4mr20776495ad.37.1715341807566; Fri, 10 May 2024 04:50:07 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:07 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v5 04/12] NFS: remove nfs_page_lengthg and usage of page_index Date: Fri, 10 May 2024 19:47:39 +0800 Message-ID: <20240510114747.21548-5-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song This function is no longer used after commit 4fa7a717b432 ("NFS: Fix up nfs_vm_page_mkwrite() for folios"), all users have been converted to use folio instead, just delete it to remove usage of page_index. Signed-off-by: Kairui Song Cc: Trond Myklebust Cc: Anna Schumaker Cc: linux-nfs@vger.kernel.org --- fs/nfs/internal.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 06253695fe53..deac98dce6ac 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -790,25 +790,6 @@ static inline void nfs_folio_mark_unstable(struct folio *folio, } } -/* - * Determine the number of bytes of data the page contains - */ -static inline -unsigned int nfs_page_length(struct page *page) -{ - loff_t i_size = i_size_read(page_file_mapping(page)->host); - - if (i_size > 0) { - pgoff_t index = page_index(page); - pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT; - if (index < end_index) - return PAGE_SIZE; - if (index == end_index) - return ((i_size - 1) & ~PAGE_MASK) + 1; - } - return 0; -} - /* * Determine the number of bytes of data the page contains */ From patchwork Fri May 10 11:47:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661454 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 417C316F26B; Fri, 10 May 2024 11:50:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341814; cv=none; b=hXN3airviY4xsmIqVWX5W6/COGTAW9GHIGyKIur0LL2IU/uC4klR+UaukBvEVAhqQBgECH23MfvOYlVhbZqdTsPljgB7cvQe5Uu2mDtqBjYsk/63uiZ5ZPzuhywCmuhHhS3sqzRzwz2ewd0UlztsQCkE7bmJK2PDpGewjWnNeng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341814; c=relaxed/simple; bh=i4h+33ayWNxAxzC4LjdAPn27sgSSgKXxUE3iazZbtVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XvNzzPzvkANKWFJiYckroqJA08hMjipb4jySLmoZfOknbut8uoq9w/ogUcW8wPfSZtTQEq/Uv4hpziFapep8WToSD9jniJ3bhhbNAK79UAgkjipRdCOkeq+ibjlX3lm1IYOjSfBz7omczSXESoP9x7L+I7TqjHwSYUVZEEuX1qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cEBnEjv9; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cEBnEjv9" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1ee38966529so21357635ad.1; Fri, 10 May 2024 04:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341812; x=1715946612; darn=vger.kernel.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=SKkpoPGaGqkRG+GvEkaimZUGHi7Z3i5I8Zq2egM0XJg=; b=cEBnEjv9cMNz+j59pbJ2Ws+rusWfP9epVu9C1Ays6zaqH0HAbHm2CzuK1K18cCpzJl XWLOq4+Bl7evRaj7Nen+1xjWYfgdagcgKIjmerP2Xp58qGNArpEelYNwzPMM2j+cBfju /64A+mr4V4+eujBeWzi4I2qDlrh/brH78ahP8EpJwfze2FSYEL6GMKB1vRw8MBtFqeJh oWx2Oh4CsHfTpsV3JReK20yGzMS++EYGsMzerWyhz+05cPQfFV0NR5NcDL0HVNYMaQYJ snWPEQbm/2ki4YWkbwidKvK0fol9y3nYOMnvyXV81blnbXDPRB/RJAhP2ALRmv0ofllC 5ONQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341812; x=1715946612; 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=SKkpoPGaGqkRG+GvEkaimZUGHi7Z3i5I8Zq2egM0XJg=; b=G4fMOtNbwU/3VTCTy4K9TPey+kkfGLeh6GUwOnHs6AbQKAaELSZrlh205KnNmpquts TuGEUEQphsxaxKYM0tCRVgn4V6hPyH/uMgttccPNAxGrn1nut7Vxsm4rtoypZNJWrWLm sU3P4hcOY62J/iY1iVXHJ0SW+bhd+E6SbXoR/eZa5PXg7hhrzXIVCz8xe1QM6oIds4gP 6NF6hvfHBX2vhBy04mT+qKM64pliKKv07Xbg/UJM6LTJv3q/8y9K0CqYUqgmKbjVWfcJ J6Cg6WTYvQPsDgjx0WKgm+6vNw/cabmcsJvReylbShQVRC7BMMIS+LdFTZQYWxpn+FLs Eb9Q== X-Forwarded-Encrypted: i=1; AJvYcCV9vI13eCvSKxqBbSFOTLcScZhyotThnn0r3Ea7aS6jLuPxt1Hp2TIBizllR4Z5VBaj5nV4e1rAOlGiFTswRt0CMCMBNq7SrVRp5WBMH8VwHdJtbNz0qvQnu/rHY2D63BXRdD7Eftb24EE1Bw== X-Gm-Message-State: AOJu0Yx4NqOYEmmjrjveB5OaGjkQr3vLVrmWPxqVDEet9jZ8Eh0WjQpE SGFn1kkVcwOQg1OqNkY+ztKaCm9t1AlKNCu6wKB4OEKLmcD1MQP4 X-Google-Smtp-Source: AGHT+IFQCmuUzZejhKR+NA0CyPkuBm+fZ6cTTLFHyaCrgsSueVY92V2AUpJszgttMrtwpUbv0gZENw== X-Received: by 2002:a17:902:cecc:b0:1e5:1041:7ed4 with SMTP id d9443c01a7336-1eefa12f408mr84798105ad.14.1715341812566; Fri, 10 May 2024 04:50:12 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:12 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Steve French , Namjae Jeon , Paulo Alcantara , Shyam Prasad N , Bharath SM Subject: [PATCH v5 05/12] cifs: drop usage of page_file_offset Date: Fri, 10 May 2024 19:47:40 +0800 Message-ID: <20240510114747.21548-6-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song page_file_offset is only needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use page_offset instead. It can't be a swap cache page here, so just drop it and convert it to use folio. Signed-off-by: Kairui Song Cc: Steve French Cc: Namjae Jeon Cc: Paulo Alcantara Cc: Shyam Prasad N Cc: Bharath SM --- fs/smb/client/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 9be37d0fe724..388343b0fceb 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -4828,7 +4828,7 @@ static int cifs_readpage_worker(struct file *file, struct page *page, static int cifs_read_folio(struct file *file, struct folio *folio) { struct page *page = &folio->page; - loff_t offset = page_file_offset(page); + loff_t offset = folio_pos(folio); int rc = -EACCES; unsigned int xid; From patchwork Fri May 10 11:47:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661455 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F194516F26B; Fri, 10 May 2024 11:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341819; cv=none; b=XbRp1Qw4k68mr4F1glwHaFDD+JjUj/jJRrOlh1MruoEg11cIadjBkzlCDJHqjQSj+7JNZAhnFwg/Z61/R1ifVVkKDKIE+pvboN/LWyE3A6qjyBt89/WGsb1Vax1qoLnk3/p2PIj0AjAwIWPBnvM6g3Jrt4/kO0VFgC3Y0dUPY+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341819; c=relaxed/simple; bh=1MRIiBP0wDFyNfh4532Vxucv6112mEx/goVx7Jaownk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DTwZYE+HiAvGPWuF0QJwZWmm/2cN0P14eolcGWeTojX6aYdIfuJF4GGzQTBQh18oo5uka6Sf2m4WZzsD7aOGrzGpc6y1OzZAkzkf558M54ifuOgzJZKVf48sq51ZMXtdu8wvEczN61+TkA2XR6phOcT/OgNosd0S/JpcVbSkTRw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F7S6kZ7B; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F7S6kZ7B" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f44e3fd382so1692418b3a.1; Fri, 10 May 2024 04:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341817; x=1715946617; darn=vger.kernel.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=P42QJurgga8X3tClV+VU5iyd0pTaBz/Ss0EAkzfZsy4=; b=F7S6kZ7Br8XjhqdCitErqbXDQ+GeQ0BadVuNOcCxLvZLCcKYFtmCDbEwTAV3xoVrpv IkCVTAzMXlOhnQqaIzcnfsDcu9ZUFMQauFIbJvQgt+jMjETTArJplzhoqlRxuoVASsbf cmUFRI6mZVxRfCOmMQk8ry+oKL5EUCOvv2AbGoH3dWzl4qRyvqmSgo1/Mq4wMRCs3kWM H81rSZXhjlFnVfFFgDwj+YWCTtksVncbZJNP1lB+H2e7gK7s9aOBrZS1+5pDpJsPPIc/ pploIPt6SvA7+XiCUFZiDMqOumvv4f7Bp4YPE7QlzEZxU+1mK79xB7nt36tRZ776XMTg 7uxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341817; x=1715946617; 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=P42QJurgga8X3tClV+VU5iyd0pTaBz/Ss0EAkzfZsy4=; b=fng64SkjMlzftBfoqOTVqvqrtKT10LHwqX/6VkTKJVwEjH9Ku+MUrntijoD4gjheD4 KWNH8tjUB5UZIBi5lLwAba38i8D0uoUSOEa0XSpRDrkVncTquHsdwGx0sDkm30Y+iDug lt6zHi/LJFfhYowpbgn2DDOGwtD3qYwfzWdsRik1qQ2CY4RKw68KLCcRARCSqqeL0VGQ GKrxqp9uwzoyB2vlvVW8QJZr7HLXwbdkwmC3ncLE3Z3NsqYYghpkRL3tF9u2Fdkexcir Atwd1qCHSEhF5qC2hKMNLs7O8XQa/pYBWMyXO8kqz4Uf7YqiB4SPZOnsHurzBHlY5Qxl UFgw== X-Forwarded-Encrypted: i=1; AJvYcCW45tSyDld0mij1MGoQgzSxpzNLyibnlhqvbTK/SyXA0aFuGfTDWPtGMfd+m+Rsrwos1cF7H3o0t8OG6RLrVBZmn2/UDD+sWZVlcbpHIS3lqFLMxCw0mRJCNezjr2cuwbh6iZdZWyk7MWMl3g== X-Gm-Message-State: AOJu0YzBc197nYnjtcbKeY8rDD+BYPspMA4P6GzjJZHDjQgVW42+yAmq nqzmqNKtDVw4KRi72z27Hy8UxMTIEZuH0HjxH+cX3tpxwjb6B69B X-Google-Smtp-Source: AGHT+IG7UAvfga0ZG2yNv2RJVoigr75WJ+wAKzDPiq9W3zLhf2/XYb9zpcIAAYXrq2V/r060tL2Rzw== X-Received: by 2002:a05:6a21:3991:b0:1a3:dc61:926a with SMTP id adf61e73a8af0-1afde234e8bmr2652358637.54.1715341817254; Fri, 10 May 2024 04:50:17 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:16 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , David Howells , Marc Dionne , linux-afs@lists.infradead.org Subject: [PATCH v5 06/12] afs: drop usage of folio_file_pos Date: Fri, 10 May 2024 19:47:41 +0800 Message-ID: <20240510114747.21548-7-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song folio_file_pos is only needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use folio_pos instead. It can't be a swap cache page here. Swap mapping may only call into fs through swap_rw and that is not supported for afs. So just drop it and use folio_pos instead. Signed-off-by: Kairui Song Cc: David Howells Cc: Marc Dionne Cc: linux-afs@lists.infradead.org --- fs/afs/dir.c | 6 +++--- fs/afs/dir_edit.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 67afe68972d5..f8622ed72e08 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -533,14 +533,14 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, break; } - offset = round_down(ctx->pos, sizeof(*dblock)) - folio_file_pos(folio); + offset = round_down(ctx->pos, sizeof(*dblock)) - folio_pos(folio); size = min_t(loff_t, folio_size(folio), - req->actual_len - folio_file_pos(folio)); + req->actual_len - folio_pos(folio)); do { dblock = kmap_local_folio(folio, offset); ret = afs_dir_iterate_block(dvnode, ctx, dblock, - folio_file_pos(folio) + offset); + folio_pos(folio) + offset); kunmap_local(dblock); if (ret != 1) goto out; diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index e2fa577b66fe..a71bff10496b 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -256,7 +256,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode, folio = folio0; } - block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_file_pos(folio)); + block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_pos(folio)); /* Abandon the edit if we got a callback break. */ if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags)) @@ -417,7 +417,7 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, folio = folio0; } - block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_file_pos(folio)); + block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_pos(folio)); /* Abandon the edit if we got a callback break. */ if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags)) From patchwork Fri May 10 11:47:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661456 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8312171670; Fri, 10 May 2024 11:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341824; cv=none; b=HWjhkf1hT42TwqqzLDYat5frjXK0Iyi6cbRFFmdD90peO94wy8MvYyNKPYWLld9dmnYX2OB9hEQggVor71qDfcwTHlDUieyADzU12ikwcSx6C/ZAzjaY5Ux0KMUN90iAxnxaOExXzmMVSwGiYSJoLWpGvj0Op6CYheXho42ZJSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341824; c=relaxed/simple; bh=F3EKclujHSSuxRJLJjZWka9tbvl2y2InP9dBBoHDt2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mGCxyAYNd7Ls66sYvHVQFyVSfXP/OwM42pBkhF/u84b0iTbLUda0rt2LePT2jJ2tMe3wIjfkd4UjSoduBWNWtkiCe37X6BsiEfACVQuaG68yyi3It5mqwb334ql9CBZk+TTG6IgbQgAJ+NyceT2KpQPeCJthV1kYJ6rT2hBMYaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kl41EsBd; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kl41EsBd" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1edfc57ac0cso15524115ad.3; Fri, 10 May 2024 04:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341822; x=1715946622; darn=vger.kernel.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=r4pI/dLra8+Fx5rO5TUtIiOfN5ranfVQtnPo5N4NowI=; b=kl41EsBdLi4RH2Jm9RI14Xqksuhmb2bqaXkewMKijqQn/Zu3fd8VBNJZZihWTpcWcO CzaI1R0/tBug2AjkX5vqSVNoqHTmIKp4XYqEvfkym5S8RMG+8c4zMH6JHhPdFpk5Sbdz +uVjDPfnm+43yccPl/Mj+/PkJWEC8xSZEbNAMmlmmrB6gcxNl7uErj7UMF+s7XuXzkil arzGZi9FA1AY5TWaYQbvrC4QHcFUHKfyZbOYQ0FXhwgsFYCOWMc6LeaGDtiihecb9+Bq AnhAJwjOm4y9oeUKVKRIYDNGVBvA1/mOLyXk3zqCf7Ztu3as9x88vIuqwl7jcNWVqhpt LTYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341822; x=1715946622; 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=r4pI/dLra8+Fx5rO5TUtIiOfN5ranfVQtnPo5N4NowI=; b=ZqySyk590pZn8rVaTqLAERMvjuLjm8J8y0BIVQd18HbMMa6p/nSjDCBgNylrOwikon YllcEEIvHJdirlkJBkVdu7CzZRxk4PbHqALhS38iKXLbG2yNScE1b7zoe2f7Ro79iejd u63NNhPE6dEXVB830eeLPpK1uHdOREfz2Af9BaMC3MMSUhYhRxLpTHcTu2oQ1vg8KxL0 2W5bRH4faLzwKG83POu2p6lKfJl/G8j+YfIwkfX60AKQGPqwoIprwYB7CTp2/YE231dX qYkZskZT9WE0z/kmxLQ3vdfdslbBhK6CyhGXOVjv1K7o8EJ+CdzXCtcBzH/zrtBMSkYd +Spw== X-Forwarded-Encrypted: i=1; AJvYcCXpED7B+8+xhxEU+7sfoE68FT45rQ/4z0wM2mdw1D3IwMQ0FNToHZh5VNNhfrCsw5M56L8FYVrENpWCUjliV5EIuAGtbYguyHFbA8/UCc3YbR1YX0zvkVFfFzkt618PuNbslD9xgUlJOHz3VA== X-Gm-Message-State: AOJu0YyPw+dMFpgVxTu6B6cbLvm+AT+XQlu52ppkRxWmWQGol+cEoK9C w7YB0PY6I9RgUlWUH99ZSL2HTJeYQyRJRnngzSvTM+2clw9zZ2V+ X-Google-Smtp-Source: AGHT+IHSu4vf1uCLF5qFTJHXuHSvWwDd6wRy4AQCNalBLaHz4N+8wZRkLwQ24nQsMv4SDXunk7nJRA== X-Received: by 2002:a17:902:dacd:b0:1e5:62:7aaa with SMTP id d9443c01a7336-1ef43d185e9mr29151095ad.20.1715341821906; Fri, 10 May 2024 04:50:21 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:21 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , David Howells , Jeff Layton , netfs@lists.linux.dev Subject: [PATCH v5 07/12] netfs: drop usage of folio_file_pos Date: Fri, 10 May 2024 19:47:42 +0800 Message-ID: <20240510114747.21548-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song folio_file_pos is only needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use folio_pos instead. It can't be a swap cache page here. Swap mapping may only call into fs through swap_rw and that is not supported for netfs. So just drop it and use folio_pos instead. Signed-off-by: Kairui Song Cc: David Howells Cc: Jeff Layton Cc: netfs@lists.linux.dev --- fs/netfs/buffered_read.c | 4 ++-- fs/netfs/buffered_write.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 3298c29b5548..d3687d81229f 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -255,7 +255,7 @@ int netfs_read_folio(struct file *file, struct folio *folio) _enter("%lx", folio->index); rreq = netfs_alloc_request(mapping, file, - folio_file_pos(folio), folio_size(folio), + folio_pos(folio), folio_size(folio), NETFS_READPAGE); if (IS_ERR(rreq)) { ret = PTR_ERR(rreq); @@ -454,7 +454,7 @@ int netfs_write_begin(struct netfs_inode *ctx, } rreq = netfs_alloc_request(mapping, file, - folio_file_pos(folio), folio_size(folio), + folio_pos(folio), folio_size(folio), NETFS_READ_FOR_WRITE); if (IS_ERR(rreq)) { ret = PTR_ERR(rreq); diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 9a0d32e4b422..859a22a740c3 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -63,7 +63,7 @@ static enum netfs_how_to_modify netfs_how_to_modify(struct netfs_inode *ctx, bool maybe_trouble) { struct netfs_folio *finfo = netfs_folio_info(folio); - loff_t pos = folio_file_pos(folio); + loff_t pos = folio_pos(folio); _enter(""); From patchwork Fri May 10 11:47:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661457 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C216171E67; Fri, 10 May 2024 11:50:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341828; cv=none; b=JSoVr4FeK/r4fgBM52e9n+qZUfwx9tNzEMbxqRB12jiu3pfsvLi22WUzVCVW13Bu6DJfxm98i7rMdKmXjPQWVd6yqYfcDYlq/+qpKsXlYMC4elJdIPV6WHI4fLnKaLaO5iOsHHE2+9PCipZ8HPNb/wxY5fF+Ohlalntw/LK6BHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341828; c=relaxed/simple; bh=YN2lXIAdW+FIH+nlJ+O6gfCsXaVYNXGhOvEJxPri7UY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CgWS29FQ+4U0VDHQY1j5VCHNUiITMaFWxKC4ruXyZBFmrdOPMrpUx53pRrGkzez5TZf6ldNkiK/Vjx1ZV8oZRxRDieskD7uWBLpyfw1iQsAfzLckL+wrkLp483l95Ov+v66Tw+s+7zQlZEoAEUbhBfbLLL3GqdBrNXsbreKsQzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Oyck0n/5; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oyck0n/5" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1edfc57ac0cso15524825ad.3; Fri, 10 May 2024 04:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341826; x=1715946626; darn=vger.kernel.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=mIIbTsUqC47TgpII0qMr2P678NC38ZS92LaHNxc/VvU=; b=Oyck0n/5EI/1+xwbwCILzdtRloIzTloqLbIeCuIRtW+eigpYNV4v+7qgKvMw1xXkRn D85nl7w+pORHzKxw1tsGjWwqOvsqHVMvFPooT7c0GAR2E38lOXSDMx8kWgpDIJZwJpCj JYGgauz9Ao6Ys9CneB1lhfhCjes90ajQwJiOi0HsysdtQrz15bpoeejQosW4BlnuMPvd HWS3qA6PtS/WDtFxciQdEoUnoMntAIeQRyZCPVwn4qM/Wjd/QAOHB1Tm6aErArXXpyv+ 0TNIZsODBz6pE6lJ6BVPS29F0SkgfjA+6pyDJ0ohpqQL/+s7dAqDkRil84qtIxLYm4Il B0Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341826; x=1715946626; 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=mIIbTsUqC47TgpII0qMr2P678NC38ZS92LaHNxc/VvU=; b=TIFYfM/WjpbYUOEESYH7uZqF/4GRIxd5CrMt1+79kJ4bXMTkygdAiwtPZ9E7VCSsNq sBqFjCMPt04CHgGiTHg94aMUExW12Yfbv770OWUjvPjGFKy/A9pnS3Ti1v9M3Ten8+WV mhFZG3hZz3ikumy/VT1YCTzuTdTxgkFt1VCxmmkIZ9w2YOV3XXB8FQghUtCaCcJK7JOw fv8TSiDXxJ1skiHT/GdCcQLok86pSuCrIZIA7tZhRpQ117JklDUNdgo7KaMHyyzmrVRT 4X1LQUSjT6oNN/wEeMpBYbF4+2r6XdAVlAuCZkrf4ubZfv5ipODOXU2fX3Rr15RFUhL8 oInQ== X-Forwarded-Encrypted: i=1; AJvYcCW0+TVr+mipHzgKwybi1TCY5NyF9pZBJ3Nv8CQndbDwEpl2l8FhJDmm+AfT4X9Bc+SK7pGwStvfrEgopXpNH9UFFjdGcVlPDvLC3Y90gxrLBDAOtnYLJ/qftGidPWIOcbgot4rXxQrKObZXoSkm9vCacAw7EirZV5nkBg1I9Wf8mzxgMQ27BA== X-Gm-Message-State: AOJu0YxqED87/4GhoA+5kjiM4v2F3JswwXq9hVkreiTVjtLc5HDd7OUY 7c8BRlQB7VxfQo+A0RTjlvGmOyEIPvvo9Bj1mT4EyqNtS1wKyXHG X-Google-Smtp-Source: AGHT+IEqWWlYE0LaQa+qtHe47sVQ58jjdkZuIoCJG8MKrxdZVoUXsASGJ68twijEqsRcGHoHUXZc2w== X-Received: by 2002:a17:902:d4c4:b0:1eb:7ba:a4bc with SMTP id d9443c01a7336-1ef43f43106mr25708225ad.51.1715341826460; Fri, 10 May 2024 04:50:26 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:26 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v5 08/12] nfs: drop usage of folio_file_pos Date: Fri, 10 May 2024 19:47:43 +0800 Message-ID: <20240510114747.21548-9-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song folio_file_pos is only needed for mixed usage of page cache and swap cache, for pure page cache usage, the caller can just use folio_pos instead. After commit e1209d3a7a67 ("mm: introduce ->swap_rw and use it for reads from SWP_FS_OPS swap-space"), swap cache should never be exposed to nfs. So remove the usage of folio_file_pos in following NFS functions / helpers: - nfs_vm_page_mkwrite It's only used by nfs_file_vm_ops.page_mkwrite - trace event helper: nfs_folio_event - trace event helper: nfs_folio_event_done These two are used through DEFINE_NFS_FOLIO_EVENT and DEFINE_NFS_FOLIO_EVENT_DONE, which defined following events: - trace_nfs_aop_readpage{_done}: only called by nfs_read_folio - trace_nfs_writeback_folio: only called by nfs_wb_folio - trace_nfs_invalidate_folio: only called by nfs_invalidate_folio - trace_nfs_launder_folio_done: only called by nfs_launder_folio None of them could possibly be used on swap cache folio, nfs_read_folio only called by: .write_begin -> nfs_read_folio .read_folio nfs_wb_folio only called by nfs mapping: .release_folio -> nfs_wb_folio .launder_folio -> nfs_wb_folio .write_begin -> nfs_read_folio -> nfs_wb_folio .read_folio -> nfs_wb_folio .write_end -> nfs_update_folio -> nfs_writepage_setup -> nfs_setup_write_request -> nfs_try_to_update_request -> nfs_wb_folio .page_mkwrite -> nfs_update_folio -> nfs_writepage_setup -> nfs_setup_write_request -> nfs_try_to_update_request -> nfs_wb_folio .write_begin -> nfs_flush_incompatible -> nfs_wb_folio .page_mkwrite -> nfs_vm_page_mkwrite -> nfs_flush_incompatible -> nfs_wb_folio nfs_invalidate_folio is only called by .invalidate_folio. nfs_launder_folio is only called by .launder_folio - nfs_grow_file - nfs_update_folio nfs_grow_file is only called by nfs_update_folio, and all possible callers of them are: .write_end -> nfs_update_folio .page_mkwrite -> nfs_update_folio - nfs_wb_folio_cancel .invalidate_folio -> nfs_wb_folio_cancel Also, seeing from the swap side, swap_rw is now the only interface calling into fs, the offset info is always in iocb.ki_pos now. So we can remove all these folio_file_pos call safely. Signed-off-by: Kairui Song Cc: Trond Myklebust Cc: Anna Schumaker Cc: linux-nfs@vger.kernel.org --- fs/nfs/file.c | 2 +- fs/nfs/nfstrace.h | 4 ++-- fs/nfs/write.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 407c6e15afe2..02741c32e114 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -588,7 +588,7 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf) dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%pD2(%lu), offset %lld)\n", filp, filp->f_mapping->host->i_ino, - (long long)folio_file_pos(folio)); + (long long)folio_pos(folio)); sb_start_pagefault(inode->i_sb); diff --git a/fs/nfs/nfstrace.h b/fs/nfs/nfstrace.h index afedb449b54f..d249741452e1 100644 --- a/fs/nfs/nfstrace.h +++ b/fs/nfs/nfstrace.h @@ -960,7 +960,7 @@ DECLARE_EVENT_CLASS(nfs_folio_event, __entry->fileid = nfsi->fileid; __entry->fhandle = nfs_fhandle_hash(&nfsi->fh); __entry->version = inode_peek_iversion_raw(inode); - __entry->offset = folio_file_pos(folio); + __entry->offset = folio_pos(folio); __entry->count = nfs_folio_length(folio); ), @@ -1008,7 +1008,7 @@ DECLARE_EVENT_CLASS(nfs_folio_event_done, __entry->fileid = nfsi->fileid; __entry->fhandle = nfs_fhandle_hash(&nfsi->fh); __entry->version = inode_peek_iversion_raw(inode); - __entry->offset = folio_file_pos(folio); + __entry->offset = folio_pos(folio); __entry->count = nfs_folio_length(folio); __entry->ret = ret; ), diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 5de85d725fb9..fc782d889449 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -281,7 +281,7 @@ static void nfs_grow_file(struct folio *folio, unsigned int offset, end_index = ((i_size - 1) >> folio_shift(folio)) << folio_order(folio); if (i_size > 0 && folio_index(folio) < end_index) goto out; - end = folio_file_pos(folio) + (loff_t)offset + (loff_t)count; + end = folio_pos(folio) + (loff_t)offset + (loff_t)count; if (i_size >= end) goto out; trace_nfs_size_grow(inode, end); @@ -1362,7 +1362,7 @@ int nfs_update_folio(struct file *file, struct folio *folio, nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); dprintk("NFS: nfs_update_folio(%pD2 %d@%lld)\n", file, count, - (long long)(folio_file_pos(folio) + offset)); + (long long)(folio_pos(folio) + offset)); if (!count) goto out; @@ -2073,7 +2073,7 @@ int nfs_wb_folio_cancel(struct inode *inode, struct folio *folio) */ int nfs_wb_folio(struct inode *inode, struct folio *folio) { - loff_t range_start = folio_file_pos(folio); + loff_t range_start = folio_pos(folio); loff_t range_end = range_start + (loff_t)folio_size(folio) - 1; struct writeback_control wbc = { .sync_mode = WB_SYNC_ALL, From patchwork Fri May 10 11:47:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661458 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D63F172795; Fri, 10 May 2024 11:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341833; cv=none; b=RQZSkRAVbN8y8u40vWYcOLfXKK8X1riGqC84PqbH876EhOtS8596wGv1dGcnMNLpEUDDT1aKyXktPP9MkFN+q8/oinqowp1SIGHs5mySj74W+Ib73HTH+hCeXBC9SadodCjSMKqtJVc0pGbG+pWhfN6K4ljf5rumUq9QhLVwIek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341833; c=relaxed/simple; bh=1SAVvMr94KYXIST+pzvRHms13THqgeIYsOrrjA5MSRo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ofF8ayib0zjYBTlI7feKoCsT+RYpGRZEWGhaT+gOdHnJJerOFl4NcMZSKJekVNwOsaZXQSZqnEPhLQjpzfIgCDcQFfDQq+BLn5j5QUv6T4IBMIScS/MNYFblgSgxwcmi+/Gs7S4odV6keiRbjJ2374i4OfH5208Cc5rFAODOkuc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RTWpwKIt; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RTWpwKIt" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ecddf96313so16452025ad.2; Fri, 10 May 2024 04:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341830; x=1715946630; darn=vger.kernel.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=D1huxSjfPNpI2elfAn7WJAQ+EPp79T3Zke3qFamrARc=; b=RTWpwKIt5zNLF83nVl0M/t3XTmWXQESJKvJLGOXHQbplIh1AGHDxAB1tdpg2flbuld s9V91iai1aoQI+zn2UPWOwjmNJx0EAa2gOCsqT6jdiOiXsRwapcBxs0OdDiLrG8DFQMW zukDHQ0kDdSqbmP1HNFU/EitQeoCCRCmaDbiS3NvPdxNOX1btQITiTcIyxNPBuze/O4Y lkkRBXLDQBCUeagb8K6wUw5uckFWqLvdm+IxwDcl+qcI71boFS/xW9WAZuQY+r63xyU6 JYTGT6zQvuU2udDAZH8nvLwkzY9XeNAp3Uuq7x681cv3r3ixsxoqJwctypn1T//X97FH 6lJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341830; x=1715946630; 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=D1huxSjfPNpI2elfAn7WJAQ+EPp79T3Zke3qFamrARc=; b=hM2IV8109I8Z1dGKTFRUMdO7cffHoKsyAGgDy1Qpx7Im9+z1HW1BpOHYJsHAh8NrfM fGNlLrleVWG85dMoBwmJVbJ90WUDCfUNFyliGQ3cFBado3TzImd8KrPKUKJRoUb5QVas KRLeVQ6/jKIN5nUWaXvuI4tyr/TIPcd618kA//LeO1pd1MAwnUlW4U8VoZpH18nQOWkC oMuGfc9nQApdU4q7QgmU6kgX7c/vaM+Po1jQfWoaeVLaqZKWJwwIhlI0WRSED/s+VXVx py308NigmQ+921rCYIWBsiPeGGafEp3EKnhol6qdGxf998jvT4JIM5bvfrmZJ6Yw1HJR pnMg== X-Forwarded-Encrypted: i=1; AJvYcCUggOUJvokr/YjZpXF7Td70sr4aZF1aOVZ+xWoABvxqNfc1ZOIIbsBVSBNpFusGhawaFya2+qrkrnj1BCAU6MaZDi1vSAltUneZ3htoUcgIQULRFpCgSrKWNUEaLcx8DoB8/GMxmhfRUUgi+w== X-Gm-Message-State: AOJu0YwyXER1qtMbv9Ht82xcBfW/JiGBFRNwpskB/7TvbggRjUR4g77W SbonZaXcA/TIvV26hXMFjCmGk4KoR6oKugPgrHUZ9jSnoPYJpLA9 X-Google-Smtp-Source: AGHT+IEEg6dE9/dabWmlAkHlSPTCpPJRcc/k2Jrk8P/i3G+yAdrIEP6CyhaxILwoXp+bzQftvYAMNg== X-Received: by 2002:a17:902:ecc7:b0:1ec:7b0d:9eb9 with SMTP id d9443c01a7336-1ef4404e44bmr34221205ad.64.1715341830560; Fri, 10 May 2024 04:50:30 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:30 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v5 09/12] mm/swap: get the swap device offset directly Date: Fri, 10 May 2024 19:47:44 +0800 Message-ID: <20240510114747.21548-10-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song folio_file_pos and page_file_offset are for mixed usage of swap cache and page cache, it can't be page cache here, so introduce a new helper to get the swap offset in swap device directly. Need to include swapops.h in mm/swap.h to ensure swp_offset is always defined before use. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/page_io.c | 6 +++--- mm/swap.h | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 46c603dddf04..a360857cf75d 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -280,7 +280,7 @@ static void sio_write_complete(struct kiocb *iocb, long ret) * be temporary. */ pr_err_ratelimited("Write error %ld on dio swapfile (%llu)\n", - ret, page_file_offset(page)); + ret, swap_dev_pos(page_swap_entry(page))); for (p = 0; p < sio->pages; p++) { page = sio->bvec[p].bv_page; set_page_dirty(page); @@ -299,7 +299,7 @@ static void swap_writepage_fs(struct folio *folio, struct writeback_control *wbc struct swap_iocb *sio = NULL; struct swap_info_struct *sis = swp_swap_info(folio->swap); struct file *swap_file = sis->swap_file; - loff_t pos = folio_file_pos(folio); + loff_t pos = swap_dev_pos(folio->swap); count_swpout_vm_event(folio); folio_start_writeback(folio); @@ -430,7 +430,7 @@ static void swap_read_folio_fs(struct folio *folio, struct swap_iocb **plug) { struct swap_info_struct *sis = swp_swap_info(folio->swap); struct swap_iocb *sio = NULL; - loff_t pos = folio_file_pos(folio); + loff_t pos = swap_dev_pos(folio->swap); if (plug) sio = *plug; diff --git a/mm/swap.h b/mm/swap.h index fc2f6ade7f80..82023ab93205 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -5,6 +5,7 @@ struct mempolicy; #ifdef CONFIG_SWAP +#include /* for swp_offset */ #include /* for bio_end_io_t */ /* linux/mm/page_io.c */ @@ -31,6 +32,14 @@ extern struct address_space *swapper_spaces[]; (&swapper_spaces[swp_type(entry)][swp_offset(entry) \ >> SWAP_ADDRESS_SPACE_SHIFT]) +/* + * Return the swap device position of the swap entry. + */ +static inline loff_t swap_dev_pos(swp_entry_t entry) +{ + return ((loff_t)swp_offset(entry)) << PAGE_SHIFT; +} + void show_swap_cache_info(void); bool add_to_swap(struct folio *folio); void *get_shadow_from_swap_cache(swp_entry_t entry); From patchwork Fri May 10 11:47:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661459 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E6D1172BB9; Fri, 10 May 2024 11:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341836; cv=none; b=hUFwEzLWz6rYPwnWMYLhUg7LD7RIFhJtlMy8s2emAZF6Y0uD1AK1f0nvBrKd1fcQXJ77NwnWK219RWGzQy1NT0Td4ms2+U65vMXL1tlVR0AkdhjEjk1jNCZWtEMEOgRaHOvirnHoiHSncm1mYr/W04xqvSyt1BIunLbjxuhGOg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341836; c=relaxed/simple; bh=02q66uzfsHRLYNQh/pzEc3jR/80QOz2ISdwMRFlmOcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DqazhHaLs8AmSgQmr9y79pdylmpBN/RflIEVP9JAsl+L62Gq66lTexSAOUE4lzQcF+k2stFlU/bj76tbKqQ9JR4zx3erLUo0bskjq0qPutxo4aSX2Cxpps1ZMHXtQKb/ocbp0FLtGot40D+OIOarxqHzZHjSE+uHqOhK0cuv+OU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hVcQqjMm; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hVcQqjMm" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1eeabda8590so15183825ad.0; Fri, 10 May 2024 04:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341834; x=1715946634; darn=vger.kernel.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=APhN0fulocDUETiygz2oAEV3IjS3U4+qkKHyL+coV+Q=; b=hVcQqjMmmsuNq+GbU+TfmNjrCJQcZSJn6PGlHE0c17kHaHXTG+jtYsXZnhBJABOVQV 3HusG3Rue9rov47k3Eme5otilIjR5IrIXAVeUZQHQqf5tEHinjOI320OxGFw0gamYZdV orZztP4fzk7zZWsRzfmfNBTLk6qBnwjkMQilWKg4KYoT/+0SiUkH+s8ow7ZrLd+J5Q0Z 0avUYWVugtqcPlEBCiKuXrssUzygcEBkg6mVGBVaJ/enRPJQjglK8nxpph+cdc655I3C z+i5YgtcD4YDO59h7PkiIhJMaV6d7kDrS45sm5dZeqgqR/L5P5XcsvWakQw3sejzBcPK mCsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341834; x=1715946634; 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=APhN0fulocDUETiygz2oAEV3IjS3U4+qkKHyL+coV+Q=; b=EG/JWICGAs5tvP3SffOCehNLzKbDNLUYT0sbwaRLuNtMZLdWGuNBP1guynQ1oum5hT TfmhmAbQjdLpbVDab0cbmFTuOmrEJCTD64kcAvYrVXS328eX9T/KdzMcM6aSq90rKnqp 3+3IAm1QFPAhAwgHy5Y+L5RXZSY5fayjbv8neyYwcCILzFSAYnaVZD9tWUJ3VmUGjmCM vG+tQ8YH/bC1YLzCQoX4Rb2170j1luCtatXlgTMYOSS9Iu6SnpFmsXeZkRQdi6gRair+ bdkUrXdbHET2fieWNMOxlN46elwl9CKvXmq4V8aVbGZGkEwiRP0laVVEa4NqL7+WYnww iO4Q== X-Forwarded-Encrypted: i=1; AJvYcCWtWLjtkMDUp/hGX1XAS5thclvpkKuwlKiWuiLEBmY7yLEtlrf6Uc6kIubBObUApBnhwK9BryTCBDooHZmT26v6S70d2xzV1jhqFezXV8nYiSUfQRPWhrrCC14Ap1QFBp4dHdyCfw7DGTrzog== X-Gm-Message-State: AOJu0YzB5p4kbyM+xCQc7UR6ihyzFOHdiUGbcl9n4QPT40GkmZUYwijU 4FtjzX8hFAjXv9Hh/9mu26IOFLDfbDPu0kObCfQnI1fgQXHlyDeW X-Google-Smtp-Source: AGHT+IGRhm5V0At8lTwKdrzoZNWdcS6HhlYsyuvWhECri1epnW5oHdn3nfMF9ycJerAmcOjLLrBH8A== X-Received: by 2002:a17:902:720a:b0:1ee:b47e:4ea with SMTP id d9443c01a7336-1ef43f3d39cmr21286825ad.38.1715341834585; Fri, 10 May 2024 04:50:34 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:34 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v5 10/12] mm: remove page_file_offset and folio_file_pos Date: Fri, 10 May 2024 19:47:45 +0800 Message-ID: <20240510114747.21548-11-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song These two helpers were useful for mixed usage of swap cache and page cache, which help retrieve the corresponding file or swap device offset of a page or folio. They were introduced in commit f981c5950fa8 ("mm: methods for teaching filesystems about PG_swapcache pages") and used in commit d56b4ddf7781 ("nfs: teach the NFS client how to treat PG_swapcache pages"), suppose to be used with direct_IO for swap over fs. But after commit e1209d3a7a67 ("mm: introduce ->swap_rw and use it for reads from SWP_FS_OPS swap-space"), swap with direct_IO is no more, and swap cache mapping is never exposed to fs. Now we have dropped all users of page_file_offset and folio_file_pos, so they can be deleted. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- include/linux/pagemap.h | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 850d32057939..a324582ea702 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -918,11 +918,6 @@ static inline loff_t page_offset(struct page *page) return ((loff_t)page->index) << PAGE_SHIFT; } -static inline loff_t page_file_offset(struct page *page) -{ - return ((loff_t)page_index(page)) << PAGE_SHIFT; -} - /** * folio_pos - Returns the byte position of this folio in its file. * @folio: The folio. @@ -932,18 +927,6 @@ static inline loff_t folio_pos(struct folio *folio) return page_offset(&folio->page); } -/** - * folio_file_pos - Returns the byte position of this folio in its file. - * @folio: The folio. - * - * This differs from folio_pos() for folios which belong to a swap file. - * NFS is the only filesystem today which needs to use folio_file_pos(). - */ -static inline loff_t folio_file_pos(struct folio *folio) -{ - return page_file_offset(&folio->page); -} - /* * Get the offset in PAGE_SIZE (even for hugetlb folios). */ From patchwork Fri May 10 11:47:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661460 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 534F717332F; Fri, 10 May 2024 11:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341840; cv=none; b=A0AmsaIxQBzmHGuzdEtb/Z9JyyAWSfE0baPTa0/BanCRxodjR94CECL+y1Dmm3O6+AR2nfRCSMp1FZPx1CsweN1LuCWmsRRnlpz+epJgW+ie4nAg0fA2LT267Qi76a8KuM5defRMCaJKmalRL8a4hUVLiVaZXgaV9zJ25in4Vcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341840; c=relaxed/simple; bh=cQxK5RuRCLtqyLVJVvZvaYYBIKRw42XwWucH8wgPCGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qaXRUdcFmkbuUnPVqonOkCilpy9+i13achDSA77NX8A67IwSuIKVuBL/LfyPejx4JP9ZVz2BTPUIyPYZnA7SHz6Qr5o8+sIi7M+r6pzXIyVitx/Fad1eRNcye97Hlr4Zt4rGvx0BJdivaQnJsUtdmaX25/s1g2lHzKGPiLX1yDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Evlz2X70; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Evlz2X70" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1ec92e355bfso17200705ad.3; Fri, 10 May 2024 04:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341838; x=1715946638; darn=vger.kernel.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=on6kE/iT1Lkf0hlBPN696BIDabVjdoSu5WvxX7mut44=; b=Evlz2X70ozKPn+IPIHEJIFptFPuhTlGo4ocxQ3BRC4LswW6gsSjjnTU8ofIgYqrkKr e/twaafrzFWVKGqIJF34mzr6HSXTzzKOd7soIdmVfsNZZ8PacB+pI+BP1rUjsPvSG9+G KgpEo6mf+aOsCp+5J5IJBBfNANt/rNleeq1v266YbhMxHztYeryCwe/SKiACjWDWlitT hcv9ViNxfov+lJ1vrlbcoYzYpDVeH9ef6B95a/EykPXtBOcTGcjKnVPTbV+zsuRU507r NNhTv3z/Z0CspPig/ns33xvjhqA1hucyXKpRwVpfeqCbKzePlMsdE7Bu4DEYLwuKNgm+ EVKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341838; x=1715946638; 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=on6kE/iT1Lkf0hlBPN696BIDabVjdoSu5WvxX7mut44=; b=kl4KM9j3Wrp36guAvZbfirrdUeKKFNUWS6p6aiQ1jUnZ/j+8bIqY0LMRy9h4InguxU rgqBMn4YHdSv4U2pFuoI6+BA60XIMvs9BYnfjhiyN+uCesmP2Ldp+jqZFy51DvzCFpxk ORw9NrRgLoDOH2ZTcd2Cv8WU7XmAyM2b68fOorHaf1YKMGC7Qu9CKsD44z5yarLH5hGV xoB5CFnyy4KNOS5Ndk/3yJiIsV2xMbnKSttQSFEJc4ZmGgrLNSPfE+Ym9t0gH9NN/abV WvUCuGFknnqB9JEVUU+4PBr14NfNhuopS22Z9BRBHHFkqfsLxjTrk1HOF2xm1sabNASb n/8g== X-Forwarded-Encrypted: i=1; AJvYcCVsnfjUgKq9QfZSzp2FP0ddsD3PtzSQWTkLCYKcTsuvEIMyq9XNLCGLN+sbC1bEnz41E+mHm/QRWKvxziXoOdzjFasfxzHcVft6iZ8+cwbHH1YZVFrfQmDxX3qQJ8a0ox5DnuAVEk1qWs6s2g== X-Gm-Message-State: AOJu0YzpBiA+XSXXVjkaRtRhRQYSmCjFtBFh+hP+lf1TZSeA+RiobUA7 pRNZBqKnAuwkiADBCAYx/v5/xTR60AoDEJ1F3J6ciTJuYyV1iNTR X-Google-Smtp-Source: AGHT+IF1A9PqpbJrq3X5IQGwkaZ9z75WJ/x5Qis3xG1g8x4Md20mqXmUkOulbCkRZ+eLmOE6iEf86w== X-Received: by 2002:a17:902:d4c8:b0:1e4:d548:818f with SMTP id d9443c01a7336-1ef4404fb62mr28624285ad.58.1715341838600; Fri, 10 May 2024 04:50:38 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:38 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v5 11/12] mm: drop page_index and simplify folio_index Date: Fri, 10 May 2024 19:47:46 +0800 Message-ID: <20240510114747.21548-12-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song There are two helpers for retrieving the index within address space for mixed usage of swap cache and page cache: - page_index - folio_index This commit drops page_index, as we have eliminated all users, and converts folio_index's helper __page_file_index to use folio to avoid the page convertion. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- include/linux/mm.h | 13 ------------- include/linux/pagemap.h | 8 ++++---- mm/swapfile.c | 7 +++---- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9849dfda44d4..e2718cac0fda 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2290,19 +2290,6 @@ static inline void *folio_address(const struct folio *folio) return page_address(&folio->page); } -extern pgoff_t __page_file_index(struct page *page); - -/* - * Return the pagecache index of the passed page. Regular pagecache pages - * use ->index whereas swapcache pages use swp_offset(->private) - */ -static inline pgoff_t page_index(struct page *page) -{ - if (unlikely(PageSwapCache(page))) - return __page_file_index(page); - return page->index; -} - /* * Return true only if the page has been allocated with * ALLOC_NO_WATERMARKS and the low watermark was not diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a324582ea702..0cfa5810cde3 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -778,7 +778,7 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, mapping_gfp_mask(mapping)); } -#define swapcache_index(folio) __page_file_index(&(folio)->page) +extern pgoff_t __folio_swap_cache_index(struct folio *folio); /** * folio_index - File index of a folio. @@ -793,9 +793,9 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, */ static inline pgoff_t folio_index(struct folio *folio) { - if (unlikely(folio_test_swapcache(folio))) - return swapcache_index(folio); - return folio->index; + if (unlikely(folio_test_swapcache(folio))) + return __folio_swap_cache_index(folio); + return folio->index; } /** diff --git a/mm/swapfile.c b/mm/swapfile.c index f6ca215fb92f..0b0ae6e8c764 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3474,12 +3474,11 @@ struct address_space *swapcache_mapping(struct folio *folio) } EXPORT_SYMBOL_GPL(swapcache_mapping); -pgoff_t __page_file_index(struct page *page) +pgoff_t __folio_swap_cache_index(struct folio *folio) { - swp_entry_t swap = page_swap_entry(page); - return swp_offset(swap); + return swp_offset(folio->swap); } -EXPORT_SYMBOL_GPL(__page_file_index); +EXPORT_SYMBOL_GPL(__folio_swap_cache_index); /* * add_swap_count_continuation - called when a swap count is duplicated From patchwork Fri May 10 11:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13661461 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9230B173357; Fri, 10 May 2024 11:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341845; cv=none; b=bYmxLNU2LfV/UKKRHC4lhtozGyzJTQ9mb+Z+D1TjKS3wb5P+ock7vD9Ua5wHuCYrBi4Ni1LYI+sFrjD3IdP6ps8nZy676PVS8plCt9GxaoQ03ov20GE7bDuB2bc9eEwqoCol1+gEaG9vOpnUKQdeCTerhOQpXCCI/n6Rpevp3LU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715341845; c=relaxed/simple; bh=XKbzzvi+qCtp+Hx+PIOSmAXf0qnXM8zrJDdgKSBEd9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CNpN8VYE7RDv6qYol8pS3KApW/FIw5N76uadNSNCWfQgI7djQgBVzWRXdKbVE/+1UPbOXdAvdx7yYYmuTawY4477uZ34JCKj/R2lzv4h1WC3vEeSj6WkFkw2u4wWjnoq/gzg5WQozO4UioeNzpdJfOzYSFZOkMoYdQQN6H7st0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=begb11/H; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="begb11/H" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-61aef9901deso1463724a12.1; Fri, 10 May 2024 04:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715341843; x=1715946643; darn=vger.kernel.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=2cHgobIkFZqi9tZy8wGcGHO8km9uOWAjV7RKPjmck1g=; b=begb11/H+pY+FrCnPYvznKyRvMZpDS+4/ChRhKEXXYyg7JBoql+8fKfl31j+vObjuv INIM6WnSXhxpQUrNAvf0llYWyuq68RJ9rq5k3VPN7/FXKjBGC5hFgttcYTY1sAj8GXcn 0iNmKkwzeu6o0/TBD7tSLVVpCTjf52KTsvnhYxQ77FHpikFKpS931KDw2Zn1W/LB1MjY AAz6R8eGq67CixZSrF8sHn5xx/DDJ5OSbqhoNT929CHfbB7JeeL+LYyCUiGQWPERe7Cq Voys6bR0ErHDCSrALA83CiKNevzDBIyYvTZsoYUOfNBbELgHzYYW5bW5yw6rFAwYojdw hjlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715341843; x=1715946643; 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=2cHgobIkFZqi9tZy8wGcGHO8km9uOWAjV7RKPjmck1g=; b=up8Up7ymqOyVOiJo97tQpY+n5sbCKn8bwp3pFX0KhG2P4g6YSDWCXy9isk33PCyZEE ch9e77K0o+77Z1eAWjcj5zA6DvoAqRGxrA/xNN79YlRQAdGEy705mPhmkPKI5mvO9Z2K 1eRQ6YYjxqFuigMZD9MFfAAmYT+9rUUX1aEKsTAzLJdVXFVoPnrn1p/sThCb0FxgzSJ5 9BlAr1baQ/5zUFvcivJHOFrAAKRF5rKvEhPrfFOndjGgTKPasl9n1hrrZQNVWrQqZmMJ azUJU/ZHa52xxmqt4mKERV1dO0L1YpRC/Okn+xSN35AxDSMVR/7QfkNccKEnjnMb92q+ Kcpw== X-Forwarded-Encrypted: i=1; AJvYcCUxhvTYzOEH5pdM6SLEi8ozhume2xRnrX6tn4T7a3rLXdbCNcjCcVlcx9IoNBWIHIUJLR/CL8EoqaYzwrc6vRhfsxFsb/BkADtFhZnoV+I34SwHBaiRV8UUXsmm8IzcsOZ1KU5cBiL25pll8Q== X-Gm-Message-State: AOJu0YwCd3mWicubmr0WaVR236LJx584V2LI98b6weOaSMknBnh9E6PK tBVra8IO4nBAy5NXv9HV14o7OqgNQhgayplFV77mjzBMMdg2sIFg X-Google-Smtp-Source: AGHT+IGk029woWQIMSrmpOx6WkZvEeZxmkaZ13U9riSBclJ33JSyP7Sue0jUtAdVtSG6k8EJeM0BEg== X-Received: by 2002:a05:6a20:914f:b0:1a8:2cc0:290a with SMTP id adf61e73a8af0-1afde0dc8bcmr3107513637.30.1715341842750; Fri, 10 May 2024 04:50:42 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c134155sm30183825ad.231.2024.05.10.04.50.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 May 2024 04:50:42 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , Matthew Wilcox , Chris Li , Barry Song , Ryan Roberts , Neil Brown , Minchan Kim , David Hildenbrand , Hugh Dickins , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v5 12/12] mm/swap: reduce swap cache search space Date: Fri, 10 May 2024 19:47:47 +0800 Message-ID: <20240510114747.21548-13-ryncsn@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510114747.21548-1-ryncsn@gmail.com> References: <20240510114747.21548-1-ryncsn@gmail.com> Reply-To: Kairui Song Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Kairui Song Currently we use one swap_address_space for every 64M chunk to reduce lock contention, this is like having a set of smaller swap files inside one swap device. But when doing swap cache look up or insert, we are still using the offset of the whole large swap device. This is OK for correctness, as the offset (key) is unique. But Xarray is specially optimized for small indexes, it creates the radix tree levels lazily to be just enough to fit the largest key stored in one Xarray. So we are wasting tree nodes unnecessarily. For 64M chunk it should only take at most 3 levels to contain everything. But if we are using the offset from the whole swap device, the offset (key) value will be way beyond 64M, and so will the tree level. Optimize this by using a new helper swap_cache_index to get a swap entry's unique offset in its own 64M swap_address_space. I see a ~1% performance gain in benchmark and actual workload with high memory pressure. Test with `time memhog 128G` inside a 8G memcg using 128G swap (ramdisk with SWP_SYNCHRONOUS_IO dropped, tested 3 times, results are stable. The test result is similar but the improvement is smaller if SWP_SYNCHRONOUS_IO is enabled, as swap out path can never skip swap cache): Before: 6.07user 250.74system 4:17.26elapsed 99%CPU (0avgtext+0avgdata 8373376maxresident)k 0inputs+0outputs (55major+33555018minor)pagefaults 0swaps After (1.8% faster): 6.08user 246.09system 4:12.58elapsed 99%CPU (0avgtext+0avgdata 8373248maxresident)k 0inputs+0outputs (54major+33555027minor)pagefaults 0swaps Similar result with MySQL and sysbench using swap: Before: 94055.61 qps After (0.8% faster): 94834.91 qps Radix tree slab usage is also very slightly lower. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/huge_memory.c | 2 +- mm/memcontrol.c | 2 +- mm/mincore.c | 2 +- mm/shmem.c | 2 +- mm/swap.h | 15 +++++++++++++++ mm/swap_state.c | 17 +++++++++-------- mm/swapfile.c | 6 +++--- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 317de2afd371..fcc0e86a2589 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2838,7 +2838,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, split_page_memcg(head, order, new_order); if (folio_test_anon(folio) && folio_test_swapcache(folio)) { - offset = swp_offset(folio->swap); + offset = swap_cache_index(folio->swap); swap_cache = swap_address_space(folio->swap); xa_lock(&swap_cache->i_pages); } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d127c9c5fabf..024aeb64d0be 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6153,7 +6153,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, * Because swap_cache_get_folio() updates some statistics counter, * we call find_get_page() with swapper_space directly. */ - page = find_get_page(swap_address_space(ent), swp_offset(ent)); + page = find_get_page(swap_address_space(ent), swap_cache_index(ent)); entry->val = ent.val; return page; diff --git a/mm/mincore.c b/mm/mincore.c index dad3622cc963..e31cf1bde614 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -139,7 +139,7 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, } else { #ifdef CONFIG_SWAP *vec = mincore_page(swap_address_space(entry), - swp_offset(entry)); + swap_cache_index(entry)); #else WARN_ON(1); *vec = 1; diff --git a/mm/shmem.c b/mm/shmem.c index fa2a0ed97507..326315c12feb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1756,7 +1756,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, old = *foliop; entry = old->swap; - swap_index = swp_offset(entry); + swap_index = swap_cache_index(entry); swap_mapping = swap_address_space(entry); /* diff --git a/mm/swap.h b/mm/swap.h index 82023ab93205..2c0e96272d49 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -27,6 +27,7 @@ void __swap_writepage(struct folio *folio, struct writeback_control *wbc); /* One swap address space for each 64M swap space */ #define SWAP_ADDRESS_SPACE_SHIFT 14 #define SWAP_ADDRESS_SPACE_PAGES (1 << SWAP_ADDRESS_SPACE_SHIFT) +#define SWAP_ADDRESS_SPACE_MASK (SWAP_ADDRESS_SPACE_PAGES - 1) extern struct address_space *swapper_spaces[]; #define swap_address_space(entry) \ (&swapper_spaces[swp_type(entry)][swp_offset(entry) \ @@ -40,6 +41,15 @@ static inline loff_t swap_dev_pos(swp_entry_t entry) return ((loff_t)swp_offset(entry)) << PAGE_SHIFT; } +/* + * Return the swap cache index of the swap entry. + */ +static inline pgoff_t swap_cache_index(swp_entry_t entry) +{ + BUILD_BUG_ON((SWP_OFFSET_MASK | SWAP_ADDRESS_SPACE_MASK) != SWP_OFFSET_MASK); + return swp_offset(entry) & SWAP_ADDRESS_SPACE_MASK; +} + void show_swap_cache_info(void); bool add_to_swap(struct folio *folio); void *get_shadow_from_swap_cache(swp_entry_t entry); @@ -86,6 +96,11 @@ static inline struct address_space *swap_address_space(swp_entry_t entry) return NULL; } +static inline pgoff_t swap_cache_index(swp_entry_t entry) +{ + return 0; +} + static inline void show_swap_cache_info(void) { } diff --git a/mm/swap_state.c b/mm/swap_state.c index 642c30d8376c..6e86c759dc1d 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -72,7 +72,7 @@ void show_swap_cache_info(void) void *get_shadow_from_swap_cache(swp_entry_t entry) { struct address_space *address_space = swap_address_space(entry); - pgoff_t idx = swp_offset(entry); + pgoff_t idx = swap_cache_index(entry); void *shadow; shadow = xa_load(&address_space->i_pages, idx); @@ -89,7 +89,7 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, gfp_t gfp, void **shadowp) { struct address_space *address_space = swap_address_space(entry); - pgoff_t idx = swp_offset(entry); + pgoff_t idx = swap_cache_index(entry); XA_STATE_ORDER(xas, &address_space->i_pages, idx, folio_order(folio)); unsigned long i, nr = folio_nr_pages(folio); void *old; @@ -144,7 +144,7 @@ void __delete_from_swap_cache(struct folio *folio, struct address_space *address_space = swap_address_space(entry); int i; long nr = folio_nr_pages(folio); - pgoff_t idx = swp_offset(entry); + pgoff_t idx = swap_cache_index(entry); XA_STATE(xas, &address_space->i_pages, idx); xas_set_update(&xas, workingset_update_node); @@ -253,13 +253,14 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin, for (;;) { swp_entry_t entry = swp_entry(type, curr); + unsigned long index = curr & SWAP_ADDRESS_SPACE_MASK; struct address_space *address_space = swap_address_space(entry); - XA_STATE(xas, &address_space->i_pages, curr); + XA_STATE(xas, &address_space->i_pages, index); xas_set_update(&xas, workingset_update_node); xa_lock_irq(&address_space->i_pages); - xas_for_each(&xas, old, end) { + xas_for_each(&xas, old, min(index + (end - curr), SWAP_ADDRESS_SPACE_PAGES)) { if (!xa_is_value(old)) continue; xas_store(&xas, NULL); @@ -350,7 +351,7 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, { struct folio *folio; - folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); + folio = filemap_get_folio(swap_address_space(entry), swap_cache_index(entry)); if (!IS_ERR(folio)) { bool vma_ra = swap_use_vma_readahead(); bool readahead; @@ -420,7 +421,7 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, si = get_swap_device(swp); if (!si) return ERR_PTR(-ENOENT); - index = swp_offset(swp); + index = swap_cache_index(swp); folio = filemap_get_folio(swap_address_space(swp), index); put_swap_device(si); return folio; @@ -447,7 +448,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, * that would confuse statistics. */ folio = filemap_get_folio(swap_address_space(entry), - swp_offset(entry)); + swap_cache_index(entry)); if (!IS_ERR(folio)) goto got_folio; diff --git a/mm/swapfile.c b/mm/swapfile.c index 0b0ae6e8c764..4f0e8b2ac8aa 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -142,7 +142,7 @@ static int __try_to_reclaim_swap(struct swap_info_struct *si, struct folio *folio; int ret = 0; - folio = filemap_get_folio(swap_address_space(entry), offset); + folio = filemap_get_folio(swap_address_space(entry), swap_cache_index(entry)); if (IS_ERR(folio)) return 0; /* @@ -2158,7 +2158,7 @@ static int try_to_unuse(unsigned int type) (i = find_next_to_unuse(si, i)) != 0) { entry = swp_entry(type, i); - folio = filemap_get_folio(swap_address_space(entry), i); + folio = filemap_get_folio(swap_address_space(entry), swap_cache_index(entry)); if (IS_ERR(folio)) continue; @@ -3476,7 +3476,7 @@ EXPORT_SYMBOL_GPL(swapcache_mapping); pgoff_t __folio_swap_cache_index(struct folio *folio) { - return swp_offset(folio->swap); + return swap_cache_index(folio->swap); } EXPORT_SYMBOL_GPL(__folio_swap_cache_index);