From patchwork Thu Jan 30 17:09:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954743 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 527E71EEA46 for ; Thu, 30 Jan 2025 17:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256865; cv=none; b=DOwrRwSgEQnExDz1M7CBR0Efuxj9gyzAJB3eEEZuGSLVBzsf+7t9/MIck5DH+wzHa74Ms+MfIpbBLbBZvKO3DKjRAka6fNVygK/MvBwLdGr6t70C3IXd1dSMRekMSpTRcaC61mEGox59Un+t8q/RiSkLlw6VagX8GJtEYsDzmUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256865; c=relaxed/simple; bh=/CcAGSXtCyzmWnS93ZOrskKZkHRoJXfInTSOetrZE0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uuoSw7KNQCHRg5FlEOvmbpMdWFTPa3REsBjkVqRC1xammyAYv3LlYzY4C+9z80QlJwPm1kZm4iO8Oes2XO5MFWmKZjy9Ny5ugSHBFLJEAHChjB160IaKhh6DO6REK9N2HWvsqYnQb3wBt7dq4aPAsL0WoiGFUd99gJQEPT7KT1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WYaehM4z; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WYaehM4z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l8+3EkgGdj8WgrbHVmLXjg2LfbG3NgNfTsmBRTx6Ry8=; b=WYaehM4zGR+o9V6hselDuEpAiNqghSXKHvS5OuZ5zuy+sLaA9Ec6pxXKo1uQCikNQ/CwUM V38PZrCeccglq/KUgs0iEz7eMoGg/t0YMWooWJ4DwAljvXayESDjqVfjoJO1B8AhKGCOh/ 3TS3V5M3WY/w+C52M45x4FEPH5xCHTw= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-IIMtKxIfMFGYfuLq-MbjHA-1; Thu, 30 Jan 2025 12:07:38 -0500 X-MC-Unique: IIMtKxIfMFGYfuLq-MbjHA-1 X-Mimecast-MFC-AGG-ID: IIMtKxIfMFGYfuLq-MbjHA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5D7921800370; Thu, 30 Jan 2025 17:07:37 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 674C730001BE; Thu, 30 Jan 2025 17:07:36 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 1/7] iomap: split out iomap check and reset logic from iter advance Date: Thu, 30 Jan 2025 12:09:42 -0500 Message-ID: <20250130170949.916098-2-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 In preparation for more granular iomap_iter advancing, break out some of the logic associated with higher level iteration from iomap_advance_iter(). Specifically, factor the iomap reset code into a separate helper and lift the iomap.length check into the calling code, similar to how ->iomap_end() calls are handled. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- fs/iomap/iter.c | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 3790918646af..731ea7267f27 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -7,6 +7,13 @@ #include #include "trace.h" +static inline void iomap_iter_reset_iomap(struct iomap_iter *iter) +{ + iter->processed = 0; + memset(&iter->iomap, 0, sizeof(iter->iomap)); + memset(&iter->srcmap, 0, sizeof(iter->srcmap)); +} + /* * Advance to the next range we need to map. * @@ -14,32 +21,24 @@ * processed - it was aborted because the extent the iomap spanned may have been * changed during the operation. In this case, the iteration behaviour is to * remap the unprocessed range of the iter, and that means we may need to remap - * even when we've made no progress (i.e. iter->processed = 0). Hence the - * "finished iterating" case needs to distinguish between - * (processed = 0) meaning we are done and (processed = 0 && stale) meaning we - * need to remap the entire remaining range. + * even when we've made no progress (i.e. count = 0). Hence the "finished + * iterating" case needs to distinguish between (count = 0) meaning we are done + * and (count = 0 && stale) meaning we need to remap the entire remaining range. */ -static inline int iomap_iter_advance(struct iomap_iter *iter) +static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count) { bool stale = iter->iomap.flags & IOMAP_F_STALE; int ret = 1; - /* handle the previous iteration (if any) */ - if (iter->iomap.length) { - if (iter->processed < 0) - return iter->processed; - if (WARN_ON_ONCE(iter->processed > iomap_length(iter))) - return -EIO; - iter->pos += iter->processed; - iter->len -= iter->processed; - if (!iter->len || (!iter->processed && !stale)) - ret = 0; - } + if (count < 0) + return count; + if (WARN_ON_ONCE(count > iomap_length(iter))) + return -EIO; + iter->pos += count; + iter->len -= count; + if (!iter->len || (!count && !stale)) + ret = 0; - /* clear the per iteration state */ - iter->processed = 0; - memset(&iter->iomap, 0, sizeof(iter->iomap)); - memset(&iter->srcmap, 0, sizeof(iter->srcmap)); return ret; } @@ -82,10 +81,14 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) return ret; } + /* advance and clear state from the previous iteration */ trace_iomap_iter(iter, ops, _RET_IP_); - ret = iomap_iter_advance(iter); - if (ret <= 0) - return ret; + if (iter->iomap.length) { + ret = iomap_iter_advance(iter, iter->processed); + iomap_iter_reset_iomap(iter); + if (ret <= 0) + return ret; + } ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags, &iter->iomap, &iter->srcmap); From patchwork Thu Jan 30 17:09:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954742 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E31E21EEA3E for ; Thu, 30 Jan 2025 17:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256864; cv=none; b=lOKLxljuAxDfs7nK4LsUljAe8zUqXoia0e40carLSkbK2BukCCaELujeyvbBP52g52NIM+g0PCmp5ExpNrhB2vvxqF+CVV5cB/sIylVL24E3zB6+0K4EiHpTuA3Il74y9DpaBOUsw41lCcJpkRxaSym2E741I/PK7wgHGIqMS9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256864; c=relaxed/simple; bh=F6nitF1RA8Ks+0UbuwspJowzlmUpb5/2u/8WdMxeJbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JcfFRnlHjaKUCI+zIyFwzHtltkABpwHk+hk2R5pjvwKwJ0a1PUyE0+GgD3dsNMsVJC7/n2kWzc1Dn0TtCMMe05ZCq7Ids9dQMyDPCdaIrlXkypqVGU4sD30MJwp1JpAEbNCfMnYH6vkEdkqEKaicCggKKzd5LlJZm1+aqlmIaME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QLOPtNOq; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QLOPtNOq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CBbISAal2K72JLWIf5DrIZYo0Uh2lYCJgSNclGMZ9w4=; b=QLOPtNOqaepzKOhAZ38YbVpH6Aad/nW0RuGmGB+chbd/46A8QmezsTHM4uSyhH/H/+EnJT iPASZ1oQqCiqVDWzLykYEdyf/oq7pUl4C0OwZrF1eKb43y7VOoP9bucB7EjSRZKbiZCxC6 IwLPiiKB0EwYUEiLoniCXAuhYhyGCM0= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-257-LcRCS6mANu2OYKXH7Te8IA-1; Thu, 30 Jan 2025 12:07:39 -0500 X-MC-Unique: LcRCS6mANu2OYKXH7Te8IA-1 X-Mimecast-MFC-AGG-ID: LcRCS6mANu2OYKXH7Te8IA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6D58419560BB; Thu, 30 Jan 2025 17:07:38 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A0A7830001BE; Thu, 30 Jan 2025 17:07:37 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 2/7] iomap: factor out iomap length helper Date: Thu, 30 Jan 2025 12:09:43 -0500 Message-ID: <20250130170949.916098-3-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 In preparation to support more granular iomap iter advancing, factor the pos/len values as parameters to length calculation. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- include/linux/iomap.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 75bf54e76f3b..f5ca71ac2fa2 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -231,18 +231,33 @@ struct iomap_iter { int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); /** - * iomap_length - length of the current iomap iteration + * iomap_length_trim - trimmed length of the current iomap iteration * @iter: iteration structure + * @pos: File position to trim from. + * @len: Length of the mapping to trim to. * - * Returns the length that the operation applies to for the current iteration. + * Returns a trimmed length that the operation applies to for the current + * iteration. */ -static inline u64 iomap_length(const struct iomap_iter *iter) +static inline u64 iomap_length_trim(const struct iomap_iter *iter, loff_t pos, + u64 len) { u64 end = iter->iomap.offset + iter->iomap.length; if (iter->srcmap.type != IOMAP_HOLE) end = min(end, iter->srcmap.offset + iter->srcmap.length); - return min(iter->len, end - iter->pos); + return min(len, end - pos); +} + +/** + * iomap_length - length of the current iomap iteration + * @iter: iteration structure + * + * Returns the length that the operation applies to for the current iteration. + */ +static inline u64 iomap_length(const struct iomap_iter *iter) +{ + return iomap_length_trim(iter, iter->pos, iter->len); } /** From patchwork Thu Jan 30 17:09:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954748 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B50B81EF0AE for ; Thu, 30 Jan 2025 17:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; cv=none; b=uz0F9cTAT6wVBLsIjps6WORzbaIQgSSKGgn6Pv6S5sTMQ5I6/LZ+Pd8BN9+rhmFnO2RtwlCHlbkbPqCd8yQ0VLRX3K9Q8W+zpFLUWvv7oNn4cC7LgCuzkOiJuemUs0P4gR9qUIU5FWO8/G0Ut6COlw+tZEnpknpgDx/vx8qLHM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; c=relaxed/simple; bh=e6rnP4AjCde4+aV7NzXPvnqZKHGd6tRSha6UNJ2JVyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VLG8Ii/tM+cGEBim6PZE2neWYC5rF3dDdcxbNFOCroMPSFrKBMhkVkaHxOVCYOIjSGIhSKk4fwrWc8RjKzIXKac38zj5vsPQN62yIDhm8RGTLICxrGftDP/W94Y44klnX4Qrb7SbWRPKYLWF0Nxrc8Oh27JFzuw7uO8F/O8WzjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CrCXvW32; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CrCXvW32" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kSBcWa4IOctTRcDERpjo76q3hw2TfdtYAnq8v9ZVCUw=; b=CrCXvW32cphu3zJ6b26oha49dGHOWPcfMB29qDTHwJOf7yxGStWDG6B9xd/qfWvp1qgMMS FZZG+eQjJeKCVEXOwYqV7vopsvYd2abDcUynJR48YCCZfo91xJ2cLscweecC4/K7/wI9eo OwPF4bocFYjKrbpBp0YjKwoPPnPQImY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-324-5FlLgzd6MTCahAbrrB4eQg-1; Thu, 30 Jan 2025 12:07:42 -0500 X-MC-Unique: 5FlLgzd6MTCahAbrrB4eQg-1 X-Mimecast-MFC-AGG-ID: 5FlLgzd6MTCahAbrrB4eQg Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A26801800366; Thu, 30 Jan 2025 17:07:39 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B221530001BE; Thu, 30 Jan 2025 17:07:38 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 3/7] iomap: refactor iter and advance continuation logic Date: Thu, 30 Jan 2025 12:09:44 -0500 Message-ID: <20250130170949.916098-4-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 In preparation for future changes and more generic use of iomap_iter_advance(), lift the high level iter continuation logic out of iomap_iter_advance() into the caller. Also add some comments and rework iomap_iter() to jump straight to ->iomap_begin() on the first iteration. Signed-off-by: Brian Foster --- fs/iomap/iter.c | 66 ++++++++++++++++++++++++------------------- include/linux/iomap.h | 1 + 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 731ea7267f27..0a13d50e9ffd 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -15,31 +15,17 @@ static inline void iomap_iter_reset_iomap(struct iomap_iter *iter) } /* - * Advance to the next range we need to map. - * - * If the iomap is marked IOMAP_F_STALE, it means the existing map was not fully - * processed - it was aborted because the extent the iomap spanned may have been - * changed during the operation. In this case, the iteration behaviour is to - * remap the unprocessed range of the iter, and that means we may need to remap - * even when we've made no progress (i.e. count = 0). Hence the "finished - * iterating" case needs to distinguish between (count = 0) meaning we are done - * and (count = 0 && stale) meaning we need to remap the entire remaining range. + * Advance the current iterator position and return the length remaining for the + * current mapping. */ -static inline int iomap_iter_advance(struct iomap_iter *iter, s64 count) +int iomap_iter_advance(struct iomap_iter *iter, u64 *count) { - bool stale = iter->iomap.flags & IOMAP_F_STALE; - int ret = 1; - - if (count < 0) - return count; - if (WARN_ON_ONCE(count > iomap_length(iter))) + if (WARN_ON_ONCE(*count > iomap_length(iter))) return -EIO; - iter->pos += count; - iter->len -= count; - if (!iter->len || (!count && !stale)) - ret = 0; - - return ret; + iter->pos += *count; + iter->len -= *count; + *count = iomap_length(iter); + return 0; } static inline void iomap_iter_done(struct iomap_iter *iter) @@ -71,9 +57,16 @@ static inline void iomap_iter_done(struct iomap_iter *iter) */ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) { + bool stale = iter->iomap.flags & IOMAP_F_STALE; + s64 processed; int ret; - if (iter->iomap.length && ops->iomap_end) { + trace_iomap_iter(iter, ops, _RET_IP_); + + if (!iter->iomap.length) + goto begin; + + if (ops->iomap_end) { ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter), iter->processed > 0 ? iter->processed : 0, iter->flags, &iter->iomap); @@ -81,15 +74,30 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) return ret; } - /* advance and clear state from the previous iteration */ - trace_iomap_iter(iter, ops, _RET_IP_); - if (iter->iomap.length) { - ret = iomap_iter_advance(iter, iter->processed); + processed = iter->processed; + if (processed < 0) { iomap_iter_reset_iomap(iter); - if (ret <= 0) - return ret; + return processed; } + /* + * Advance the iter and clear state from the previous iteration. The + * remaining length of the previous iteration should be zero by this + * point, so use iter->len to determine whether to continue onto the + * next mapping. Explicitly terminate in the case where the current iter + * has not advanced at all (i.e. no work was done for some reason) + * unless the mapping has been marked stale and needs to be reprocessed. + */ + ret = iomap_iter_advance(iter, &processed); + if (!ret && iter->len > 0) + ret = 1; + if (ret > 0 && !iter->processed && !stale) + ret = 0; + iomap_iter_reset_iomap(iter); + if (ret <= 0) + return ret; + +begin: ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags, &iter->iomap, &iter->srcmap); if (ret < 0) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index f5ca71ac2fa2..f304c602e5fe 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -229,6 +229,7 @@ struct iomap_iter { }; int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); +int iomap_iter_advance(struct iomap_iter *iter, u64 *count); /** * iomap_length_trim - trimmed length of the current iomap iteration From patchwork Thu Jan 30 17:09:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954745 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71B391EEA46 for ; Thu, 30 Jan 2025 17:07:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256867; cv=none; b=ecW0TBLDPCKtK5JyFXbfKPu5mlxQEXq2GqmaMgmzvvXbQl/DBQRhQN61HAs4JstlEytapmK8RAVC+7AjSul3BQD+hfd6Riyvt8WouapCIrL7xPQqaYGkQWMxnQTx2gdcIUsZYP9/tI+ymDA8NhgdpQYVcCirdnVQwIXWwGQcVeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256867; c=relaxed/simple; bh=2EOnyOMwZ274Xu9BeWjH6QaNCnCk54bo7FxMTpbrYyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZdkdAGuhXoJzDfa6x7kmttPF5yEHVOeeudnoFQJ5gcLHEDxpXhxORzpiUBAl55814J0yvo2hjttHpU6vBzLBn7keiDO+7kokOT0hRcGIMfbcIwbSo/gk3klPgvHrP/bruDmoX/o2VFZxNH9W/Uyq+u8AYJlsEeB9/q+FfZqK6LE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FtgRoE2Z; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FtgRoE2Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GMObJwhpN7907bRscANbVFOkK7nf5mppGoAUAR3Vh4s=; b=FtgRoE2Zpq46r/BrHiLuxHbpVWYfyrA+aKJ/vhKaTtbYd1eojRjHQBw5WlA55/DV4hWMOA WeZdF7Hh9b3c3hUBA7PREnWMU5Uds/ahmPAOXAg/uRj92HGzM6L4ew1JmJaWOVP1Qq39VB KSbOLNYJSwHCpGAslMfg5H8Mob7fs+M= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-617-Mt32DkfjOIqWJdklwAus-A-1; Thu, 30 Jan 2025 12:07:41 -0500 X-MC-Unique: Mt32DkfjOIqWJdklwAus-A-1 X-Mimecast-MFC-AGG-ID: Mt32DkfjOIqWJdklwAus-A Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B3728180036E; Thu, 30 Jan 2025 17:07:40 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E7C2230001BE; Thu, 30 Jan 2025 17:07:39 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 4/7] iomap: support incremental iomap_iter advances Date: Thu, 30 Jan 2025 12:09:45 -0500 Message-ID: <20250130170949.916098-5-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 The current iomap_iter iteration model reads the mapping from the filesystem, processes the subrange of the operation associated with the current mapping, and returns the number of bytes processed back to the iteration code. The latter advances the position and remaining length of the iter in preparation for the next iteration. At the _iter() handler level, this tends to produce a processing loop where the local code pulls the current position and remaining length out of the iter, iterates it locally based on file offset, and then breaks out when the associated range has been fully processed. This works well enough for current handlers, but upcoming enhancements require a bit more flexibility in certain situations. Enhancements for zero range will lead to a situation where the processing loop is no longer a pure ascending offset walk, but rather dictated by pagecache state and folio lookup. Since folio lookup and write preparation occur at different levels, it is more difficult to manage position and length outside of the iter. To provide more flexibility to certain iomap operations, introduce support for incremental iomap_iter advances from within the operation itself. This allows more granular advances for operations that might not use the typical file offset based walk. Note that the semantics for operations that use incremental advances is slightly different than traditional operations. Operations that advance the iter directly are expected to return success or failure (i.e. 0 or negative error code) in iter.processed rather than the number of bytes processed. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- fs/iomap/iter.c | 32 +++++++++++++++++++++++++------- include/linux/iomap.h | 3 +++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 0a13d50e9ffd..bb56996de09d 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -35,6 +35,8 @@ static inline void iomap_iter_done(struct iomap_iter *iter) WARN_ON_ONCE(iter->iomap.offset + iter->iomap.length <= iter->pos); WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_STALE); + iter->iter_start_pos = iter->pos; + trace_iomap_iter_dstmap(iter->inode, &iter->iomap); if (iter->srcmap.type != IOMAP_HOLE) trace_iomap_iter_srcmap(iter->inode, &iter->srcmap); @@ -58,6 +60,8 @@ static inline void iomap_iter_done(struct iomap_iter *iter) int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) { bool stale = iter->iomap.flags & IOMAP_F_STALE; + ssize_t advanced = iter->processed > 0 ? iter->processed : 0; + u64 olen = iter->len; s64 processed; int ret; @@ -66,11 +70,22 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) if (!iter->iomap.length) goto begin; + /* + * If iter.processed is zero, the op may still have advanced the iter + * itself. Calculate the advanced and original length bytes based on how + * far pos has advanced for ->iomap_end(). + */ + if (!advanced) { + advanced = iter->pos - iter->iter_start_pos; + olen += advanced; + } + if (ops->iomap_end) { - ret = ops->iomap_end(iter->inode, iter->pos, iomap_length(iter), - iter->processed > 0 ? iter->processed : 0, - iter->flags, &iter->iomap); - if (ret < 0 && !iter->processed) + ret = ops->iomap_end(iter->inode, iter->iter_start_pos, + iomap_length_trim(iter, iter->iter_start_pos, + olen), + advanced, iter->flags, &iter->iomap); + if (ret < 0 && !advanced) return ret; } @@ -81,8 +96,11 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) } /* - * Advance the iter and clear state from the previous iteration. The - * remaining length of the previous iteration should be zero by this + * Advance the iter and clear state from the previous iteration. This + * passes iter->processed because that reflects the bytes processed but + * not yet advanced by the iter handler. + * + * The remaining length of the previous iteration should be zero by this * point, so use iter->len to determine whether to continue onto the * next mapping. Explicitly terminate in the case where the current iter * has not advanced at all (i.e. no work was done for some reason) @@ -91,7 +109,7 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) ret = iomap_iter_advance(iter, &processed); if (!ret && iter->len > 0) ret = 1; - if (ret > 0 && !iter->processed && !stale) + if (ret > 0 && !advanced && !stale) ret = 0; iomap_iter_reset_iomap(iter); if (ret <= 0) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index f304c602e5fe..0135a7f8dd83 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -211,6 +211,8 @@ struct iomap_ops { * calls to iomap_iter(). Treat as read-only in the body. * @len: The remaining length of the file segment we're operating on. * It is updated at the same time as @pos. + * @iter_start_pos: The original start pos for the current iomap. Used for + * incremental iter advance. * @processed: The number of bytes processed by the body in the most recent * iteration, or a negative errno. 0 causes the iteration to stop. * @flags: Zero or more of the iomap_begin flags above. @@ -221,6 +223,7 @@ struct iomap_iter { struct inode *inode; loff_t pos; u64 len; + loff_t iter_start_pos; s64 processed; unsigned flags; struct iomap iomap; From patchwork Thu Jan 30 17:09:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954746 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CD701EF0B4 for ; Thu, 30 Jan 2025 17:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; cv=none; b=Tc35jNy52DxdGoWapnQsneo4kHjJ74tDY5MUu5HF8O3NNW1iWfs0UgYunfOi3Kl1fwXwv/Ld7+PiKg8TZEvaKNhhAMIdt7fRJZujCAyeJvxTXjjMZbwCdpmDSvwpgVPannxTRglovnLkwOqMLMURNQc6WwTDbX1MWuNUy6zYgn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; c=relaxed/simple; bh=ekrO+DIvIeJsTz3MJBLWCVr0aC9MqZ4JDuo8KuVyjhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hHBiMlbWZojshNvU9ECt6sBnjtFgR6zxioNy6nUX1uXuNYPu/QHZC5OK3RtFjuoMSPbzaFfCAk72DmHDDDg2kPM1Jv2uADCiBrv+Erc8HdZtpCRbpBaV1JirIm6sdEz5BeTFNm2RFrYiqSFFGBa+UeOrbdqKqiOkT/iHVDtLmZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CzqnzIfh; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CzqnzIfh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=itUrYc7cJ83YbakxDByAcgZzeORx1fTgCGYX7hsyg/g=; b=CzqnzIfh19kdV13v9aMKV1xxXh9LsqoiLEA+oXojaP7dOx8G1TwyZ+btaKvcxk878vIgoy o6bDIb3Y6u98tVO91pfw9ENZXjyIo0wfzgLdpOF4nCw1JcWL9KlE5YqlIH8915o9mzLj5c zdL5rgpBtb63GNTEY4owEdH9DIn3qLk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-PrhoPEawPzeTun3hxhkJzQ-1; Thu, 30 Jan 2025 12:07:42 -0500 X-MC-Unique: PrhoPEawPzeTun3hxhkJzQ-1 X-Mimecast-MFC-AGG-ID: PrhoPEawPzeTun3hxhkJzQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C7E8E19560A3; Thu, 30 Jan 2025 17:07:41 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 071A230001BE; Thu, 30 Jan 2025 17:07:40 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 5/7] iomap: advance the iter directly on buffered writes Date: Thu, 30 Jan 2025 12:09:46 -0500 Message-ID: <20250130170949.916098-6-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Modify the buffered write path to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Also remove the -EAGAIN return hack as it is no longer necessary now that separate return channels exist for processing progress and error returns. For example, the existing write handler must return either a count of bytes written or error if the write is interrupted, but presumably wants to return -EAGAIN directly in order to break the higher level iomap_iter() loop. Since the current iteration may have made some progress, it unwinds the iter on the way out to return the error while ensuring that portion of the write can be retried. If -EAGAIN occurs at any point beyond the first iteration, iomap_file_buffered_write() will then observe progress based on iter->pos to return a short write. With incremental advances on the iomap_iter, iomap_write_iter() can simply return the error. iomap_iter() completes whatever progress was made based on iomap_iter position and still breaks out of the iter loop based on the error code in iter.processed. The end result of the write is similar in terms of being a short write if progress was made or error return otherwise. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d303e6c8900c..678c189faa58 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -909,8 +909,6 @@ static bool iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) { - loff_t length = iomap_length(iter); - loff_t pos = iter->pos; ssize_t total_written = 0; long status = 0; struct address_space *mapping = iter->inode->i_mapping; @@ -923,7 +921,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) size_t offset; /* Offset into folio */ size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ - size_t written; /* Bytes have been written */ + u64 written; /* Bytes have been written */ + loff_t pos = iter->pos; bytes = iov_iter_count(i); retry: @@ -934,8 +933,8 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) if (unlikely(status)) break; - if (bytes > length) - bytes = length; + if (bytes > iomap_length(iter)) + bytes = iomap_length(iter); /* * Bring in the user page that we'll copy from _first_. @@ -1006,17 +1005,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) goto retry; } } else { - pos += written; total_written += written; - length -= written; + iomap_iter_advance(iter, &written); } - } while (iov_iter_count(i) && length); + } while (iov_iter_count(i) && iomap_length(iter)); - if (status == -EAGAIN) { - iov_iter_revert(i, total_written); - return -EAGAIN; - } - return total_written ? total_written : status; + return total_written ? 0 : status; } ssize_t From patchwork Thu Jan 30 17:09:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954747 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A85F1EF0B9 for ; Thu, 30 Jan 2025 17:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; cv=none; b=hzbhEapQA7DuWCE17MtK80Xf2EP5XhkP+4SlSYqwLw5tmdIo55Y3Kt3ztk3ogb6zI25bVd/BGF3xLeUZTQtLt5hx8DoEcRcCqi4fkzhUv7kgZbxwPmy1uFBEL3LUBldY9Ba7CF6E29Vr/pQcljG3Atym+tYkKNwXIQ8tZEL4Gdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; c=relaxed/simple; bh=lbE0ncRQAHCxmz6OZ0krfnko+/rOEkIe83zcnTw04fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZHdPoSs8AlIv2fTai59/o5qGKf6PBBL3X7mU6gIOFcYQseVoWl1H9qa+Z+ovajC46KNndhzryP63sa24pEljpxvVvylSj/MRC++HnoU6YfM6PWOoMUcnKdGPzVaxc8nHCl+jnotOfAoM/N67VAUjKenTQOjGv5MySd3PDO5sdvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=elX+P935; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="elX+P935" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y/3n+3CqF5bkcm5ag7qCI2+ZZ+H1Wf/QP/jrJXyaQmg=; b=elX+P935iGBWSUI/CBrfFBlbh+HOa3ueNanGYOdyD3oH1RKM1hJ8x+RW16gMnXHpuwunFK MQx+bgb+xqIcDifT+J+e/FJhlweQU91oA3TaPn9yH/Jjb8WkH0YOjIM8XDAdrTo8DgBpGs tzzlQA3cUqHhyB2lJK7TABvmIuUD6VE= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-OtVSqm6xNZqQvDaE2oSYbQ-1; Thu, 30 Jan 2025 12:07:44 -0500 X-MC-Unique: OtVSqm6xNZqQvDaE2oSYbQ-1 X-Mimecast-MFC-AGG-ID: OtVSqm6xNZqQvDaE2oSYbQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D7A221955DC6; Thu, 30 Jan 2025 17:07:42 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1ABE930001BE; Thu, 30 Jan 2025 17:07:41 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 6/7] iomap: advance the iter directly on unshare range Date: Thu, 30 Jan 2025 12:09:47 -0500 Message-ID: <20250130170949.916098-7-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Modify unshare range to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 678c189faa58..f953bf66beb1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1267,20 +1267,19 @@ EXPORT_SYMBOL_GPL(iomap_write_delalloc_release); static loff_t iomap_unshare_iter(struct iomap_iter *iter) { struct iomap *iomap = &iter->iomap; - loff_t pos = iter->pos; - loff_t length = iomap_length(iter); - loff_t written = 0; + u64 bytes = iomap_length(iter); + int status; if (!iomap_want_unshare_iter(iter)) - return length; + return iomap_iter_advance(iter, &bytes); do { struct folio *folio; - int status; size_t offset; - size_t bytes = min_t(u64, SIZE_MAX, length); + loff_t pos = iter->pos; bool ret; + bytes = min_t(u64, SIZE_MAX, bytes); status = iomap_write_begin(iter, pos, bytes, &folio); if (unlikely(status)) return status; @@ -1298,14 +1297,14 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) cond_resched(); - pos += bytes; - written += bytes; - length -= bytes; - balance_dirty_pages_ratelimited(iter->inode->i_mapping); - } while (length > 0); - return written; + status = iomap_iter_advance(iter, &bytes); + if (status) + break; + } while (bytes > 0); + + return status; } int From patchwork Thu Jan 30 17:09:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13954749 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF8D01EEA46 for ; Thu, 30 Jan 2025 17:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; cv=none; b=fG6/EDqIfvpJy7jII+oXw0LDhiYqoExhkem6LUW/ZEBiGj67+yE04MGhPDX1n5UmDzHcmoOpU58RkwEVYbPYcdqslku6VMwkFYYvNFNroxnOcxhxrEjEmUnFNnP94gxB/uasrSeFGjdUXF/+we3sESW+zWkt5Sn1Aiz2Tx87uu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738256869; c=relaxed/simple; bh=L2mmDyh9vSnF5kPYcuSSCXwYdATDMPPUCAXCq1dipV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jXPg44OwdP1VTOq4UqAArfGJh/RQNNtIuOMX7QgU2rG3i5ciLB1djAA3flgJ+u1nU0YxS4i/d4XsKVhVGZ/1wnN7+oaeoVDSqZ5tepfmN7DQlOl6F8bb32aDRlKgBrLUIEX6qDcuk++6k17pXsGR7eVia6zr9qxi8I5eMSb2Lz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FgjNEAPY; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FgjNEAPY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738256866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJEIx2LIRNUN4l5wUAEOnQB79yzRujfzjRc/PncFlt4=; b=FgjNEAPYYsgWv8Fm5e8QbbRhi8mwSDj0SBN3k4zvzjfPIwN/LTy8maI47Q98hubtzapG5l oD5sXgS23Z5d8QkTdVhfQxiS1mdYE7xaKX7Key20WRxX3bDhDvExOfNVt2RU8uhSA94pqR 4AR7hOQQQyjcGOTN3eiCQ3jZUJFjQtg= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-6ACNbWsoNhuFF1WDXtdw7A-1; Thu, 30 Jan 2025 12:07:44 -0500 X-MC-Unique: 6ACNbWsoNhuFF1WDXtdw7A-1 X-Mimecast-MFC-AGG-ID: 6ACNbWsoNhuFF1WDXtdw7A Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7E921956087; Thu, 30 Jan 2025 17:07:43 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.113]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 278163003FD1; Thu, 30 Jan 2025 17:07:43 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [PATCH v3 7/7] iomap: advance the iter directly on zero range Date: Thu, 30 Jan 2025 12:09:48 -0500 Message-ID: <20250130170949.916098-8-bfoster@redhat.com> In-Reply-To: <20250130170949.916098-1-bfoster@redhat.com> References: <20250130170949.916098-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Modify zero range to advance the iter directly. Replace the local pos and length calculations with direct advances and loop based on iter state instead. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f953bf66beb1..ec227b45f3aa 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1345,17 +1345,16 @@ static inline int iomap_zero_iter_flush_and_stale(struct iomap_iter *i) static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) { - loff_t pos = iter->pos; - loff_t length = iomap_length(iter); - loff_t written = 0; + u64 bytes = iomap_length(iter); + int status; do { struct folio *folio; - int status; size_t offset; - size_t bytes = min_t(u64, SIZE_MAX, length); + loff_t pos = iter->pos; bool ret; + bytes = min_t(u64, SIZE_MAX, bytes); status = iomap_write_begin(iter, pos, bytes, &folio); if (status) return status; @@ -1376,14 +1375,14 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) if (WARN_ON_ONCE(!ret)) return -EIO; - pos += bytes; - length -= bytes; - written += bytes; - } while (length > 0); + status = iomap_iter_advance(iter, &bytes); + if (status) + break; + } while (bytes > 0); if (did_zero) *did_zero = true; - return written; + return status; } int @@ -1436,11 +1435,14 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN) { - loff_t proc = iomap_length(&iter); + s64 proc; if (range_dirty) { range_dirty = false; proc = iomap_zero_iter_flush_and_stale(&iter); + } else { + u64 length = iomap_length(&iter); + proc = iomap_iter_advance(&iter, &length); } iter.processed = proc; continue;