From nobody Thu Oct 2 17:59:15 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F6C91DE3C7 for ; Sat, 13 Sep 2025 03:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734651; cv=none; b=B/wX/qCI7+0fG5JKvlUiZAhj066B/m/0QHwguIVDxKabhwuB45ydqnUsgg1drO93FjRxVi0N8uWEyrxCF/IPJ4lmVkoemYk8gHITT43i9CQIL18yJ16cVi5asmh5vSAjNCeGNfBYSGZ5Z05fpPvkwOi0dPctQ2s63QaOWmwrgCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734651; c=relaxed/simple; bh=nbmHvENF6wiVd4LFNsW3/Myx/TXvx5lSSh9ejpw6OMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eNfIkzCm8EELjlwWn0XNBjxehkS8pGv1j+8nV+zagKzXScBETJ+IrqWk8j2fJ+oF1zu91KEFFWSCBKPA+JRLSCN1X98SBq6BhinrZE5Hv/Kvtn7wu6weRML0Fi8Yxgp8qSI8JUuM4GvNgX1kK3xX95eHggjsf+ed9MgoRi70cTs= 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=RFYNYJ/t; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RFYNYJ/t" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-77616dce48cso914929b3a.0 for ; Fri, 12 Sep 2025 20:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757734650; x=1758339450; 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=RFYNYJ/tuvLylsma9+lf6Nz3v0bne1J3fs6cSSuHfOMuE4Bmjym6fiENFu3AnC5nDI qQ7FD97rwLEKV4BsfEbjt3y5kR5cYom8qKFcii2ZHSPiEiIyA2CXnj86TVBmlFhtfA58 zYzy60+RfPbmNNo4585c6usLQi1YESPXcGFJy4Ow2CRxvJlSa8rhM4CuUB9vrcTv7Zog Z+SvPWy+XeKj6lFFlD45eSBPZrQOdWwR9U831mUcW8hrol0JMpUQYH5KVIWMmvo7+HWb qnB7Ma12V6sJETFmvWITmKXT83qHetMPxRoKRuugYUu7O0iOJ6gOwKaOFMo2ijOlAfjE 7l6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757734650; x=1758339450; 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=g+c3GxMQTkzvc7Z5xJPoh2kbmecFWfxZrZH/+7hR5TqiyVGJh7Iuw9LrsMm7OvJyaR uPKNsUeu4feVVG11VfRigJhvVjqODP16tVB1unx5wjEW08dDvBIRoyTxhFUsoIGHiD+L AoApIb+7yVRq73JNj2gyQ4LwXBclvcQSLiyhZfA1hoDZexhTS0Gu3DEqCUEkLRJt8+VJ BMxvktvbqS2uONXrZGFiJCFlQpyOGco2Ve1DgkCb91WPbBZ1og6q1SBAPjcGOFuwwrgg uLI6jgu0JySwHE532aqe3dBO6LpEsCdVq+S2CX9fgMNYnl65vEAFCH8AR4PcXBxtxHbr K22Q== X-Forwarded-Encrypted: i=1; AJvYcCUD3Fbpa0vi/2ZOlO1YRV7UoJkTXdYo8uVkc18A2u51qzrDCToZzYklLdrlS+xZJ/hKqoaVHmfFamon4S8=@vger.kernel.org X-Gm-Message-State: AOJu0YwCxK2uJC0nhlEGSWIeyw/3hgQ2g6WbgB3uZ2CGFBP8Uw/rVVo5 jA4H3k2RuIHTNo34jlVnsHPOnfjXkFwW2mKv/S/XMdEeELEjvYschPM5 X-Gm-Gg: ASbGncvstkzYKUGZfIS216DIxhc2VKz1g3ZnOypwu3Su8r8pQGLjoriKB0t+WQTgsCA sRjLektGCQzk+Xx2laAJBTBqYyZFWwiSK72X1/lNzO9WBUogbYp27deQIXg1oKe5ezc1UT7QwBK qG0cx4ihMoJprC6umnfZ7ojqea66ancod8mWvP6QtCPgUIRBsdb6i3VBMkwFWElLRiYsgRZZds6 Pe4YuYKU3ZrouAnO9BDH43nE2CY68xZpeG1j6xZHa1+H/iAwy3NdEAdbC5X/zhjlJ0sXd6sNDA3 M1/5N8IElVqHC/AZ+UVOxzzgHRihjx+JPqQZkTEsQ9vuGjkREWQ0cop2vYHY6Cd49lg2EqFJZmN 11bsboPervDhQUIoSYYGXNE0cLLgOtVhZPLohj6CzvuSTgPjMDyedSiQ= X-Google-Smtp-Source: AGHT+IFUutBth5XkTwW1pC/OkCDAZih9KHUCMdYgxnZ59EYAd9MvBO/hHD+Z59SU25Og0yzU16T+xQ== X-Received: by 2002:a05:6a21:6da7:b0:24e:e270:2f55 with SMTP id adf61e73a8af0-2602c14caccmr5977282637.35.1757734649906; Fri, 12 Sep 2025 20:37:29 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dd98b439asm7150770a91.15.2025.09.12.20.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Sep 2025 20:37:29 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: hch@infradead.org, brauner@kernel.org Cc: djwong@kernel.org, yi.zhang@huawei.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH 1/4] iomap: make sure iomap_adjust_read_range() are aligned with block_size Date: Sat, 13 Sep 2025 11:37:15 +0800 Message-ID: <20250913033718.2800561-2-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250913033718.2800561-1-alexjlzheng@tencent.com> References: <20250913033718.2800561-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 Thu Oct 2 17:59:15 2025 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 DA6CE1E8332 for ; Sat, 13 Sep 2025 03:37:32 +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=1757734654; cv=none; b=MpElxTgTJA1jvXQzRC0jm7bAkMtyvqlVx246ZuEOk03SqK2rIWUKBt928++iNFfXsbg2rhK/G9yXBYOA0vTC2ca/WrM23rPSOx/0lCgVsxIjpraXadAiAxsb2ypDJKy2MfXFHvL0hhLY8GVnbGLb+vqov9OsWqj6i94c7o6ktzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734654; c=relaxed/simple; bh=i+rdKmNLLqGvwTHxeA8bz7QFUciPCdRQTOlJcDYX+3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GplErAJakJ7mvDnmskGY+wfyCgZBVxsF0e94A0e4cF4ge1jk8ZpmwRcfetQxEUsOmMK2EVGi5IZ0srsrvNfWqAeJi6Lk/MHJVGvNYCG6OSRT6cgjWngh461XqH3Wrgo/KQ6DKG3oL54jbigTOUkZf9gZmhxukb7z985eb0bSaV0= 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=hXlHd/At; 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="hXlHd/At" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-32dd4fa054bso2078140a91.1 for ; Fri, 12 Sep 2025 20:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757734652; x=1758339452; 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=hXlHd/Atz/S3XYLrfdlyoRljpyU0hSn4Hnm+dRYp02HpfbqUnvtb1e07g+wC/RRe6V L2bIFprYhzi9y0yZbb1BdeVTwzxms14fMTWHwBm+iPW7ijhssNmboS0Omng2dTjmEVr1 9OsPWHSAowtg3Jh1FPsr3I/N44J82mY1Phj/0/VFhMKPCm42KUo2CQGwPI06NW3sDznv GAIwJOej+RoE6qIJRRjQDQPxDi2+yKSzJSpfddLpPvWQpI3qqkBl7eWm1/PccpkZmMC0 l84d9rYiX+KTC5uesSuiovdboCioJlMM0sp+jUtVYfw6Td4swTp4bWLgtQUE4yH5DnhG wuRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757734652; x=1758339452; 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=MoOJYjimAhsFBqNb8Z24HlC2F6/GCXthR3v32RJJFxJ8BIlEYmHhkzw4g6xzcOvGuD IUL9u2bb2ijBLVMTuNMpHfkUQVYZ7XTIGumzPs+b7cobYrAJdFwfloNrkGoomB4vj65f 1ukMbhbJtXtwXWeylNrgmCgcGAAxFWbZBoiXCemKP3KhcOWipz2DKVoyNeEIm4brgNSB aVrrRGD313MuItihLps5gznlxcwnthPC/lTA0rYfM6f+PlF5p6+eOfV9QqE8wqJ+p2Vj TYVf24OUxQRZ0L4h3/lAi32LHGFTUzqrLEjHlUt1tquNJYCBXd8NNi3dCEHce1hv1pL4 kpYQ== X-Forwarded-Encrypted: i=1; AJvYcCUb2pWW0UeXpfxfY8Np+zOCbq1m/GFQk0fM6pEIHuFXCkuN6B2nHwkMF2YwndewUru9k0055OzPBjxzs38=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3O5N/+94ClskO2dooGTtS3MlpAGbpPXsUqUjU0Bcu8idCFYfW pbZlkrx8lAF7Ix5hllFFIezA9cdxaXVo/vo29wfSdAhZPFIu2JRBv3JutRLJ5Yz1 X-Gm-Gg: ASbGnctXDb8Uf4AOgpLBTWEvUGMIeRUyLVmNurH0s7NPdcBM+8h6yo8YUm7iL9AvwAS zD+dSZwbGvXNHX0+59YT9AuU0fisPPdlO7Kg9DJavDodDHaDurbvMeShLVarmP31ljy/jG3cLX8 ggc6zVYnO1Ob7WUTZlZ2dixOjTTdlaRS0C9U1d6MiCA9Ov/zWWyTYxuNDljI18LhnL30t6U7TNq 94BG1F4iV+eZqm2H+KO6aYhTaCp1YmTndZ3ghDOUpIEdfIj4xCS7lFvYNg+NqJWcPmd0KQJKqqa 5la9Dggq4H9MFaHqBbWEbroo2CNxSI0KutMoMkF+BBvY/S50gYH0GHzUOma4bTuMMHINZsIHKfI I/Yx6GGGwb58DnLT4n/T0PCyFdnUGju++bhvA7BWfKQDp X-Google-Smtp-Source: AGHT+IEOeHsLPRMfra6unUs5NfyVRITba83xdMVSRQfiY2OhYU1gf7ElboHBu/sxYisDe0m7N+j1HQ== X-Received: by 2002:a17:90a:d603:b0:32d:e309:8d76 with SMTP id 98e67ed59e1d1-32de4c33d5emr5685465a91.10.1757734652269; Fri, 12 Sep 2025 20:37:32 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dd98b439asm7150770a91.15.2025.09.12.20.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Sep 2025 20:37:31 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: hch@infradead.org, brauner@kernel.org Cc: djwong@kernel.org, yi.zhang@huawei.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH 2/4] iomap: move iter revert case out of the unwritten branch Date: Sat, 13 Sep 2025 11:37:16 +0800 Message-ID: <20250913033718.2800561-3-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250913033718.2800561-1-alexjlzheng@tencent.com> References: <20250913033718.2800561-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 Thu Oct 2 17:59:15 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 395071D63C7 for ; Sat, 13 Sep 2025 03:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734656; cv=none; b=u1V5k7NxGFr8LdlaPz4LtnQfbXLgqOCKFvpRWTyC80z2StKyuzgRg3Zc/51Pw+DeVqqomFy6aoK6n+iWWUDkUwDP4ew2FZFukWwbtseaxNG28xTVoJz2nIaZ/0rZqmkRNuEU98uhz43MKE+1RPyhPrXXCBXQGcIIYJ2otYmmIXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734656; c=relaxed/simple; bh=ycpaoNa3MN6uF82TEzzmVwGPWKJsfjTrnr+qTVnDsf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a/6dPjtce2ouujq3cLXpXmudNVDeCqSCwpAAiN0RV/l8znH8rnVSBzGo3e8MMjyLmnINmQ2uYIcr2zI7CerNEhBVH7VHA8+Jzpu6E/Dwcf0izFPpreTx7JFyyZmasnOxwKNnLzsdFUIj4KRNTtSjq5e0QrVGjpv022fHPyJNsG8= 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=cROztID4; arc=none smtp.client-ip=209.85.216.51 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="cROztID4" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-323266cdf64so2219076a91.0 for ; Fri, 12 Sep 2025 20:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757734654; x=1758339454; 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=cROztID4fSyst4TeqU9SosaOvuP8PaVXUvHYyKXqpJZvd7+wITk5/wVzfEAddvyT2i 96hR6N8zZ0c++t4psIugtNXV6MuQx1bTj3zkf+i7GEWzYXcIwt7DTJb2JHFZt1ulaUmX 9RJEZ1rG3ee/47oFCpE2KCLjGzqhS1FePE40lajSbKXjktPbCPqFF8EZvRw1M/bMvAjR NWZ2yb9Q2NpgTW8PnJogiigKJ363hNEZ46Mfg4kl43DwnM9tZ1+HTQA4y8uPgn2Ja/9C lBKMXzJiLXvYc1kvl83JJmzkkEgxrFYTLu6p/t+DR/6TMQhIUnlfhjCz3wbgnW24UWvF OSxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757734654; x=1758339454; 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=n5llTo9uCiyq0lTxlPBbPhUfjbfmpmR/DszqDMTugRbPFb7Dfsgqw9N9gOjQE1dvYj sZ6RKkzsRkO++IrQB2FWlxCr8qzarevUULQ3430xgzHRlERBozhgW4yV+GNd9qFerKxJ 7Ik5gIuBJ/UCoRO6u7PBirzi6DIxDWN4np3jClAvi7Sge7XO4iN3ttCSzgv30Oh8RnE2 twjd0qaFm6MeFZeiL87i/WmIpulc1mnPCRWQ/mV4wshRlD71+hpFpHAU3nYFrC4XsjSs kzdDUstQi6OZ2tJzuQHmGq6YpK0NEV9YqYZikPF+wkjP1hOr0OqXkhKzJID6fuNpItAq Sdzw== X-Forwarded-Encrypted: i=1; AJvYcCUrNvZ06qrcoR+CATLVEafQu822nSN66XT7vLtEjcuFs9XqoCWSmCcpYDQythVSWuaNIY866XUBtrTXjEg=@vger.kernel.org X-Gm-Message-State: AOJu0YzErbxseZ1lEgwjbePvhOnpW9r4zwWvw65ymh/Iu/IHUNT01Cdv MVPtoUc2SBD27Vd+NH3Yr6IhHlz8l9jKtfCcr8UdrPxq9WAQyCh12hO7 X-Gm-Gg: ASbGnctaqKLmymBX4yLaWbAEXElveQlOnpLmdfK6P0aTyNVDz91i4lkctyOWwNFxW8d z2EqIbBnZPV6n1EaGNVVS6s1vYwP0e/idnmISSi9AH/5ulcOjGo+N0g/pnofAkGfK7Y+GfjlY72 6CXsT0oLTdgFN91UkFd0H9olelZKllzPq6k9RPgv+6GevUlGrHYvZqj8cDc5zqIYsvWuHeW8lhA lZmePHAh3GuI8/yfg0HyTowScEiSk1zReXeOGv0VdxuSvtTHc74b4TQjbEfWGDLyE4n2+sQydyj AiXJuiDrHeejj3SK5IlxArHMtgbzg0L6t7nqe8BRwJT9IEMKcASB5xlLyi5tWGOqL+sgoJ8P0f1 qlB3JA08bS6SrkckOi9b54oNiSnMpWpBcdg== X-Google-Smtp-Source: AGHT+IFTSjLSmIonQ/tT9ymELWFyPtl8pb8LOwBSdF0oV1rT/SaH3ISod88rjuwb2oTrX2uuYFgG6Q== X-Received: by 2002:a17:90b:1810:b0:327:7c8e:8725 with SMTP id 98e67ed59e1d1-32de4f8ad49mr6517497a91.10.1757734654423; Fri, 12 Sep 2025 20:37:34 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dd98b439asm7150770a91.15.2025.09.12.20.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Sep 2025 20:37:34 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: hch@infradead.org, brauner@kernel.org Cc: djwong@kernel.org, yi.zhang@huawei.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH 3/4] iomap: make iomap_write_end() return the number of written length again Date: Sat, 13 Sep 2025 11:37:17 +0800 Message-ID: <20250913033718.2800561-4-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250913033718.2800561-1-alexjlzheng@tencent.com> References: <20250913033718.2800561-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 Thu Oct 2 17:59:15 2025 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 5C3311F4625 for ; Sat, 13 Sep 2025 03:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734658; cv=none; b=iiKGMgds75BVCXfI3kUOfJp2X9k0yjsxjoInmRUA9uGy283bVV9ecuwXgIBu9vovlF4RCUeX8M2LYeE3/xQI2GSC9gkjrWCK+qM2fwB+qgtMIVZScyAecX4c2vy/MSMiV7y7Zht19DtCfqirl03FnmmfQCeZT61S9/9qFMmsddU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757734658; c=relaxed/simple; bh=oxoLeYkcBF241PpwFv0BAx+rwkzBjJ2c1sGVHg2zOuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FmC1gIekZpOJjq6EKj9gqghE1YB85B4T70uPXvYczZakq54XqA46ZLf7L6FlufVG75Pu9qiDE3i6RuE/n0I7DvS42B5iqDL0RljgHGfGaE8bzVD28+gMoiULDynzfjPC8y1Zn8OImR/QQSz7yu00nVwpv8EfLvuOalCzrDEqMoo= 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=MXX+SM89; arc=none smtp.client-ip=209.85.215.175 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="MXX+SM89" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-b523fb676efso1968499a12.3 for ; Fri, 12 Sep 2025 20:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757734656; x=1758339456; 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=dfcXJBZLCmfYyA3YbUkaDw3XHxbE6UhRnVQlKyLTp6Q=; b=MXX+SM89/q5fvlIEbup8ihwJxEILb2Dg2u8AE70nb7yrUp2R2bXRRCosZFQb9nLW6C csdWZPuPyy7DY/+0r9b3RQg8BYGhJj8YHnAvOJTZsNzYtENrA3Utsahl+O3St905nXwX eCvNvqOoDKz7cD+pOukBPM0neDLI4T5/jRlVXrgEF+pdoQ8LWNndoihtvgLBUKIUuoHA Yr1qjRX3Z9SIpVnNntjDAiT/KgHEGmxvlUzQzIwzp3uJLW1IJA6J09caqF0W5VfoAfwG DHgfji4tD/Ngbs9k8oQr/zrT3M8kz1rmY9Udvs+xFp0b8qIXw/R/cG/Er/KuJk3lB4Ie wiJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757734656; x=1758339456; 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=dfcXJBZLCmfYyA3YbUkaDw3XHxbE6UhRnVQlKyLTp6Q=; b=ChleplCI2SFBl4fC+LbC/8uqoPoHHZnxozNJIAE75/AATD/YJ9HvwN0J0L3shHGLAs AJfe2WcoyoSqM/5mnsNpJv5x8Aex2jvalKsHox0XUmSYYyWSPeEzEX66VbmFHZyTKNWc IxNWlPBiswomptT16u7b3S9pivf4a5I80qpZo8dxIF+eq11KIMPNjaNgEP2YmBci7FEk Q0DbsKZxFwiVPPmvEbSWIZWoP1kOmcaQGDrfbxrQ4FA7fpAM6IkiZEpQigGkRhxg3jM9 4Olet105+TQH0NFFGkJ0pZcvWHUCvdXYvCYaDN+QnnbBWcDtV3EiKeC4nbq/8uG+V7wy /ptA== X-Forwarded-Encrypted: i=1; AJvYcCUiI3xwonC8VuMDqDmnyERIxRJfCqIi1+RJrA2sEF/EN1WFIR+vuP2MkQNmIDGXXYq6O9ouayybDATFPp0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7Ed2uuI3avxfRmHIyA1a5W0OhB6ufV1lIaiJ38Htzw52GD4OC jFOnkNP9+78+CETOWY7Z8zmjzH0+lxnGJp3o1mxAQ4A2LnZYimxT12KS X-Gm-Gg: ASbGncsWGi9nE0veRpz+anS642TsF0dx5kNtZmNwZaeA8Y9+2h3xqYlLV8jhn7eqTCz gQSvVsvNrpNvs1SxWPgbWmAaXx88/pXvWRbEN3KqWR+kRG6T/ZKGatXaxLPymv/eOvQSajQip1F 71srwKYnezMvop2iJYHg9oITakhy6XS0oRH/Ffag/BFMWjXaxH1SrvNO2SyaqhFTWrvQEIoI0kw QUSMZ2hp6D83zuChLmA+71NdD0vKZF7kzxMlndmEerbw+2PjNq7e+rppoz+f+wzI2L54omklNeT XLAFfPPtM+PkTXv0FwtD3OPHELouc2hySO0eqtBgR4JQzadh2MFSJM8iNpv0VLXHfC0tVueZtbv 8uh/MDC7qz/VXa9ATahG5AEstuxAdI203Hw== X-Google-Smtp-Source: AGHT+IGMBnPdZGGHXedTN9wIo2T02B3lU73VKw9Kl9ZgQvq7+Z196AYaCvOiDVt6BXSPu9nMY+sLTg== X-Received: by 2002:a17:902:db09:b0:24b:1d30:5b06 with SMTP id d9443c01a7336-25d243ef699mr61019425ad.15.1757734656466; Fri, 12 Sep 2025 20:37:36 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dd98b439asm7150770a91.15.2025.09.12.20.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Sep 2025 20:37:36 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: hch@infradead.org, brauner@kernel.org Cc: djwong@kernel.org, yi.zhang@huawei.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH 4/4] iomap: don't abandon the whole copy when we have iomap_folio_state Date: Sat, 13 Sep 2025 11:37:18 +0800 Message-ID: <20250913033718.2800561-5-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250913033718.2800561-1-alexjlzheng@tencent.com> References: <20250913033718.2800561-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 7b9193f8243a..0952a3debe11 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