From nobody Sat Oct 4 22:35:32 2025 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 41CF42E8DF1; Tue, 12 Aug 2025 09:15:55 +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=1754990156; cv=none; b=cPQhM7SzUDFBKwT/q3zweC69tgZECS3FoPXEeyC0IZ5Vq8akq/dHrlkL+U/sXQYi9GAR6UdK57LLXX4zwUvuhiHe2IqdfsbI1w5qDs2O2UCMRbvrmbpH/3XhSxd2aLQ3plrWFcN+4Ouy7lgmsMQ6xBsI488414ozGdLFOfcvJGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990156; c=relaxed/simple; bh=nbmHvENF6wiVd4LFNsW3/Myx/TXvx5lSSh9ejpw6OMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eaeniAW3mH8xS2+9I2YvNPK2JwLHuxPZe5VuVntseEXxMdc+SSolQ8H5qWUBoAJR8Vj+DogSQ5W5eTiPPaqm7tWMo6gXO59u2NZdMKT3jY1GiDWWDUadoZ3rt+ZtiGBZpogWIaxa/VwTVNRrwWP9kz062jMJa4R3xx3Guie7G7Y= 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=PGGF1bdP; 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="PGGF1bdP" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2405c0c431cso49236845ad.1; Tue, 12 Aug 2025 02:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754990154; x=1755594954; 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=jP93xN6gwLHr70Ds3prjvKvRcobCNOyB/BNk5HT+4PY=; b=PGGF1bdPOnIvlUxs/qaNXSCDSL+uPzCVLOXezapGuPPX9VLuU4AjYEpElTSA+f1F81 NI3A6HzHZBbfeYbCXE9+AbM+yi5wER3eGXW15N0WWBge6hpm9Hib4vcJGhUUWvTC+pu3 EK5efadtaiuYBQeLGXiuefKvbORt6DSHxRhNS3yth2hWzdw8jlIbwiJOlDDzjLUEE/0j RDYP3H+DGceZ846/ahugpfXUd9YJxidNQsUl1x7iseCSJv4FKT38YK2w1O/VHlmrg89P DlC132f9uPm//IcADJV00zzoMiuinWg68OXyzMloRt1tEyXdl4zmfyeAwqNHQ7NUzTpo qE8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754990154; x=1755594954; 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=jP93xN6gwLHr70Ds3prjvKvRcobCNOyB/BNk5HT+4PY=; b=tOHjB6DwctL2t7LevjDSC7WhWVBkvKpPrYm0xttoO26uON6Upy8yPIEnEM0AWkq43B t11J2xio1Tjyv1TYO4SmgR/nOIMpYPT77eijOgSwZqPjafyOJLh7LbgUB4jUSSOeSww9 djVNocWgyjVbr4MqvwMVqQNExXbgHUBV28Fgy0+WLOCOOE4ElkoqGPFtErb8uEIaTQQt bfqgW9FhyyLrQZox2ZydgY/1vK1bMdoRvWP5iKfBK0MfrOHIMtcB2psEi94oDl8QpGKE HlrsU/7Wm1vLXvp7gfOrbNV2LI70jEdCAF5a1y6TnDRP8fkiiw61CqZfsnl3PCEczsKL swWw== X-Forwarded-Encrypted: i=1; AJvYcCXKOz1Ioc95tgpWSGB6xJ8Dwh8enK3W3Sr8ZK0vBOCVRX7V5tSo9U0MLvfvIy280K8fdfQxP7kHaMNTUIKH@vger.kernel.org, AJvYcCXObuh1GiOKlshFlwmenridLwd4m1qo+AZqkkpbA6dQPPBdmdyQTtEnVZscpPzNrRyYe/DPtTa7jyDRyjIG@vger.kernel.org X-Gm-Message-State: AOJu0Yzrfsn7ljYhVZTPDWo5CcjP/za4xg6dNl9SMwv51c1rAUA2jtLu pZej8kNcsPUwSO9gKBZZL+e2aGXVcpxCm/Wo5RJqHLGQSdEm2cN3axqJ8OasdncW X-Gm-Gg: ASbGncuBfT2m6imuwgH7UixJv+RB9m8TCayfj/qzAigswNSpzuwtiURl9Od2Lx9eBAU Y7iELdGBEWB+/BtwHzYnwQFu+EAt5YkaqtbliI39ZycSwfJtjrzBjr8BWio/m8gkZb6FGcQGXUe QthFLXQYDqAgWKdV/2XL2dHAc9ldRad/6y465mEnSB2ygal9F0ErLDodgDcdpOGamfxIRzDrTnf Xm65mQt82+e+wspBg1u+YTV6fzYDTLCodAE8RouzLe10NFiGyS4+XurLtY68hmQA127zFx8LSoz 5+TwewWZdOcAsGLmeJaNcuX/HNfGEXuqoSCnh5H6kXFOZctPDT1dk0985wmiyJvkWrt0XA4lc3A zgP/d3iZ+TlTYxIU/B3GPMKlac36swC40qgY= X-Google-Smtp-Source: AGHT+IEPQ+MKj6cZsUrHYGttStupeCXS5R6YtXNdkNDqh1mPp1qU+hlOHYrAr4LCph2p99TUoFrk9A== X-Received: by 2002:a17:903:2342:b0:242:b03f:8b24 with SMTP id d9443c01a7336-242fc1fcfc8mr44592995ad.2.1754990154380; Tue, 12 Aug 2025 02:15:54 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241d1f1efe8sm291670665ad.69.2025.08.12.02.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 02:15:54 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v3 1/4] iomap: make sure iomap_adjust_read_range() are aligned with block_size Date: Tue, 12 Aug 2025 17:15:35 +0800 Message-ID: <20250812091538.2004295-2-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250812091538.2004295-1-alexjlzheng@tencent.com> References: <20250812091538.2004295-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..0c38333933c6 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(*pos & (block_size - 1)); + WARN_ON(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 Sat Oct 4 22:35:32 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 6BE3F2DF3F8; Tue, 12 Aug 2025 09:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990158; cv=none; b=Qu9APN2Fi4xfFgOw5FJdaWEFpAzC+9al09t1nsuROzjOINZxY6dWjEhlzci/R0PjmrKF/KSMLmkYls2u9RxnFf2w8vRneqS08Rg1DIPA8OUe/4dK2SI+FO6YB3JR1Cn22uphzItfogEeumRF08ggae3XbjYI4EGjlxh286qpivE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990158; c=relaxed/simple; bh=i+rdKmNLLqGvwTHxeA8bz7QFUciPCdRQTOlJcDYX+3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pnyLBoy5+wG6kd1WTEIEU/s5cDdD1AxZFR5CVg6BEis42um0j/qd+HCs/VGx4uT95OA5naWV9efTcTJ6VqCwc7zV/2YdfeWzBiYvXPBhJw2W2Kkcuklx48nUat1o+NlQ7EIWpQMH4KAKsTXuVFPWk1eQS9q4aZWkfAEF9gF+Leg= 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=ZU3IFSEc; arc=none smtp.client-ip=209.85.210.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="ZU3IFSEc" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-76b36e6b9ddso4434493b3a.1; Tue, 12 Aug 2025 02:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754990157; x=1755594957; 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=fM1B2JsbtQYQeIjPqUgcbjG7nDJGVMQTVHa4+Nz/+SE=; b=ZU3IFSEcKYNdKtdt1xQFOOfKNib8IGV+wKz7OHjwX/rmy2P8f1nsfG659X1Yvursl9 AkfPp3Wxo4e5/1fB7s9VChlNKUYLNJJq2tcyMLOqfQ6lCW+E+drJG2UXco0ecPM6nAMY KKqB3iO4szHIB4NxyRLykKHvl3Ok/8VaB2Zdq+Ar/XtKObavUhtjF7a4++JSqtIRiDRT hKeS/x54nWTQxHDkh55qUf1LlZD/ESnR7ttZJ/PQCGoG2Xs3ARrrj9so9cdLqfkmc3ck TT0zaOo4dVrslkKPk1XD0BF1yd7jSVb6aLefWt1I47DGW5VTUj2t6SDaYuZRibzjmylW kOHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754990157; x=1755594957; 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=fM1B2JsbtQYQeIjPqUgcbjG7nDJGVMQTVHa4+Nz/+SE=; b=vCjIK3jjLVuEsNv/F3IkUJqH8MCnC8OQ5F+IqoiT6iXSzE40itPjSMKOG6PoRHoUnn 6klyfr5sCjUNNj2R1lqhhrp1Qep9hHT46yAQqRvtHZeFwmjYBBuMY6Dt6ItZQ6XVEYfm raSAuuKhJkE5v+6arBVih76q2JCj38+ts4WezYMJvjxIDtOwOppM0kf0pFpuf3g8xn4x Co84C9CG9XsSvmZVC9HhbY4g+tC28nq6GImEJVXc9uyaBsdEnJMeCVx5EvQhSOYs0iPm Iz9s7DFZFBlM9OFQO6r18ZpFETbwTJ3uSCc4PTZildemZ2gaYdFfsqcO/DUdtbjauLev +2gA== X-Forwarded-Encrypted: i=1; AJvYcCV97OOOl95waeV+UpvfXRx6r34Etv+6LtRVR8GidmRx7UUeulljCcKOZjEeLsbWrucXb7U11CrdeWCoWwGg@vger.kernel.org, AJvYcCW+9gKD13mIRWSRSQ1HNwEIVpehP/6hXhvp5fPN7EMZg8rI7WSUavbE8WCJfEJRWPiywMpS/9q5xb+V3KDC@vger.kernel.org X-Gm-Message-State: AOJu0YyluYN6nteu8OanSYLcMXMXpoujMMGSuNTRPchFJ1Kw0mbfg2V4 5coKQlcem2zu+tPnat9UYp+ybchVgeWvjmc4ssguttLQk2PPJ/WWbW24 X-Gm-Gg: ASbGncuLzvXDuzK+pALdYCKosI8TzykaseKrsYFYLvKA8XOyU4BIi0u075dOYc2dOd7 1Tl48yv/skH+w0xGHCh8V0W7yZbZCVUtCd5287WOI/pNbKFiWPIBVJuOO4vR3kAwS8prUGXEAyi Au2ZY6x35LDcUZmh8mWCeuFeerw+XLk6H2aVPGH9R/oRKSEwIpqTCdBKxaEHAzDW78RTFOOeb2S Ngwigy48hw0Lctz3mUGDnssoSBmQWtwLB0Lz+g48D/Mn1k5bx6KWsWiqBZr9e++kLzasznFYBCH MorYHY7MM39h48WSvoTyHeFztyTX60psAORgKicnqYcE/MP2g1UEyOI6F9J7eCkp6Ba8MflB/0X 4KWdevpjuxIM/14n6EYGyAE/TjvxQHfErH18= X-Google-Smtp-Source: AGHT+IE6NUwbN/7w4nwB3d9QPsqO258Ijpe4rqyfO7Yo6QszO2IAXWOBFHzbNXsUmvQYSZzC7Ix+Lg== X-Received: by 2002:a17:902:c949:b0:23f:ed09:f7b with SMTP id d9443c01a7336-242fc365389mr40438495ad.48.1754990156646; Tue, 12 Aug 2025 02:15:56 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241d1f1efe8sm291670665ad.69.2025.08.12.02.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 02:15:56 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v3 2/4] iomap: move iter revert case out of the unwritten branch Date: Tue, 12 Aug 2025 17:15:36 +0800 Message-ID: <20250812091538.2004295-3-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250812091538.2004295-1-alexjlzheng@tencent.com> References: <20250812091538.2004295-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 --- 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 0c38333933c6..109c3bad6ccf 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 Sat Oct 4 22:35:32 2025 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 A27EE2E9723; Tue, 12 Aug 2025 09:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990161; cv=none; b=CpAQ1YlvdMRA8ayVZ513jIztu6YWCFP8UANEzmT3962Xk2PL58itIayNuA0xIXw5IP/pAnaZyBk8/F+ieUJszD7NTaKTLEkf66sTPWMC8Ko68nr1hMFylYNtornOpAqLlWeU8/AS0iTa1Bi0eExWfrfzKoYF8XSwyPmnEzNeJGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990161; c=relaxed/simple; bh=ycpaoNa3MN6uF82TEzzmVwGPWKJsfjTrnr+qTVnDsf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oaqB5Jh5F7bPkDmTJBoXGpg346E74ZoObiix8/9MKbT9X6Ka77sKUrF+5UCV4fecxfmFZXpb0L312QH1+FxKOuCyRVs1vPgAtSrq0W7EvNgpBxHR8GLEMZv4KGLEWb4TqezqWKWNLFo2xEFMl7SQ+cIlIne5aR4jeCrNH4Nfz+8= 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=jyqRxKVH; arc=none smtp.client-ip=209.85.215.174 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="jyqRxKVH" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-b390136ed88so4005823a12.2; Tue, 12 Aug 2025 02:15:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754990159; x=1755594959; 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=kUVL95c0pEIZMhDo9pFvxVeTSyzxblZ+STNvH3cwOYE=; b=jyqRxKVHmc5b5qikZCDP2X0up4I8ag6MpJcR1kv4k7Oc4B/yzomAC/ftGkMWNicI9n GfbN4EGNR0ivlitts5xzET8xD/ER+rreN4ePD8YQ8kO/HqCGuMLrRhsDQapMwNWWXsKa gVwo1pWzYb/V5NRlUyTswgj4fsf06kOsiD3JKvDK9L93GPstT4BLvvcHiUOjzQ7P/E6p hcqqns/bcUcPW1qUG86erE532v3lv0dTxKWnVWUoH+YnCvle1l5EtPYO0MXMKML1QYhY 2IVytLS/juGQgWbMhL9/V/qjfYySXaVunM1mqmwtah/PWm6kbePJC4v5ENY6R0IhERvc Tcyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754990159; x=1755594959; 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=kUVL95c0pEIZMhDo9pFvxVeTSyzxblZ+STNvH3cwOYE=; b=MIFshHrizpEDjKDuNLsCv1U3Og0KcvZojtCL1rglK8E21gX+7tKuSArl/436kBXqJM CWWw80GGqszBN3yb15efbgrP2SzDnGg2YUrzwTjQcSFlVmOzdEAhOhtA6Sm0nEPmqQr/ 2mSztv6JtwGl+Y5cSEFJrcF7tnMsQwTlwnFMr2FjAlBaD/4E7JNan+/HIV4SvlF19Ayv LIvF+uLe/6DSzNY7GmgOqI5r8T4gnMPFhCLAGLsVAWO6VqKTec5xNyhi18Klt20q3IIv 1L/CMOAuw/6rUc0FSbqt/YU6QgezTBc3ZxO9mXYETh6OnDBAg+zLGjP/MYcTp+EKaGM6 ew2w== X-Forwarded-Encrypted: i=1; AJvYcCWLM4hjMwoIdyL5t+fr2WiUrUwQOWdCBc0edmr1VbmzbtfF6TGCXukqVkXC7AchgvPAHadGPo2rcJPW5rQc@vger.kernel.org, AJvYcCX8xYoqtpgSf6UFtqEEfFAvE5s4Lz3IQwhAfoRc/jodUWYBO5UPSTeES7r4jNu/bxv4DhGgIUvMYmEwzRzo@vger.kernel.org X-Gm-Message-State: AOJu0YwVlE+G9Kk+39P1vMqtiPoGoPWDbk22Awn/quJuEvNWSllst/Xq lVLijwIAZwzXfvwKrZ3M7oyU8upmTLgIH01Vy0tSZQe0FElWTrUoFZKE X-Gm-Gg: ASbGncta64flWALxDRRPyGVfclOCE55mVzsrkH3gHc0rFkupZUXQZIOOb0goTooan12 wiaIwuhfW1Lnm4DcsQAYpdHGLE/6tyhtyK9WI46Jh7BE85+Lx9KEdrzBt/bwZSu+htqpntCuToR zFdU1fcLW3yyFGbIomMxnboA4O7UBY7Sd+dJHo9HP1Vwn+RuIN9PuDkXmWCvETi24HfWtvuQNE1 lPVrPTShElPpumSqmBS//rcjgMcdzLjvNCltHJ9tneIsNF2ykVJT0gDMI8/+IHNLalPgmxa+c4U YMTXgOBnqW/Wf06olUNFdgtYwzs0SwykPPt19/PcGhKBs3tijkZDlaAz8baLIiuIFgYqPGU31hl kUChtoATqTVnDGgG3laodDQshzSKoZrj3nlI= X-Google-Smtp-Source: AGHT+IG6s8wRhNll09E9mnFMqnkGHcJHCk3ofhuGPJ7PDVhD420zRD/2YPXhHcnAq8Kxiqco4LDBqQ== X-Received: by 2002:a17:902:da92:b0:242:accd:bbe8 with SMTP id d9443c01a7336-242fc36829fmr43178685ad.36.1754990158712; Tue, 12 Aug 2025 02:15:58 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241d1f1efe8sm291670665ad.69.2025.08.12.02.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 02:15:58 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v3 3/4] iomap: make iomap_write_end() return the number of written length again Date: Tue, 12 Aug 2025 17:15:37 +0800 Message-ID: <20250812091538.2004295-4-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250812091538.2004295-1-alexjlzheng@tencent.com> References: <20250812091538.2004295-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 109c3bad6ccf..7b9193f8243a 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 Sat Oct 4 22:35:32 2025 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 B097E2E54C4; Tue, 12 Aug 2025 09:16:01 +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=1754990163; cv=none; b=rty7R2IDtGGzAAD4YiDlFhtGqfURmGpobmxxzJTE6UR3H8bl7aNd5ed9sXOnrnmsWvAEXuIHv+/VRfC+OiFvcdIJqAlXFNxG8hceLJ5y6ZXaJ+h9SbazzKtpIJi7IAptDMPIlhsH/mgLDDH96Ec3APNRKD1UQffBb3wInPedOVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754990163; c=relaxed/simple; bh=ELWvW+M2jADaIZWOkli/FMGFEI1EmtXEE0T6HI5+TdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mTwrYsu0snWmTiJXF9ulCMDy8CWr0ALzMQIdim+AWPGKrmcVOBM0JRR1pPSx98VdNzll49jN1tjXaiR0TNLjLPKBno/1MMkHaVuDhGrCrg+HubA6BEHFyRdfPzUEs66I4NxoKPEmoDceXmPsJ37i4anvA2KcPtyKULGalHNbSP4= 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=Y+SzDVgS; 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="Y+SzDVgS" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2403ceef461so44066195ad.3; Tue, 12 Aug 2025 02:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754990161; x=1755594961; 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=ETsvnaYYTYssQSdiqD1pneEVq8m5ZOm8thK8WL38Gi8=; b=Y+SzDVgSonJRg8Pur3nQMAv1y9pltRLTUeUp93UT+wqmBhO8AHUiDY/aqAng4dZJau 9KJZyFDfJ/g7XuMal8/RzkMhmvDe8Z2ONKvochzrTLW9kW6fvkFkP41KXnC/solT7hu1 mWn0AXTN9DUDNW1w5+yXPEQw0iWWI/bzzO5JiX2KmnZfd9WQeeyeU7vuyvg4dB93wQaH 1KHv4JyFUOF3zckfeEl9oTJLFP4H5UaRqvkeZzd+zBCJSfd2ivFTLZ1jNSOFRhCm5+Za l6K+RNBjsQZJVc5PQdYrJcc6OME2d6MmVtJECmkBaSiJtUlpho4n8aah39NANY+Buid3 i7ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754990161; x=1755594961; 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=ETsvnaYYTYssQSdiqD1pneEVq8m5ZOm8thK8WL38Gi8=; b=MC0r073XP9CwfEGbAHsCRcvJRvGOxM8RDniimMELzLCrPFIq1g20XKeX1Q0y4iXzyv P8HbG5iKgI2s+1vqgWGJWYTfotk0SZkquiqvTYXW7+qcWkJjsNiWEhiiRqZ3DbffJD8O fY2pe/Koysp19lkntXLF3K3WkFtV7Y6bongZdpqBppEnD/hlEW2IHECN1BYCx45kc1zT 6PQdYeFkXRkhUAGWH5NMN7DGPbFamzAVTrV/3nOj7OIPsc+Gk749r4g7hBA4YjvlafXy WS5X9EejIuP1E+0OcT77ymp40NRh4DNSbR0S0fUt5CWSmPzU287LOP7Ukte7JPWnxIXv QIyQ== X-Forwarded-Encrypted: i=1; AJvYcCW89OpX5vfwLjz9AZOfRCNHk3PQ51nOAP2MsOCsmK3fvaiW4KHPth0EbU25C/uTcek7pFHw9sd46WwD2EtK@vger.kernel.org, AJvYcCWbtR0kmGsapxLEXvPZiCV8BEWBwvbku3a0Kot4wEhtdB3qXy6HBMYgWfgagxJQ/rGmCo+ODUlJMeInlhmP@vger.kernel.org X-Gm-Message-State: AOJu0Yxj3a+Qoen5OMAS5fg1ssJDOmsAiOYmcltjaXm2cSftDXDCRWEw TY9G1f04XSFxSdag7ZKu/ePazEZaTnyo5jPOu+t/0ux5mcaZczkwbzmTjU7VavyM X-Gm-Gg: ASbGnctGNwef71NFwQQhuNwfFZSAVgTUH4XeCWcoP3ZS4gF8ILUT1/rpDJJM90egdi3 bEhlGDJ4TBZ0z0IuS4KyLMv+o0NMgnMmYaKAoknysz+tfLcN6tALXxfPgEUOxxClgtpXQGrEFh9 NTyc/h0ajXwAn464LoB6Qi7/4q/9G95heaVtVIQidbEU3Qjh7drSdjYdlGbrjyaKrjLK+NENxi2 EGPa2URRj5PvrZ+4X0hx0Eq3/lyV813CF8wNGDS4jgMWSVpqJnecZeOE5y8y2lO9FA0oeH9cf3k NoVyCXjuIuuvRuloMTdlnxYEsGCTQUY+I2HRQ9kl17asm21Phhi+UlZygYNEQOKmOEvUi1foWj5 Hu+HH1ia6Zu1shabUHWccz7sqqC8tlFugMoJvt1vKeU3rVw== X-Google-Smtp-Source: AGHT+IHPnPWiYSaXaV0zUa1cKXWI5MwMCHYaCm7ZlRbK6uLcbEU1rYhEf47LkLOcZUOOYIGCc4NPpg== X-Received: by 2002:a17:902:ec8b:b0:224:23be:c569 with SMTP id d9443c01a7336-242c201115amr257867705ad.22.1754990160846; Tue, 12 Aug 2025 02:16:00 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241d1f1efe8sm291670665ad.69.2025.08.12.02.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 02:16:00 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, Jinliang Zheng Subject: [PATCH v3 4/4] iomap: don't abandon the whole copy when we have iomap_folio_state Date: Tue, 12 Aug 2025 17:15:38 +0800 Message-ID: <20250812091538.2004295-5-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250812091538.2004295-1-alexjlzheng@tencent.com> References: <20250812091538.2004295-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 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 | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 7b9193f8243a..743e369b64d4 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) { @@ -886,12 +905,15 @@ static int __iomap_write_end(struct inode *inode, lof= f_t pos, size_t len, * read_folio might come in and destroy our 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. + * non-uptodate block as a zero-length write, and force the caller to + * redo the things begin from the block. */ - 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