From nobody Thu Oct 2 03:30:49 2025 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 128EF2765F5 for ; Tue, 23 Sep 2025 04:22:04 +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=1758601327; cv=none; b=kz+oE8YX03wW3ROHEzX0EDRjO7u+IvPg1psCpTd1VYxb+RvkzWE/W8+Y5X1no+kzUSrimLl+JEuzItvntWmVzTmcfiQfP2fPEiw/4bNhMv73Yp6Txz2epfxZI5dmbDIGWv0ZvPGNTBNPxpQd810rq7EvpI8s8UMN0wOGP/4Q3R0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601327; c=relaxed/simple; bh=XLZkhs9B7s43yPMz0XkRiX5V/b3jeChbEWeI9PX6mdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cgRUsX3yUNHi5AME0SQMiiTBcW6ZfRaUIhHrSNYpdoFagsCDqGDmGbhQ5+Cnek3Vfn9ckNU6ZXIphiXZ0Y7dSCR4NQrGGT1GBmzh5W+bVorQh+kQv63bVYpPwYcqc+qyLo2ezl9op0GvIuOoUaBU3bA0nSWgXcOvjPByNaTEP7A= 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=QIl2bQ0R; 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="QIl2bQ0R" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-77f38a9de0bso1633770b3a.0 for ; Mon, 22 Sep 2025 21:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758601324; x=1759206124; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3+ep2im58IjxT7DllA4u/z9ICpD6gnUYG9dPd2F5jf0=; b=QIl2bQ0R3qkHGbx7wtcI+aq1Qp5wUz3htJv3pN0OdZlkdmfWLWSSifGLkjZpwemfji AluDAtJEUXF05VpONny+dYF5n5ijJSCa9OYdjVZGPuRs1YxvnP+T224tr3DoZSNBcv7n OwpECYJwBrrWE9w+wwloDs383yekhoHh5ZWHJ/rCgQsnxdkd+LwcpNHJEoUyCCF3fIOu 0Z05VlM3tNbi7FR8iZFSM+x7hOJP2+XfRVw7eXjSOPJ6oFkney9lfhPw+AhNAZyYwUAn tWsncgSBd3AEoMwmBcbVfg/PVqahoKxYiriV3Ugh5xYsU+p/eiMAUqZuUXclQusGIDwh Q74w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758601324; x=1759206124; h=content-transfer-encoding:mime-version: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=3+ep2im58IjxT7DllA4u/z9ICpD6gnUYG9dPd2F5jf0=; b=u710pCpBnFhToTxF37cTqmU2ADUXAynxA/+eivBf/Z/sXYcLZ3c9bjL+zlwC1auRil t3GkeJZgC7AblcrJcl7YI0rufuB9mId/pByGSThT3VQoQdXatoNer5haIAnKs1yKYwwn ME5x+3FfSA4gpASMvO9igHn9XTXSNQpSmBzo/OQUww6KzChuQfr0h+ewhB/DlqlnO/ds 51HFaL/zF1n61vdgA3vzRFmYnVjuiYT+wNmD0ZpRpm7ldKJlAAdWb6bCCkuc5ogU7GPS 4gHEPm3+4Y9Rht1EmTgKEucO/BHpphLTZszeyG+lXbXMKeTeGTim5nAriIiJ6XwnsYGE IDpg== X-Forwarded-Encrypted: i=1; AJvYcCXkANLAuKTj9MnjKlY+G3Sm2kvT+zxO6gP3eqExmnpJSHz6q4gYSffIOwj4nYNdWhwG6ejZOF2L0nHhW5A=@vger.kernel.org X-Gm-Message-State: AOJu0YzV3p808l/aSVRFJKGYbaAvakOB5fo1VPpwfygAfpd+FPM7/IpO xx1tdkIjRCVRKTI7z7I3KQchk5+y8NML2geF4+/ZZV8aSnqp3/Ba2mRyIf5v7lBp X-Gm-Gg: ASbGncsiF2tgPjzMGRiZyQRl8lJNQREhossgn6YpPNj3d0p98ObfKys5beAIftvDtPX dg+O3ma1/MIN+D6sRpldYJtVNJt34g1ORAYNMvchUly1W3BElMiJHj35gBDElpW1doOGVvL43dB ivD7qZO0Xkp6gfXYrc9mhyeiAa9JaWjv6f5unzPeAknKL1Z8OAl3dEFrgX4+AN8+qxa33IE6Ibq 5Nr2Liqs8KaETg2o/YZyyFnZ2IJmQGQ4gi7H5WZI0iV+gVWb2ATqf31iYp4TkZKtTTvOYcw1VVa uf0SOu1S7YT4qWxfrkyY1PjSuqETMlzEVn0n2gAx/1Gr6sMguzKzZuNR++gquzK7KelJT0H4KGp QfUfazBHAf8NiA+4DMYdIFSx9b55lvj46Kg== X-Google-Smtp-Source: AGHT+IFYm7cLGFEmVi93jViXMI0vjzoclxblnK03HrQzBTlwHSUg8RgeIuDYR9ocCKvlWOoegY4qwQ== X-Received: by 2002:a05:6a00:3d13:b0:775:f2cc:c78e with SMTP id d2e1a72fcca58-77f53a83d8emr1675324b3a.21.1758601324334; Mon, 22 Sep 2025 21:22:04 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77d8c3adfd4sm13316513b3a.82.2025.09.22.21.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 21:22:04 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org, hch@infradead.org, kernel@pankajraghav.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v5 1/4] iomap: make sure iomap_adjust_read_range() are aligned with block_size Date: Tue, 23 Sep 2025 12:21:55 +0800 Message-ID: <20250923042158.1196568-2-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250923042158.1196568-1-alexjlzheng@tencent.com> References: <20250923042158.1196568-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng iomap_folio_state marks the uptodate state in units of block_size, so it is better to check that pos and length are aligned with block_size. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index fd827398afd2..ee1b2cd8a4b4 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -234,6 +234,9 @@ static void iomap_adjust_read_range(struct inode *inode= , struct folio *folio, unsigned first =3D poff >> block_bits; unsigned last =3D (poff + plen - 1) >> block_bits; =20 + WARN_ON_ONCE(*pos & (block_size - 1)); + WARN_ON_ONCE(length & (block_size - 1)); + /* * If the block size is smaller than the page size, we need to check the * per-block uptodate status and adjust the offset and length if needed --=20 2.49.0 From nobody Thu Oct 2 03:30:49 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.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 865E727B340 for ; Tue, 23 Sep 2025 04:22:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601329; cv=none; b=qbsZKam8LAh/FA84gQa2Vfb2BGnTFwvbyslp30V1utaE34lZu+jR3VQn4YINeyJswSU45F5NouAbxgQmIeAMKvfWSzcz1SVisX1uC9FatN4urjLc6fYskKVJ9+eEO2AVYaToRzWvFQFr0+mKjG13WB+UyxsxqOEpW9/e/ZZ3sIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601329; c=relaxed/simple; bh=dah8ZhgBCCglBmK2Z+eAcnLpuYOrh31bu+S3be/sAjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qgPP1kRjN1qtFH7i0VZ48VjNjmbNT360tNAwqZ5VD1Q1Vx/iuBJRqt1i+WLmOXcYUJH0blltIW5yl7sllpbAU8DuturyB4lG0Y7/hcfa42PJuEkELDGclRQi3sWTCVYmD+0LhqrfcCpnYp5kXoiJ+dhYlRvgv2nHHcQrNd+6DXM= 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=Dthun77Q; arc=none smtp.client-ip=209.85.210.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="Dthun77Q" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-77f22902b46so2319849b3a.0 for ; Mon, 22 Sep 2025 21:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758601327; x=1759206127; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s/cHPlIzPABEuPSPErkXxAEb1eyYlTFw7Bjb++zcmu4=; b=Dthun77QjAYBxbl7NhtATWcR2H8zHpjyWXjQibe0AzQnD+rSBfC+Z+fHczVXfWM1Dc 9npSnr5b5cbDUA/h7UNUQPRaMrYf6FigI0C9sRGwszLyBtnuDYhJ7/k82HvpDmmZhqzx mVo3fzgR1HsTwnswcBZVl/h7MBvbIL6EGU3ir3AqxIoyte7Nq7jWN8ZwS5eD7XVdPxO8 K9CVImy1MJpsDrwU4CnBteC3H0kkh2K6oxoFwpMw2Vu2i+tC5927K+WXw9TPBxzaIDFI NJUIrqRVQoKseQuszuyI6KeguRZj2SJjDYg4Z/LtI4MMcGETda8vJu7Huh5TNvA/i/jN 4q9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758601327; x=1759206127; h=content-transfer-encoding:mime-version: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=s/cHPlIzPABEuPSPErkXxAEb1eyYlTFw7Bjb++zcmu4=; b=O95l2s68yWbGl60fPhEYPbN0mmHN65RboYI6RuqcFZx3FBdU71ISVyQQA4hCzQA7PJ iwZ3mwIcIYy8Inb0WqsYu2DyUNDDQzei2qjR1LcTpKoNNcf0yO+FzgGGbduK68aKaqd2 O8k8p/DPzFeqj83Y9jaRwCdnAu8pPtADqpjgn0fNfTBnhf3cHHgGmZXrj26ztiYVbQLE cm+/Z7Ze9Orlb1SvRWY9xgkRW0xQStWdAYeKRMe5mN1qqPvb2fZ80X6nFbY6oT/HVN3m qlR8Y3HGzUH7hsrX5oW4ZiAJp0Fk7xp3Ne6HBQ6gj1hv7QJzUhN+lAhB/K5bv5mRy09N UL9g== X-Forwarded-Encrypted: i=1; AJvYcCWhXq9+jJ4/KfMiEAOMa7JFIRCKxtaEPSDinXhq7+scFAUZyS4ysnxzjz9Wb68R6WkNW0Td+5AInYx2+kI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy65qPvEHEKjh9HLsguQ43Dfba3VlaYcNc3Q0yIzY+ChxRT5Csi QW6IlhrSMpHUghMYl+qTmA58IApkIq/EZgkKWqLGJ07Ihe20HMlHlYtiH8IIico2 X-Gm-Gg: ASbGncvvH88uqinftZ3KvnYupv7+Br/96ZgyCp3s3Yjg4VR07JSgfbJQG7rzuo+8EzI VYQhApQY4HiVTJX1ekbw8v8cUVRs8+W+NeqdAcUmTFcK4s1cCkmo/1ERMTtxv2mQm2dcIraoeiv KMs0XXFQmsqfal0KKkbh1Dpv0DBULBP0fzmdKk7mm7+Yhn4YMspwlqlxlrlIg6hgRI2d34m4a2l R0Xb1LP0romyNc6BxZ5lNtmHIS8DGsqdeCxYTHbcf6ZMg0NtcBe9YfF56E/vnjLSfDIirpEdI77 W5FMDYtHlt0UZGJ67xyXagFqPf6jevT3lhW3qnuYdui1ka+0R6jAJgUUtC8YDsSiCTKJkiQ2+73 nKQulOwZEbUe+D2DgebFfYiq5QbIlO1YNUQ== X-Google-Smtp-Source: AGHT+IHZAQls+5hMZhGCN0G3+29ESb1NDuuB+LUQQRQtRCIeNRAgRN5oig1MawJfpWsB1afMgMFY0g== X-Received: by 2002:a05:6a00:893:b0:77f:1d7a:b97f with SMTP id d2e1a72fcca58-77f53ad04c6mr1449286b3a.28.1758601326763; Mon, 22 Sep 2025 21:22:06 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77d8c3adfd4sm13316513b3a.82.2025.09.22.21.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 21:22:06 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org, hch@infradead.org, kernel@pankajraghav.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v5 2/4] iomap: move iter revert case out of the unwritten branch Date: Tue, 23 Sep 2025 12:21:56 +0800 Message-ID: <20250923042158.1196568-3-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250923042158.1196568-1-alexjlzheng@tencent.com> References: <20250923042158.1196568-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng The commit e1f453d4336d ("iomap: do some small logical cleanup in buffered write") merged iomap_write_failed() and iov_iter_revert() into the branch with written =3D=3D 0. Because, at the time, iomap_write_end() could never return a partial write length. In the subsequent patch, iomap_write_end() will be modified to allow to return block-aligned partial write length (partial write length here is relative to the folio-sized write), which violated the above patch's assumption. This patch moves it back out to prepare for the subsequent patches. Signed-off-by: Jinliang Zheng Reviewed-by: Brian Foster --- fs/iomap/buffered-io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ee1b2cd8a4b4..e130db3b761e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1019,6 +1019,11 @@ static int iomap_write_iter(struct iomap_iter *iter,= struct iov_iter *i, =20 if (old_size < pos) pagecache_isize_extended(iter->inode, old_size, pos); + if (written < bytes) + iomap_write_failed(iter->inode, pos + written, + bytes - written); + if (unlikely(copied !=3D written)) + iov_iter_revert(i, copied - written); =20 cond_resched(); if (unlikely(written =3D=3D 0)) { @@ -1028,9 +1033,6 @@ static int iomap_write_iter(struct iomap_iter *iter, = struct iov_iter *i, * halfway through, might be a race with munmap, * might be severe memory pressure. */ - iomap_write_failed(iter->inode, pos, bytes); - iov_iter_revert(i, copied); - if (chunk > PAGE_SIZE) chunk /=3D 2; if (copied) { --=20 2.49.0 From nobody Thu Oct 2 03:30:49 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 AC0D727603A for ; Tue, 23 Sep 2025 04:22:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601331; cv=none; b=Ud6w8o5UtM5qyIbpyHKWDsSK6eVl1MRMRUGGWhDup8z/xEbjDg1l55NF7bpxt760wPYuQfOD8Ug0ECQ07hNHB+m7umVyoMEzfdiZ1gd16yvf7FplG2Ndlmg2UgeRSjuXAe7HM8+roOdr7Zk3uHccaNhghcIlgHe5iGEOa8VZpV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601331; c=relaxed/simple; bh=5eH935+lsN0R/DItA1U64YcW9yDNKNSWjjrWljodN0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MzBlN3FLSO6JI/zHUJbP8VhEtfW83TYcwPNxmkmWjQvrZ1u2JA3UYvAsZNOI6tx9S07J8ygOqXepbJVrPXKHvpJTzGUOq96md6AO5vzSlxug+WMhM1SoROkP2T9nBf+87kJ5brjkFwWvnF2mW6k+X9onjogFQsvgSMY5Qbrvis0= 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=bb8nCN0t; arc=none smtp.client-ip=209.85.210.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="bb8nCN0t" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-76e4fc419a9so5122452b3a.0 for ; Mon, 22 Sep 2025 21:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758601329; x=1759206129; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QTiKYWhp9DqW3xIE0b9hgxXBoYHgu3XtAiRm2w5aZUo=; b=bb8nCN0tbhRXM3QVcmVwW+hzdss3hHiWvKEcGF2RSoxdOMY8JjpT5p4WnaO8m8UTeC J1P008BG3hWRFsIpM4ThVD4XcjYLfqxwyiBkokZtP0f6SuICViCMAZWaheKnkCNX8olo 4thsFUf1MB7fDJNjq1CTExjEFTHaEVeUbCQhkGstoG2fueWdu0Rnb0R8U3Tzb+3sXooo hNghaEYu0d/ZSwqAgUZl7YtqSWPkNXmHvvaHh8mYmzQTUiwP7OE89PGnaaD8T/n+7LNq NwAoLdCZZYYyzqVMiaB07oEh7DuJv/WuyDKXZfLHg8e6HkQib+KWSQwSoLJTgEie7Bkb SPJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758601329; x=1759206129; h=content-transfer-encoding:mime-version: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=QTiKYWhp9DqW3xIE0b9hgxXBoYHgu3XtAiRm2w5aZUo=; b=GFcbqzyWetbPj8sRIj45PcI2wXR/9S4DwmnWRN2ufTHgYRTs6QFtE+e1jfB4RR1xjb ElrAmAIJd4m8eBiVYhT/S9Pj7mZOMNajJuQrz+YZCaUG3VNpHWhJB7gXdGcAhZeAJBgW DkHpgiEV/wA7OvYEnpsPI7cT0Ay8Uvuv1FLpbbJBIv+vJUW6ig4hlGQvVkAt2sVoZhpX 8W1SQl7TbpSWcW5XooLVzrTnGEr50Q2p+fHcsp/q2cspnMlryXH3taXU4cMBQ+1YryeE WrjUpEJJQskpfCWf7aL+gE/xCtmvknhejwMk/Xna8XSNHy3n07Oj+HB3ANZTt6CruFDw ORLQ== X-Forwarded-Encrypted: i=1; AJvYcCXecguzkiZvJ+QfdSRlt29ZaTTkdDNLhTf+yw2sOh2D2XvGorYqnOqfm97SKNM/G/JZ9Rqj7C7n00ed/2k=@vger.kernel.org X-Gm-Message-State: AOJu0YxqeH/p7vTS95uGJQFH6gsx1DxwJNSjqZc/4iLY5dnH6RlnHcy8 PT6a6maKddj/t60bw1HSf6+rWFSTavRlX+A6A3xxZ4lxsmx026/hdu9z X-Gm-Gg: ASbGncsy4W8+1BMxugq+nZxyQDm3W/jlJzF+sFWvgwDCmAUC/V/aL2blMp5Npi8odwL 0Xg+JP16QVARv45ecXi/yZiGftrgWMCUTOe+Fxb+D0rQee+qJCjYtngukwKObqfgIZHh/w3At7W Gcv5z3yWeLedFnQe8jpXdK0A6y9anolE6dLjSHNLapyPGCmTMf4X7g8fvUmOaHNqjMA7uif4Ym6 G7BGpajyC9PHXEisfngnUdVP00AzNAuyMOnisPSeCK7y7Db8a2IRfSm9lkpyUIcCjj7DrjTLUgZ 9LFjSik1rYESWIuUNP5GWS/ul39c6rLiFRLvzaYg7LsWUdk/L4xzYJNLEXMr+1651Uu9ty4qY36 c/dBZ/sdJ4eaxP7Yg9ycMXtvbpbKsn0tbow== X-Google-Smtp-Source: AGHT+IH6HBhAi03cdQLfqQC6cecOw3p26zijbrqK/kBrzopVVn6ri+wpqvCMc/oJTTwEYKJ19Ui/VQ== X-Received: by 2002:a05:6a21:99a7:b0:24b:c7d9:88e4 with SMTP id adf61e73a8af0-2cfece8b630mr1830042637.42.1758601328808; Mon, 22 Sep 2025 21:22:08 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77d8c3adfd4sm13316513b3a.82.2025.09.22.21.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 21:22:08 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org, hch@infradead.org, kernel@pankajraghav.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v5 3/4] iomap: make iomap_write_end() return the number of written length again Date: Tue, 23 Sep 2025 12:21:57 +0800 Message-ID: <20250923042158.1196568-4-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250923042158.1196568-1-alexjlzheng@tencent.com> References: <20250923042158.1196568-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng In the next patch, we allow iomap_write_end() to conditionally accept partial writes, so this patch makes iomap_write_end() return the number of accepted write bytes in preparation for the next patch. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e130db3b761e..6e516c7d9f04 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -873,7 +873,7 @@ static int iomap_write_begin(struct iomap_iter *iter, return status; } =20 -static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len, +static int __iomap_write_end(struct inode *inode, loff_t pos, size_t len, size_t copied, struct folio *folio) { flush_dcache_folio(folio); @@ -890,11 +890,11 @@ static bool __iomap_write_end(struct inode *inode, lo= ff_t pos, size_t len, * redo the whole thing. */ if (unlikely(copied < len && !folio_test_uptodate(folio))) - return false; + return 0; iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), len); iomap_set_range_dirty(folio, offset_in_folio(folio, pos), copied); filemap_dirty_folio(inode->i_mapping, folio); - return true; + return copied; } =20 static void iomap_write_end_inline(const struct iomap_iter *iter, @@ -915,10 +915,10 @@ static void iomap_write_end_inline(const struct iomap= _iter *iter, } =20 /* - * Returns true if all copied bytes have been written to the pagecache, - * otherwise return false. + * Returns number of copied bytes have been written to the pagecache, + * zero if block is partial update. */ -static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t co= pied, +static int iomap_write_end(struct iomap_iter *iter, size_t len, size_t cop= ied, struct folio *folio) { const struct iomap *srcmap =3D iomap_iter_srcmap(iter); @@ -926,7 +926,7 @@ static bool iomap_write_end(struct iomap_iter *iter, si= ze_t len, size_t copied, =20 if (srcmap->type =3D=3D IOMAP_INLINE) { iomap_write_end_inline(iter, folio, pos, copied); - return true; + return copied; } =20 if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { @@ -934,7 +934,7 @@ static bool iomap_write_end(struct iomap_iter *iter, si= ze_t len, size_t copied, =20 bh_written =3D block_write_end(pos, len, copied, folio); WARN_ON_ONCE(bh_written !=3D copied && bh_written !=3D 0); - return bh_written =3D=3D copied; + return bh_written; } =20 return __iomap_write_end(iter->inode, pos, len, copied, folio); @@ -1000,8 +1000,7 @@ static int iomap_write_iter(struct iomap_iter *iter, = struct iov_iter *i, flush_dcache_folio(folio); =20 copied =3D copy_folio_from_iter_atomic(folio, offset, bytes, i); - written =3D iomap_write_end(iter, bytes, copied, folio) ? - copied : 0; + written =3D iomap_write_end(iter, bytes, copied, folio); =20 /* * Update the in-memory inode size after copying the data into @@ -1315,7 +1314,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter, do { struct folio *folio; size_t offset; - bool ret; + int ret; =20 bytes =3D min_t(u64, SIZE_MAX, bytes); status =3D iomap_write_begin(iter, write_ops, &folio, &offset, @@ -1327,7 +1326,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter, =20 ret =3D iomap_write_end(iter, bytes, bytes, folio); __iomap_put_folio(iter, write_ops, bytes, folio); - if (WARN_ON_ONCE(!ret)) + if (WARN_ON_ONCE(ret !=3D bytes)) return -EIO; =20 cond_resched(); @@ -1388,7 +1387,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, b= ool *did_zero, do { struct folio *folio; size_t offset; - bool ret; + int ret; =20 bytes =3D min_t(u64, SIZE_MAX, bytes); status =3D iomap_write_begin(iter, write_ops, &folio, &offset, @@ -1406,7 +1405,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, b= ool *did_zero, =20 ret =3D iomap_write_end(iter, bytes, bytes, folio); __iomap_put_folio(iter, write_ops, bytes, folio); - if (WARN_ON_ONCE(!ret)) + if (WARN_ON_ONCE(ret !=3D bytes)) return -EIO; =20 status =3D iomap_iter_advance(iter, &bytes); --=20 2.49.0 From nobody Thu Oct 2 03:30:49 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 7A4952836A4 for ; Tue, 23 Sep 2025 04:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601334; cv=none; b=oH4gUApUoVDVWZJpLwdkMIeZmFmOClgMDlhkA8j552BQ83h3ipiadx19qZa26Yk7yiHv86KBgt+29OuyGAEJxR8k4ISxbfjhnIvEhMz8CHR+iMD3yHCxjzT8DC6kP/HvpJqj93VFGkfbuwpfAjWaGEiHenSke7CFVSC5q0U5NZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758601334; c=relaxed/simple; bh=zpvEKZqLhwIOmRHUipSf1LyZBL80ITB37XK2LvCaT4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C34RsPmbY6Lf7op4i90hN2zL1IN2qOrReppxbT/V8dbd+fisuBYueG+gVL8vzAzPSt9P04mTLsg8WwxCAn3vA0eXWhsP9WwFTAruz3VCmvvvw3JeiPKNjPti3EGh0upYSVNIOuxMD8v4eJs2eAoIIMO1MtFWWWpbAw3YAb8WQmw= 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=np7XVXeh; arc=none smtp.client-ip=209.85.216.53 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="np7XVXeh" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3322e6360bbso2332319a91.0 for ; Mon, 22 Sep 2025 21:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758601331; x=1759206131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1nDNxXFU6/HO7z5iXuMR9cVnSyuTgICPbquGVbvl6vg=; b=np7XVXehliYilDBlAhJdCZXRHsSa4eV3yIB3vm1tEaexFoM4zthPU49+XCWe88jd9m HTOC29E2ZbtC0Ybpqi7lL+PwBjAb+V420zF2u/NAjHoPcWnNAs1qfk8LloMGVSs8yBpc xBJcmxeaX2kskV2tXhzhT76dUJUGC4Jchm5/1aq8wjojwXQFiwkAbwLBxxPxVcclNzdO OAggBCuGk5YgvHo2MZqdxc3Z+5fHADOnK17xZoiKR4QlPlHSLY0X6T5ZF8fQZgz4MwNz S/EDRVxKzyx9js7a3VywfYN3Y0zYZ/28Uvpy/2IVie7eJ4iFGfMQtgHTON9c45ceIzPq Hwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758601331; x=1759206131; h=content-transfer-encoding:mime-version: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=1nDNxXFU6/HO7z5iXuMR9cVnSyuTgICPbquGVbvl6vg=; b=OhtsCbgJZ2epvZH+EZ8EyXNcVDXlkWGj4EcP8ldSbHllP/KpC0Fl+ZqWjOJd/lrcvT 4pbJLDMbsYk4Gyuk23VOoCPz4QmuePwJxyLdTNGf1oo9bQAlYzx+sZwdjrRSyqqYjELG ysnXAF94/eUGwcwu+lYBJMQptSwktWwZnT9axcGpTpkYLKJJH1GE2+/QSCzGbcrmhhNf SiPhmy4U3/6/T9+RDATM/WarROq0QMWDmD8HFmTODJXp1JNrw9wzhsswdVnHX/El7O94 0mmFOO5F4/HduqTw/ZhwFcGuGAh5881M80SRqQc++03XwfwF5j30i9D0J8vbkm9ux/Hf kpSQ== X-Forwarded-Encrypted: i=1; AJvYcCXiGQfnPwN5LYzy0mR2r6tWPlmCA/frEaCVPbdbAQGvbz+QP2VcQ0pC5uyqPaJ1Rtt9Y5wLgSPnz6RyyxI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzmrq9j4ODs0xPujcmcCeBXCccqjpYeXAloNqwD3LZ9OhEAXnjI WA+CImYwJak4fxzXQS/SEGAlpT7qaQWN8/oSlrSQdSOpN9Jl67Fk6m3v X-Gm-Gg: ASbGncuwrA1ErL7ce+oz0qKbX4Fc8ujax46gYTuknxdRq3KmAVaovWi6UVy5s6M2HfN pfYLeO+0Nz1dCagmr3CeOlXR7l0N+MdaBYFN9qXzeeRFEZX/LdjrdSVLssT9r1A/YP2gIpWcBhG VQYPsz/ktrqeweS0U2m/lEfP3DRn6g5lJE5pOF5D97OslhsRpIAs15FDO8nJ+Jy9vwJOBCHjbsg 2H4KZK+zKx+NwbNGcIbMIeVgR86UF9N1UUyxFLMqUpZYunwHLA5+rnsqnhocPYICrf8TCoq3Yro tmIkrRLkP2zz948JRqex+QfD6F9QhEVCIUaua3ksHPkcGPvN2ppAtoVC+Yb51VA4gSQFHMa3TbY FNQRGdYXvVbTJD/g2ECnCRqXErFyytBe9YA== X-Google-Smtp-Source: AGHT+IF7vHoIXKK7ahfVkrWmvrmfXhwv4d6xCB5n1yI9ZZQycPuvOWR5cPz7VJstzs3WJ12MlmIo+Q== X-Received: by 2002:a17:90b:4b82:b0:330:604a:1009 with SMTP id 98e67ed59e1d1-332a95c82d3mr1254994a91.23.1758601330689; Mon, 22 Sep 2025 21:22:10 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-77d8c3adfd4sm13316513b3a.82.2025.09.22.21.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 21:22:10 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org, hch@infradead.org, kernel@pankajraghav.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v5 4/4] iomap: don't abandon the whole copy when we have iomap_folio_state Date: Tue, 23 Sep 2025 12:21:58 +0800 Message-ID: <20250923042158.1196568-5-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250923042158.1196568-1-alexjlzheng@tencent.com> References: <20250923042158.1196568-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng Currently, if a partial write occurs in a buffer write, the entire write wi= ll be discarded. While this is an uncommon case, it's still a bit wasteful and we can do better. With iomap_folio_state, we can identify uptodate states at the block level, and a read_folio reading can correctly handle partially uptodate folios. Therefore, when a partial write occurs, accept the block-aligned partial write instead of rejecting the entire write. For example, suppose a folio is 2MB, blocksize is 4kB, and the copied bytes are 2MB-3kB. Without this patchset, we'd need to recopy from the beginning of the folio in the next iteration, which means 2MB-3kB of bytes is copy duplicately. |<-------------------- 2MB -------------------->| +-------+-------+-------+-------+-------+-------+ | block | ... | block | block | ... | block | folio +-------+-------+-------+-------+-------+-------+ |<-4kB->| |<--------------- copied 2MB-3kB --------->| first time copied |<-------- 1MB -------->| next time we need copy = (chunk /=3D 2) |<-------- 1MB -------->| next next time we need = copy. |<------ 2MB-3kB bytes duplicate copy ---->| With this patchset, we can accept 2MB-4kB of bytes, which is block-aligned. This means we only need to process the remaining 4kB in the next iteration, which means there's only 1kB we need to copy duplicately. |<-------------------- 2MB -------------------->| +-------+-------+-------+-------+-------+-------+ | block | ... | block | block | ... | block | folio +-------+-------+-------+-------+-------+-------+ |<-4kB->| |<--------------- copied 2MB-3kB --------->| first time copied |<-4kB->| next time we need copy |<>| only 1kB bytes duplicate copy Although partial writes are inherently a relatively unusual situation and do not account for a large proportion of performance testing, the optimization here still makes sense in large-scale data centers. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 6e516c7d9f04..3304028ce64f 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -873,6 +873,25 @@ static int iomap_write_begin(struct iomap_iter *iter, return status; } =20 +static int iomap_trim_tail_partial(struct inode *inode, loff_t pos, + size_t copied, struct folio *folio) +{ + struct iomap_folio_state *ifs =3D folio->private; + unsigned block_size, last_blk, last_blk_bytes; + + if (!ifs || !copied) + return 0; + + block_size =3D 1 << inode->i_blkbits; + last_blk =3D offset_in_folio(folio, pos + copied - 1) >> inode->i_blkbits; + last_blk_bytes =3D (pos + copied) & (block_size - 1); + + if (!ifs_block_is_uptodate(ifs, last_blk)) + copied -=3D min(copied, last_blk_bytes); + + return copied; +} + static int __iomap_write_end(struct inode *inode, loff_t pos, size_t len, size_t copied, struct folio *folio) { @@ -881,17 +900,24 @@ static int __iomap_write_end(struct inode *inode, lof= f_t pos, size_t len, /* * The blocks that were entirely written will now be uptodate, so we * don't have to worry about a read_folio reading them and overwriting a - * partial write. However, if we've encountered a short write and only - * partially written into a block, it will not be marked uptodate, so a - * read_folio might come in and destroy our partial write. + * partial write. * - * Do the simplest thing and just treat any short write to a - * non-uptodate page as a zero-length write, and force the caller to - * redo the whole thing. + * However, if we've encountered a short write and only partially + * written into a block, we must discard the short-written _tail_ block + * and not mark it uptodate in the ifs, to ensure a read_folio reading + * can handle it correctly via iomap_adjust_read_range(). It's safe to + * keep the non-tail block writes because we know that for a non-tail + * block: + * - is either fully written, since copy_from_user() is sequential + * - or is a partially written head block that has already been read in + * and marked uptodate in the ifs by iomap_write_begin(). */ - if (unlikely(copied < len && !folio_test_uptodate(folio))) - return 0; - iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), len); + if (unlikely(copied < len && !folio_test_uptodate(folio))) { + copied =3D iomap_trim_tail_partial(inode, pos, copied, folio); + if (!copied) + return 0; + } + iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), copied); iomap_set_range_dirty(folio, offset_in_folio(folio, pos), copied); filemap_dirty_folio(inode->i_mapping, folio); return copied; --=20 2.49.0