From patchwork Tue Apr 23 17:03:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640378 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 78C0713D635; Tue, 23 Apr 2024 17:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891838; cv=none; b=ZgdSY2bMJy5Ej6YOPEwMsqR3mZ3DOzMSZlaAhY2nb5pSzx6Bf9CGSjmp05ifo3iD2qeSUVTghvsgckWBawzRoid725HE6fbgj0z95pC8Fe9EKdYvDHY2QMnQrIA8dvTXHrJmN+FNEw9xJIW/qIYBipjxvdglTcwQK9x1ajJ/EDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891838; c=relaxed/simple; bh=pMXBuRSYRvxJ/Pm5/D0Ih9VGkrkcDFfmsJy8ADz5Yxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tALBB1kQ3qA6ZHOi/6cPi9ds7dR8pqTYB1gftb2HXxLY2VZ6ykQRN9FugPjVE7F4qC8NHI5nW5nptKV3XgMtlZF95wEoNEFNTr+t5yFK+Dnt7ct5O8xva/1HKmBMDGdWNXDjLn8isz38Wtrjon/B7TUydwLyPjPasJEQkHDq/cQ= 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=jZykjQRt; arc=none smtp.client-ip=209.85.216.41 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="jZykjQRt" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2a559928f46so3877789a91.0; Tue, 23 Apr 2024 10:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891836; x=1714496636; 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=BixicrujN2w/NN7W8Yk1bOtYDD16jf87ysiCrI+mjZw=; b=jZykjQRtlxsp8nD4pOJ5uzQhDja3LTfe9CXKa8lo7w/ZlAUf7TJrOBMK+9wuogOR1B SuyZYseHTkKj6qwJ6auL0Uyz0axVqqpWVwg4LZGNWkhVT/n52E2ux8PBgLlqYpmyBA05 Cg8Q6IFDt3xW1hkUDarpp6xystB9/4W9A2OB4sj+mDckPcIX8BqfuEQ2lJ0YODLSrKL0 9M+iEvn1TqSD75CgrQC2bHwnQWBI2aB2e5qfgd5Kg/2WErQJfqiWnXUaATIoh6a62P2/ q5vWLTHxrrLlhMt/RDrWPjSSk1LvjDCLLWD7my4IhCarwOXpOOvJMDRussGKYQENBm2c oqqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891836; x=1714496636; 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=BixicrujN2w/NN7W8Yk1bOtYDD16jf87ysiCrI+mjZw=; b=NFc48+q07nvxQI/nNZxeHmlp4TZUhaDhIyX2tMUDBoPpBoNPeULccPApPYdPPyx/XH DXxnj/+RszA0NjX/CpEhGKfWh0xERdlpt0mAuf4Lh24+GWcSdHTMfYq5Js1IxQTPlyc8 3pJDBvwKk5FQ8ZHVAXFKHMHFfBNS3AJdeQpK8TDNfPaa72b6VyarwOq9bGyutlIVphXe Sn4Iw8J6LbFUAULUVCwocp1PX30+bNNKOtZiE21qJiJjhxVk85fa5yWiwBl0ZYYFAzJb EHZgDa1XoHFyKLsf+tiN+Sq4yfkloNvGp6XF0cQDwLgwsmw/Rjn5+3zMONNei7n2QqWx U/bA== X-Forwarded-Encrypted: i=1; AJvYcCWWYXrGV6gqEvqvggbN0U+gYOyFCJaYcMf3rfSxjbJcNHF+9ozSYg5PPqtP49BZlB7AT6tgQzk1JpO9o5bMARckq7ZDKt7Cpq0JACD736u6+yHYZq6okokNdBHbWYZiXAQFHVWy7GKDdN2hgYgUBwdriJmy1+qQEmFTEecj6aCg+YhYqlHeHA== X-Gm-Message-State: AOJu0YyJBSfaeO7F9e65v0ZNCCBv/vWdYjO9LE1AaiRcpnz+jyja3R/m /LMRvYHbV1+UgG1Wu0slK0EjJP0Er4mt+95061mUyNlmOHpfNEyP X-Google-Smtp-Source: AGHT+IEZ4GKNo+ZGTgIioZ6E8Q2/FLCJDMv5q/lYaYPH5b0i9NhmaYmcUV6iKdtOBuu19Rf+VfV0Ww== X-Received: by 2002:a17:90b:1205:b0:2ad:c098:ebca with SMTP id gl5-20020a17090b120500b002adc098ebcamr7093107pjb.20.1713891835397; Tue, 23 Apr 2024 10:03:55 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.03.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:03:54 -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 , Hugh Dickins , David Hildenbrand , 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 v2 1/8] NFS: remove nfs_page_lengthg and usage of page_index Date: Wed, 24 Apr 2024 01:03:32 +0800 Message-ID: <20240423170339.54131-2-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 Tue Apr 23 17:03:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640379 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 8825F13E057; Tue, 23 Apr 2024 17:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891841; cv=none; b=PXGqUV3dEX3GEkvSAFNKI25HcpvEU2LN1C7Zy0G00kl0aU0bIXtQBIinZnk3KDWAI/gzc5ixV2Af8wJXTSNNswz3xMFPsJf4xj/ep6OMK055VAZQD6otvLh7kqjXMx4W0aY/nDEl/qVMDtE0rcQI2NIFPgUPd+3sW81h+ODyX1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891841; c=relaxed/simple; bh=Uyce+dc3t6E+2F7Kun0sqcdJkKyU2ngW6vMHcIsFCvQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tct6ryTyJMpb4orilm0cwG47EVe8FeE896aBKpVn1NOpt+ppLUbPG2q/wiyFg25obXXjXaDheS3QYSm9G4XoUfP+eOksxU64Fc6sM64WXK/iY90d01whzwJCxRMbMaCGBDs14jauUhKm5VZv09K2IZCWohY0iqmNYmpaHXkZUOw= 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=OCFP2ODN; arc=none smtp.client-ip=209.85.210.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="OCFP2ODN" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ee0642f718so56017b3a.0; Tue, 23 Apr 2024 10:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891840; x=1714496640; 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=YfpxwnN8CfoAe7aR3YgTjEdl37ZW9GmobE0CddHnTJA=; b=OCFP2ODN36AyfHCRosaPabwYhrhVdgjZi9lQb/qWno2ZbQ5JXjGHPEA1UQPTHNcvcN A62jdVQCEk7JA+LyZlLwLpU3ZVc4apy0WJcBTquV5seDzcgUjcQ/K/M/rwMfXGuypfP9 9nv04vQZ2lEN+95Bg05sBOk7lakWcdEiCnHN0t+jOP1b36kpetnd59MqCHJw4Tdqd/kx gPdKrlIZZ7Ex33o0dvO5DHd/a3AGO1ZNUJDdIZFvED2q7nwP0kPdhrsK5kujSTizZYry x6jNG0WNyF+1pS9c3/nCVjHWbsazdk1z2FurhTSyH0gNjnV7YUpTD0T1mPYzBp5SJnn6 6soA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891840; x=1714496640; 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=YfpxwnN8CfoAe7aR3YgTjEdl37ZW9GmobE0CddHnTJA=; b=XkxUIRUFIEaxaaeP1EcGeGS3CndOUGCLV/wOJQceuIZX+Y/+LH8Z6mXEWqa+gmh45P mYDnPa27ymTlsNzwy/odx9oN49KKbY76oayI8NBSsUZVlXXNgAANuLIpa7d6mHu9/FRm mowF9WkHQ/eLhuYHJSHvItRuQlWVQe/F32l7g9/u+JmILLLyMlkhhuYjAhLmueQyHTkL IumMukUu4eOB5A5SjQQcxon3DQFBge3FGLPgqshKaGFdns5RJRtZkxWKc+PuWPjIcsZm B++gMO/w3Tl3mZKcvkxP+oA/zoqFme5gHUAzqCSJyeglwh++oH9bsIiPy2gJKsUQNuSB +atw== X-Forwarded-Encrypted: i=1; AJvYcCVesD5poqBCes0urYixToMHi8rQz8xfgYu7txzyjNAZsFY0EfTdxlmiBdevULHgQuAkxqTDB1O0Fv+fiITUIq6Lm8jQTNERtxBkoURxV6tjGoKkKOjWYsl/GvROSATHcSaqjujrq+QIOkqn5Q/3QcZOBHGSohXHoAek4ZejCzYRHXqMnC3e6OK6 X-Gm-Message-State: AOJu0YzIUajgjT1oDe/EPC+E3iRLmnW3OEJ6oDYh5JFfGfblu1bhhfPD VbgUutACNUb+o+K0hVm8H50T5EfNz8YXxKDzaa1Tz3cLlVOO61Tq X-Google-Smtp-Source: AGHT+IEWWHhF19ksGF0RHc9H2/SNsHmOpvGzFHUqvC8eQ1hIjSvMBjQypYUZq4AUNd9PZKflJXxjrw== X-Received: by 2002:a17:90b:815:b0:2a7:8674:a0c8 with SMTP id bk21-20020a17090b081500b002a78674a0c8mr4130992pjb.1.1713891839853; Tue, 23 Apr 2024 10:03:59 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.03.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:03:59 -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 , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song , Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v2 2/8] nilfs2: drop usage of page_index Date: Wed, 24 Apr 2024 01:03:33 +0800 Message-ID: <20240423170339.54131-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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, also convert it to use folio. Signed-off-by: Kairui Song Cc: Ryusuke Konishi Cc: linux-nilfs@vger.kernel.org --- fs/nilfs2/bmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c index 383f0afa2cea..9f561afe864f 100644 --- a/fs/nilfs2/bmap.c +++ b/fs/nilfs2/bmap.c @@ -453,8 +453,7 @@ __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap, struct buffer_head *pbh; __u64 key; - key = page_index(bh->b_page) << (PAGE_SHIFT - - bmap->b_inode->i_blkbits); + key = bh->b_folio->index << (PAGE_SHIFT - bmap->b_inode->i_blkbits); for (pbh = page_buffers(bh->b_page); pbh != bh; pbh = pbh->b_this_page) key++; From patchwork Tue Apr 23 17:03:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640380 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 35CA14CB55; Tue, 23 Apr 2024 17:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891846; cv=none; b=MtS1tw1sAFUwVwPonDL2D/rAcD1NK+Y6DEypY/t6/biSUHCiG7GX1CuUqM/El/eW+oRof1N04Tp4k6HO7EXAWM74dxYF9CfSMYn9vsk2EcKGskMU1vy4w1qBIOQAPtiYkl47fUqa/EHtnEwW+oL9EsU285cdybCtVz9yCWxoHEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891846; c=relaxed/simple; bh=UaTaQyDAPYJXzxuGE+S2wWuP7fLVM+PYcfLn2sBx5RA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bjqM7LS2Nf3qz96CZpm3uM2aawgjmZxtOR4msuPps9rUpGJ8kzMZIjCSfeBxM4aGyMCxcE6Xt8rHDk6XgWU3AeUYX9HW1868vJG3l85VGb+cmKJhIpCxhFJkCZz4J5yJGW9dHX7kJwGte885iBXZ4RO4AHp7FrYwH9uoEiGSvD0= 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=gUtsxvPc; arc=none smtp.client-ip=209.85.216.43 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="gUtsxvPc" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2a58209b159so3913749a91.3; Tue, 23 Apr 2024 10:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891844; x=1714496644; 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=ccxP7TY1LZd03lAzTUSjd/WMiiw2l1TFGZjibmTvaRo=; b=gUtsxvPc/b7Tv8Lie0u04p+EHBvjcwrWMZl/IfuAh41zxDpsMykv3ToPAWt1o/15ig xamnLWhwnuVI99FCWuSd/r5HfIoDm38gs70uaxRKwKeoF/bboOr0nafzdDGt3tem9dcu xy8q9B+YkxNmznJ7CJOpUYyInJX4JfA5VRhnEZ9xHTN4zq0CH4HwPkoc/mj9dOpumnvL BxzRsQlRSYY6+QKJsbOYfqYb/gCexIll7jObAoD62DB4tvl9bx3nmSodMBHm1ky/ZgPO AUlfpvteMLuyPBJIjzb6p3wLLOM6jS5QSZNuNMWYV4M9of89DLIjC8E591EDt8r+pDNR cQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891844; x=1714496644; 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=ccxP7TY1LZd03lAzTUSjd/WMiiw2l1TFGZjibmTvaRo=; b=f7+5QtPTW3N36DioN/woV2DFMCCVjjR1tayr63YWBO8nqfA3ngYZNbK9rt3PS8LM9t twgV5wKUNjpM3JF7x+pIYb5fEhK/tFDdxp+uKtEDAJFpWcgiMkFQzgy7czl+7IYuPia+ rVmAFQSxP42KA62kRyDKgMJeo/3qKpr4vgWbQ56vsYod1DuLhAOpGn41hCZ9smDlL7Wg fHNw8ju8CdbBEJ2PegVimIpm9AmVKDR31Ub7C7Q7gXzZ0Noaj9/a2Y1GqmW0WxmeZQVF rwWyR8UkGg/8TRE7yrwdQR/KPrgfGNZ3VHEm9nH7oZi5UBHT/FquBqytD3Fs15swcVeU 9C0g== X-Forwarded-Encrypted: i=1; AJvYcCXBK8sYVBardR6kj4bT1Y1ZUq5CDVgnwppcKnMxYE6mMXhIuf5Fj2F6AyQnid2WbNYIGqBWcWlcA1p0wdmvs1iPjczXsNN/wLCjvkwMnMtT35C/nCiqvDdn1fNsFk1fYm+sx69wufLj/xDrlA== X-Gm-Message-State: AOJu0YwSN6Gtpxn2B/KiuvfXYvkPh8jLyHol87O9851DK71+0j6xf0We XFMyp79K7R8t/CCCJGYiSKmTn4A+zQkNgYT0VMxLODar/28rvQ7R X-Google-Smtp-Source: AGHT+IFl9PJyw3gV5yMYnps/pmPpaL5DbNMyQbbzhrOpZIakLlc/OOAGq7K0pRF3PyTBE2M2iwLZlw== X-Received: by 2002:a17:90b:238b:b0:2af:15db:c741 with SMTP id mr11-20020a17090b238b00b002af15dbc741mr325358pjb.13.1713891844299; Tue, 23 Apr 2024 10:04:04 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:03 -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 , Hugh Dickins , David Hildenbrand , 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 v2 3/8] f2fs: drop usage of page_index Date: Wed, 24 Apr 2024 01:03:34 +0800 Message-ID: <20240423170339.54131-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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: Chao Yu Cc: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net --- fs/f2fs/data.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d9494b5fc7c1..12d5bbd18755 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); @@ -4086,8 +4086,7 @@ void f2fs_clear_page_cache_dirty_tag(struct page *page) unsigned long flags; xa_lock_irqsave(&mapping->i_pages, flags); - __xa_clear_mark(&mapping->i_pages, page_index(page), - PAGECACHE_TAG_DIRTY); + __xa_clear_mark(&mapping->i_pages, page->index, PAGECACHE_TAG_DIRTY); xa_unlock_irqrestore(&mapping->i_pages, flags); } From patchwork Tue Apr 23 17:03:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13640381 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 EBD1013DBBD; Tue, 23 Apr 2024 17:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891852; cv=none; b=ee2TKrxYujMYhuYqVs6ccpbYvzispaz8hLmQ48ev/O3jMSBmoCO1Z81IiJ8aNk5B8St3cvIV27S7FuCzeg+eTyc1FCf5vO8jqQXAXQaGkvyEsWAP5pn48IQaTn2octElxjIoHsfiXu46tm78rNUirvnrmMR9X8C4yjTC81gn/Uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891852; c=relaxed/simple; bh=gNeowpHLn3XanGMjOPlcSsZZHe5AP0lM6lADWQVCs4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VUJbxRKusAwoHyeNKNoTj9zr4z5MO6LLOW5dXZ1HQ04nnvv3F9JtxrPtrSWb9K3w3Q+o8lpPj5BSE1MDmg48Yjdw4BotGlJkYTfOIRtcNHcf8AhQ7mE7SGtR3Ot30NykAZzSQu3bvzN4c/8NCuWfYX5ji+2HVyuhDctK+RjI1XM= 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=hssLaR8M; arc=none smtp.client-ip=209.85.216.54 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="hssLaR8M" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2a528e7f2b6so4175372a91.0; Tue, 23 Apr 2024 10:04:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891849; x=1714496649; 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=5+IkB3+J9K42d+V5Wi+AdhWpwnXMtEpYhZXm/5fw+dM=; b=hssLaR8M2lcyrOpNUFlmgrj2Y1T5SXrRUj1lifpeOb+bkPn5xghGzVuGTD0fcwFw/C unEJ27qIxjTra/3Yq4pIlQq0KOj7GOdTeQTHlfzoLmaw0cq1RfaENtJuMSa8Ylxeib3m N/651MyY4GhWYmnbq/KzY5S9EUeiIpNQ0S+Z917obAvPFZ+zzczLtH8fA7Oyw5q636UB fzVk997y+XC14gNlnQDn0O8AEksrF0Twtd5h7JVclZWQZky7KR39XWMyjLYZlT5hYCB0 ANm5XYqs336VFDPVV6n/bdiNVZt8os+DjX2m5xLurp5VERemGO4BXKii4NkIFZsrSRcq LjFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891849; x=1714496649; 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=5+IkB3+J9K42d+V5Wi+AdhWpwnXMtEpYhZXm/5fw+dM=; b=n3Xz/dpmak/UPdzX3OBml2IqWyoXZVOnhnLNv/yOJE9RJouqJXnVtc3yxCBS0Rrjah mZU1V0uNDdbREPmjgpf9HPvivsYpXxZZhIYruh+/ZLDPtljWVpsQkJEhz/CZRUcUtQ9D WnFxaMYGS49PNlvhfkq1kzFVBfVhT24jJJ9hmeUYTJL1vA4PIAHnJQKBepnDPrdlKGRI DR2UGhl4FD56oauDfFCHvR0V5YFDW8V3aaJL8vGVbGHPxF6PfjBLfyDNqVRZdcgh58ED 8hEir4weJ7IqakGwR85vD073QK0ovDC4+lid4amx9/ffb32KTQ7mmJDEfU9G4u89UCP5 N4kw== X-Forwarded-Encrypted: i=1; AJvYcCXZMGJVDmXK6Kbcs7ht7RgFAcux9fBEfZRkC6PT4KwxvzzeGR/2fTNKoTMgO+xW0wFBt5ATrkp/Rzl6OAWV9k2BqCJfKz5DJpica/yRqSxOmc4WF4+ZwKoqzMTGaYq2TyreGPFhrODa1aKyDm7+Ylrosz+heG9a9BOlJJ0r8AQyUsISEuP8NvM= X-Gm-Message-State: AOJu0YyZtYEy1AAdgeB5uPALHWiptbSB4lsVLLwDLt3YBf9WwJzFgi6D pkl0Dk/+TCGRSfby7SJ2juQue2TrLHW2XG8agkUjp6XFEbJBUGsV X-Google-Smtp-Source: AGHT+IGWT+ho4KjjKYkt4pXE9QMNwfjSrpJN8MJZvcmr2D9GT4W4gI0wGDBUlpVmvv4mlpFse7FLPw== X-Received: by 2002:a17:90a:cc0c:b0:2a5:d979:8eb2 with SMTP id b12-20020a17090acc0c00b002a5d9798eb2mr10816827pju.19.1713891849092; Tue, 23 Apr 2024 10:04:09 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:08 -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 , Hugh Dickins , David Hildenbrand , 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 v2 4/8] ceph: drop usage of page_index Date: Wed, 24 Apr 2024 01:03:35 +0800 Message-ID: <20240423170339.54131-5-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 Reviewed-by: Xiubo Li --- 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 Tue Apr 23 17:03: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: 13640382 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 A5E7513FD8E; Tue, 23 Apr 2024 17:04:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891856; cv=none; b=EHA1ojLtTe52bCevRJN+brZVDGtn1DVXl6cT2McJFJZR9k84nLLeJ8xo66niUrDGl4xVVHnlkHdvwQaUViub8HiV8ixAKYIXnK9h4aKJxVqpqmi19BAS9TLsj6B5lX4f6htJP3nyAG9uF/2xfFABF5A80x/aEiqJ76nyVsYROB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891856; c=relaxed/simple; bh=A57oBviTsoYjvGYijwaaVR8klkIuYTbTGJn2TKpAIPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SLRc/6WJv1Sr5fuv/IxBcfc7U9Fr4v6vQ1X57eoS89IR4frvht9gt3PYfTpbhdTl9/SIdfSd3it+qmNmYVHlm5VEcYO2v0RHOp8imJ1rP1SMKjTewiixD52bYmnmCYNNRgoYhFb+dVd1L6cVcHd2L8eIwSoTGomV9paOW8KCiAo= 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=cY0iuuZI; arc=none smtp.client-ip=209.85.210.172 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="cY0iuuZI" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6f074520c8cso5684582b3a.0; Tue, 23 Apr 2024 10:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891854; x=1714496654; 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=GV/G4qXk1onz2IqC3/BpNLYGtgLEbJph1C4Exu3LQ8Q=; b=cY0iuuZIDNefQz9fq65tOzjKVUMeMnXLAmJ4VOBkCRCd2Oc5MDZ7fiek0SJwpdnOv4 SP0yV4SdnrTRSlIH0hpKXoIfNPFAsRCQTkThEajX1gTtQ16dmkN2KqNL6aWmSjmborrj HWi2Nv9+KPsiG97jwVkfEaqwNoxLnf1BpUPtGIDR8YT1JZpcYnjgjNPq+dW+e7p1oiNL BH/uOP9yYYoRwW9FlFBVJoCZf2eJ9vk+W9yqPjfXx9Tn94B7yuClxmPGZAbGjdj35530 QZ2XGWtsakVZpqF/NnllGx8BXUgoyZEdClTmbjn4U9suIUOA9+Vx4Twww3YtmKsOz+uC 1MoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891854; x=1714496654; 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=GV/G4qXk1onz2IqC3/BpNLYGtgLEbJph1C4Exu3LQ8Q=; b=gXOD5n6D7uNY/sLVpPwImHINbC8Z1LHoudECkylw8RMZAJF+XNarTzx5PZJ4VG6K5e f8iovzxm+i/02zSf1niUhBOVqn1BOiOeT72g5guOTdpg1h4eYSR1uAKqbO1qzHYsBN6g /+73Cu7FTj4pXlfp5DnAUa7wzAY4oFbY2U/34IOaoYSwyYeGOv6N+PtwjAJgdKwQsdxJ eHvZ9PAGxQDIk2Kx0HAb/nD9bXg2XiIMBzYtB4QNMh8qxYG+E/RKKTzJRFLkWrFxvXEx CRJCKi6I2rhuhmvv1FD28WwancSfcGWCt2UOjYJwGu9GamCQiA7JeQ4B++cr/lVDnAPb uXOw== X-Forwarded-Encrypted: i=1; AJvYcCU1sBnuewWO7bKhDrgQotuWiEwMp+ENgQS0H15X82/oSf16J7q9PNgu2L4Hye9wxPEjTFbqaBKHxgMQEpxaE6v1sKMGXREFX5/OkDxLTQ4zIzXywDXU8Xzz/fjOmAcKVJq7zON8i4ayjSyOKQ== X-Gm-Message-State: AOJu0YzjoaCaZo7NbDoztb5rbXhdJ3dQQw7BbO3xonxhfUY9yrz8VpDw TO5Cb8hsrnd9xmvegPqpGqRI2EvH24MmhkgGIFDSZoBkyyPd7LcgkeQrx5iOl1cNEQ== X-Google-Smtp-Source: AGHT+IFXnXzggSbP9Ki4cPzdCkuwcEVn65pZLG0YlEPbx8oPpQU9xrUurI5P4h73FEaKFW5G55uUNA== X-Received: by 2002:a17:90b:3796:b0:2ad:e055:bb34 with SMTP id mz22-20020a17090b379600b002ade055bb34mr6180074pjb.3.1713891854019; Tue, 23 Apr 2024 10:04:14 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:13 -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 , Hugh Dickins , David Hildenbrand , 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 v2 5/8] cifs: drop usage of page_file_offset Date: Wed, 24 Apr 2024 01:03:36 +0800 Message-ID: <20240423170339.54131-6-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 Signed-off-by: Kairui Song --- 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 16aadce492b2..56ebc0b1444d 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -4749,7 +4749,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 Tue Apr 23 17:03: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: 13640383 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 C2A861411E0; Tue, 23 Apr 2024 17:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891860; cv=none; b=hOMCSkK899i/dQpcWVAJ/KdVwT1XE1tSo4AfP6d3fQhTe5V8fmpVg7tqfuTVwY5d34VLekNzynfg3DOcolhU2eXt8Qh0Xbui/vI2GRygaqJSsRimubz4PIlVTfDppNepGW+vQsLafgQKwUam7b0PvzZqrtnaSD8CFa848WfyZRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891860; c=relaxed/simple; bh=ZHTQ4D6mBwXm8rBHAXZMODNowQ4ZDuM4+W3lPfOCPV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IFIeeWhAaoRpemZ6eTMxeYU8JSXxZEbD9jnWchwKrtML7BBP2/0KGTthDCkM00W7puuXxj+ESoiQkPE1Jgne7pwzTuhfDTbH2tOHZA+OXCv6rZCLSo1z3/ne13VOeRTk/A8Yad21Md1KTNvTPI1B8GVrKemlAo4ZdJfnypULvs0= 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=S/NZJ2jJ; arc=none smtp.client-ip=209.85.216.50 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="S/NZJ2jJ" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ab1ddfded1so4913034a91.1; Tue, 23 Apr 2024 10:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891858; x=1714496658; 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=KNG88VEX6ymli+8A661y92lZCXehoPGwKzjIttUG4iQ=; b=S/NZJ2jJXPa29jNRwA6/W3nIShrL8rqUy28ADap1Ci+2DWunTUIm+TSawJQCrzRrIE xsmRvoR6bNknhgt1YnDgy2tqwiQ9VnzyKaBW05o39/AYv0Dr3TGpswPT0FPvZOaWBhjv vyWEndoRVSleExwfZM0zYTvZlz93v66xZt6ZCVf9T6O+/uBllDf89gcoGOJXyXXZuApf y7VckDNgOmPTUQV8gX20N+3YgWr2VXCpM81U49rD/LPF6LX+He3jfCQwAxR4ogSEbHr/ Jd5cEIx/aa9X5MaSYSGTp26a8u7PjNRwPHbwrbYR/XYPig8WcWFcTloprkmbZmp9ELbC 4rBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891858; x=1714496658; 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=KNG88VEX6ymli+8A661y92lZCXehoPGwKzjIttUG4iQ=; b=Rn+SQtuL1AP3QOgzMrwryollp1CP9TtLuwgGQRnLVqo3eZFgep/iVGRI7Zz1w0+chj yqV6cgdFXZP8IyYMLcp+GDGEmQ6g6fzNSw27bX53VfNuIInY0EYU0ym1O8AAh03JL5PY hKSIPBDP7WUDvwIbr+9K/R4EKVgbJ6zzVtuCeHLoD0GmZ4D5vJvxffctB13sROggAH9J WG9Nnh0eF9/dwiD/P2cs1IvjzTqZI/iUE+8e0kXvBZmKkAD0MIQHYHMJax45fr/yH51/ mjXAkZ6taWp1K5RWkGl8vCzGJHkeS2MutbN3DtCVkSbWthjOhH8oEE/2YkgBPM3z7FfA cXxQ== X-Forwarded-Encrypted: i=1; AJvYcCU2nkNX059+L4RuJvLfFdkjwa5z7irfiN4HVzLnM2WJcLjV7+aNrdu/+xCc1n47yXZO4W5kzQpCPwbMPBQ3M0mtiGy7Kj5BZP51u+osBSlqEHnl329NVGjX3BPMkoVlQIWT9go+xEnC9hnd+Q== X-Gm-Message-State: AOJu0YywwC+Rg4qKdGo3IOrvUlmDBvz/KP4WbAHPDXD7Gutqg9ZFRboT 7Wx9wYbQiYV7tncSJ/NkjyhzSytxVSVhCRGjHDbuTV+Nzh+EbVim X-Google-Smtp-Source: AGHT+IHXKQ3glHiIimSKVos8NC6ThIL+D5to0mzqdpKPEwEZ9osxyRN208oepV+c07VYuM6yym9TLw== X-Received: by 2002:a17:90a:7847:b0:2a2:981b:2c9e with SMTP id y7-20020a17090a784700b002a2981b2c9emr14886163pjl.36.1713891858028; Tue, 23 Apr 2024 10:04:18 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:17 -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 , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 6/8] mm/swap: get the swap file offset directly Date: Wed, 24 Apr 2024 01:03:37 +0800 Message-ID: <20240423170339.54131-7-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 file directly. Need to include swapops.h in mm/swap.h to ensure swp_offset is always defined before use. Signed-off-by: Kairui Song --- 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 ae2b49055e43..615812cfe4ca 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -279,7 +279,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); @@ -298,7 +298,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); @@ -429,7 +429,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 Tue Apr 23 17:03: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: 13640384 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 F091B1420D3; Tue, 23 Apr 2024 17:04:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891864; cv=none; b=PzgYYLt7UVjvOQMYWsbse2QttJ7OvAYfDybwFea3OCrHyRkKlrfB+psE7l2ogoeMccJ3d3rlhi+Jipjl1FtEsHpRROuLev9O5wF8AH7n+/dKXRWOKgkxJmlmvy9m458bIOXsiQf6/enOPVgW6JS2CQskQQBgBLzAkTb2lHke2YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891864; c=relaxed/simple; bh=vrFjOYePpawjbVdhBsK92t7A0slbtAyHi4xRIBD0oEc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FreH0FxHvD6xIezcNNe0n782t0Gpi7k8VKz8nDnnI4cSQWzQ4A38fb1ZXR9IA8F7PmcYIfDJzKXQQUjKYGZfXsSUfM5VPjSi0KEbVYz4Oj2pck7Yxw7mBGBuvtrHHr0D4o+AWKXElnfmDaww3xPCW+1Rp/W2Qe+8xDhBf0AT8Ek= 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=T+e7/y35; arc=none smtp.client-ip=209.85.215.176 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="T+e7/y35" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5c66b093b86so58577a12.0; Tue, 23 Apr 2024 10:04:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891862; x=1714496662; 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=QrfJLtSyOHzdWNwAoeEt63qAvh/YvWPDSOmG3agvpH8=; b=T+e7/y356dJqp04AZTthvSTbcWdig5+ObIy/qPIZuxMGI4kvTksUULgtACoOEmm7nN trAEm0gmlPeylXYuGrCVFUKsxU07OCReZEKb668Y8ji3tc4mcWV3LMLwAcjOUNc8VXgc LXsn7zLpLORwZRJ8b78d550VkPjw4tdxuoyEolTdo/fkyVc3Kcei6qaZiitj3Qx3Q9z5 drwbuTg4xFAh4biYjf2/8jr3EGyssWpMjeeh2oBCN2oG07kqBU4+/3dVb8xmS/Ez4veq 7bEeKKmzudA3Di0SvPoso+S1YMBjN32xchbadOxtaqAKCcQur/h6DL1yVDVKFJ3dkVzo hbRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891862; x=1714496662; 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=QrfJLtSyOHzdWNwAoeEt63qAvh/YvWPDSOmG3agvpH8=; b=O9aKk+u1NtOspRqso9qzOcQF5ukhL0VKd2SHnAF7ymJQjf9JRYd8VDes0tyjGzdjND z6HOsnlUJRcBSqhEEKkcKnRd6mUvrZP83UlafYlfw1dIbivArWsVIheRkpufDzN3dpKy OwkIyE9OWaTQ9+X9P+lZnk/cfzYUCCWcvsGg1h07SWEp9KC1At437xjMHaRH8j8ooPG5 a4cK8aV9l9IomnVhOSYMWF8eUvcFFT0dMzo/YgEEJ+JTZCuuCiRDcnLh6f8ZZIpt8bzV uFuSho+H6bi2JJFi43EWDY0Bt7WObMKNHvowDzP+dMl1YGb03C2R+DcXf76j80JinQEk cMWw== X-Forwarded-Encrypted: i=1; AJvYcCWd8lSetGTNPNfx8XneCO5RdpxjiJAUaEXEHmeyVEzYSIlc+MTeiCW2l8E+4nAGlFkIBWFXXTtQafHSqsLyb+ZNWAxK5NC5hM8YiOX50UBY9gZiL75YryuxT7qunVNA6AIlLWeKS5ZDsRLJew== X-Gm-Message-State: AOJu0YzC89kJTdxT3lxDu56YryYF4RfzGnMbhQ7B15URyhQlEu4w2LDX bf2F47AGyZqvRo0D6xY7Uj/ms0dEUOE/H1Fx66OttTkHzpww6gh3 X-Google-Smtp-Source: AGHT+IHl29mA2dJ+DAVqdOiUnUGnuaMZJ8DMUB92M2KECrfDvhzldwg40C7x44GzkGKAl0R+XjVRbg== X-Received: by 2002:a17:90a:f40f:b0:2a5:506f:161c with SMTP id ch15-20020a17090af40f00b002a5506f161cmr104445pjb.4.1713891862010; Tue, 23 Apr 2024 10:04:22 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04: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 , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 7/8] mm: drop page_index/page_file_offset and convert swap helpers to use folio Date: Wed, 24 Apr 2024 01:03:38 +0800 Message-ID: <20240423170339.54131-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 four helpers for retrieving the page index within address space, or offset within mapped file: - page_index - page_file_offset - folio_index (equivalence of page_index) - folio_file_pos (equivalence of page_file_offset) And they are only needed for mixed usage of swap cache & page cache (eg. migration, huge memory split). Else users can just use folio->index or folio_pos. This commit drops page_index and page_file_offset as we have eliminated all users, and converts folio_index and folio_file_pos (they were simply wrappers of page_index and page_file_offset, and implemented in a not very clean way) to use folio internally. After this commit, there will be only two helpers for users that may encounter mixed usage of swap cache and page cache: - folio_index (calls __folio_swap_cache_index for swap cache folio) - folio_file_pos (calls __folio_swap_dev_pos for swap cache folio) The index in swap cache and offset in swap device are still basically the same thing, but will be different in following commits. Signed-off-by: Kairui Song --- include/linux/mm.h | 13 ------------- include/linux/pagemap.h | 19 +++++++++---------- mm/swapfile.c | 13 +++++++++---- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0436b919f1c7..797480e76c9c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2245,19 +2245,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 2df35e65557d..a7d025571ee6 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -780,7 +780,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. @@ -795,9 +795,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; } /** @@ -920,11 +920,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. @@ -934,6 +929,8 @@ static inline loff_t folio_pos(struct folio *folio) return page_offset(&folio->page); } +extern loff_t __folio_swap_dev_pos(struct folio *folio); + /** * folio_file_pos - Returns the byte position of this folio in its file. * @folio: The folio. @@ -943,7 +940,9 @@ static inline loff_t folio_pos(struct folio *folio) */ static inline loff_t folio_file_pos(struct folio *folio) { - return page_file_offset(&folio->page); + if (unlikely(folio_test_swapcache(folio))) + return __folio_swap_dev_pos(folio); + return ((loff_t)folio->index << PAGE_SHIFT); } /* diff --git a/mm/swapfile.c b/mm/swapfile.c index 4919423cce76..2387f5e131d7 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3419,12 +3419,17 @@ 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); + +loff_t __folio_swap_dev_pos(struct folio *folio) +{ + return swap_dev_pos(folio->swap); +} +EXPORT_SYMBOL_GPL(__folio_swap_dev_pos); /* * add_swap_count_continuation - called when a swap count is duplicated From patchwork Tue Apr 23 17:03: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: 13640385 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 CF3601422C7; Tue, 23 Apr 2024 17:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891868; cv=none; b=NiVe0x0DXE3VDaE8iaRnaBKhASi6IVuRLMMcy7avXrMggyADwU+MfDtQfOBpCCYlUPbfEkdb7vCPBoG7JOPkX/eqGCqjfap9U/spZXqToAWFcUbghw8dxI4EM0BJQt5JQtSp+tzK15I6wCm+vynz6xraoDZj4DShtrOhhxeuj4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713891868; c=relaxed/simple; bh=v/4DZT1o7SWRbUFCwl1q9F0Wyx1rUuOJ0NQJDPbonbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7htv/+9Yn/U6PctrPH+50z7t91OfAp/uMeM6s4bGQyd/UgyShUsC25Hl6/OzkpeX4TCrILw5YF1KTfSLl4vq3k06KxxnYC/hP0cKDMVzpjEgbWaQAaA/6tjSIIzYgQZi48O+IOsO0gvditlIqjz03f0Vn3Co7Dg5LdOt14PQAs= 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=GSxPWhj8; arc=none smtp.client-ip=209.85.216.47 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="GSxPWhj8" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2a614b0391dso4688679a91.1; Tue, 23 Apr 2024 10:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713891866; x=1714496666; 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=CnMzyp4v7D+bPlM4VXqNTLQwTcA8u3vvnjSU90ZgW/k=; b=GSxPWhj8KIm7+7RjVbAQyb86c7kuggpq9L3wHwsAjO5obwBhumrS0Jut7+z4cte5cm WFCmNSFdk58Teso/aLUas91RvL9tfVA+6Xh++blfVx6CXhXKJdIA7p93KqZa1QT+BD2W 5yWXTuyZLyK9mDxwGAcdL6xacKN/6bWREWqvivqYmtR9e8cQM9h1Mj5OOBtTFl/gtzsa mLAFIM4UXYlqxU1VJUOPKO+bkT+IKUuOy8kcGUKk5fnPu7z9+3ZqWEdOcmTYM2RgE6Ym 6WIXYJgI5JU+SQMndw9pIw9/4aDksgrOVjpQkHelTXDUQGFpMAD+JndMfr1qLqMuW//U fS5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713891866; x=1714496666; 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=CnMzyp4v7D+bPlM4VXqNTLQwTcA8u3vvnjSU90ZgW/k=; b=tSsCeblKz/2C8ABfLcL7UtUfw2+SN2Aw7EvBzYnP/yNnpnJSrHzMldpRqBbsiOH81d Z3VvMUevHjzsHcLZ27EP8imFKD/91m1O7Hi8m4Bc9ZGwjJc9RHQIpaYdscrq3laoq9hi 9Rkc1L30wU47a2Pr7VF3Z/zeuOiFhAIVE9lKLqjISOb/zTUPS7jqbF+lIIx1AmerJuBH Go4CsBm/UXWwRxTSiG2m4XKZdHsa/rs8J3S0c4bMlx+oQZpc9HYzvQBdrkzjktWNmyOM oijZVK4UFLhoghVH16wMzqGLBz/vm7lb08bWoQTFzIhQO5HggLE/chVlia3kPNWcdZiR iZZg== X-Forwarded-Encrypted: i=1; AJvYcCWpnCWZRfKrf/aEyDBk8y3J36mhVZsHQi58xhYnbrFo+b4ruWc/RCF3GXqXbE+mYjtTN9AQjovRFKDmhXvKAxgdrmMx0xGtHux7g13z0OSV9SSl4YrKU3H1zpaPVtSyFuOjuEr8Q72MLhangA== X-Gm-Message-State: AOJu0Yzo9IS930YKgVtCwaOyUPIPNn/MtXAbnIHnQsbVfJ5CERJBf8gn kx25j5tLTyjesuSreWkVuNTaJ0C+C8gv/VovPLpmMmNoZkUVzRlJ X-Google-Smtp-Source: AGHT+IHsdf0a0hXaosoeNJct0li+Z9JISuE3KsVNLbRolhiRYgiN4NDjYwA6cqx8BtEiKf1+SehY8w== X-Received: by 2002:a17:90b:3506:b0:2a7:e71:eb72 with SMTP id ls6-20020a17090b350600b002a70e71eb72mr37270pjb.0.1713891866020; Tue, 23 Apr 2024 10:04:26 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([1.203.116.31]) by smtp.gmail.com with ESMTPSA id s19-20020a17090a881300b002a5d684a6a7sm9641148pjn.10.2024.04.23.10.04.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 23 Apr 2024 10:04:25 -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 , Hugh Dickins , David Hildenbrand , Yosry Ahmed , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH v2 8/8] mm/swap: reduce swap cache search space Date: Wed, 24 Apr 2024 01:03:39 +0800 Message-ID: <20240423170339.54131-9-ryncsn@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240423170339.54131-1-ryncsn@gmail.com> References: <20240423170339.54131-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 big swap file. But when doing swap cache look up or insert, we are still using the offset of the whole large swap file. 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 we are using the offset from the whole swap file, so 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 --- 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 | 12 ++++++------ mm/swapfile.c | 6 +++--- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9859aa4f7553..1208d60792f0 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2903,7 +2903,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 fabce2b50c69..04d7be7f30dc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5934,7 +5934,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 0aad0d9a621b..cbe33ab52a73 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1762,7 +1762,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..93e3e1b58a7f 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 (BIT(SWAP_ADDRESS_SPACE_SHIFT) - 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 bfc7e8c58a6d..9dbb54c72770 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); struct page *page; page = 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); @@ -350,7 +350,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 +420,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 +447,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 2387f5e131d7..3d838659f55f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -138,7 +138,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; /* @@ -2110,7 +2110,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; @@ -3421,7 +3421,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);