From patchwork Wed Jan 22 13:34:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947282 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 38C5B43AA8 for ; Wed, 22 Jan 2025 13:32:26 +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=1737552748; cv=none; b=IukJOqTHE82n9TjKKsz1CzxuYmudi06uEMHvsgW/jJBQkU1TF8ZqCyxR9rDhiT+PB7+MQjrjWS9byQgr9Ged3uiX/SXOXnp0WsCAu8KLJoZeABFA2N+nATvlLHuwiY7xNxFF2pm5EFQxi+N3IwRrkJlNz1+QqfLy5zaiGrghtJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552748; c=relaxed/simple; bh=/CcAGSXtCyzmWnS93ZOrskKZkHRoJXfInTSOetrZE0Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iD57TVhxq3elOuS9POWOuluR1Xydv0+eg0bJvki/pqRVwWkVVMet9t9n/NUM4o+KKAJ1rAEC0PO9trsuIPzv9DkJBbG4IXRPa+i7h0pMG4g1OohDseWnXD4NuKicA5c5mFd0yCMQ0Kbt5P9JFWT4twzLWJwMr8r18uZJx4qJ0rg= 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=NjNOeLSZ; 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="NjNOeLSZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552746; 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=NjNOeLSZK0KsZVsCpECuoEfh2aSIxVFaTFZ9kJtomImKKkL6NQ/TpzsiHioBFPJ1gL7fw6 H5y1rv+kRJIG9cuYQQ50fegM3E+BZVAwSndXU6HPZMjUX4j11XXi1Hxh8a9Yp5bdfKmiUL cMHkDvZwqelhm1hUKb8J7iJkEYNG+38= Received: from mx-prod-mc-01.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-20-YighNPpWOoKNiOYnBA5Pew-1; Wed, 22 Jan 2025 08:32:23 -0500 X-MC-Unique: YighNPpWOoKNiOYnBA5Pew-1 X-Mimecast-MFC-AGG-ID: YighNPpWOoKNiOYnBA5Pew Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1669619560B8; Wed, 22 Jan 2025 13:32:22 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6F70D19560A7; Wed, 22 Jan 2025 13:32:21 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 1/7] iomap: split out iomap check and reset logic from iter advance Date: Wed, 22 Jan 2025 08:34:28 -0500 Message-ID: <20250122133434.535192-2-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 Wed Jan 22 13:34:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947281 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 720C31BDCF for ; Wed, 22 Jan 2025 13:32:26 +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=1737552748; cv=none; b=TZrWZL5eiAPV126FjzK/PfA3PpvNqhjAQ2rvCg8kKsSc0WozrUQfeFi260Xs7xMGrZJ/nXmd8lxEBEAc+HTz02p4xeIcODWRXjttWFnIiKeICE0FmLqG8v29+U/HFzhIOLnsHwrNnux1TMcu5pFhFGGoMWjeUFW1OAE9oXGfZ9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552748; c=relaxed/simple; bh=jG34dVuSjv0z2kFCOUY6Xx2vuTQQe1eQNxGnCYQWBsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FtyKBBpB8vLLIMUS31p+U3++BUp3lebEx28S76Q/V9oa3T/A/8qLE/hGlF/9uYbqpCw14D3n+9y9TdIaP+X+hmd2zwze9R17vL1MxoDApQlXtPw/IWqg1+q7UERMwNh1oDo/3Z63Opz8xO1cGqImb6gE3G7RyZnbfs+l2/aHcyI= 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=G12vyERc; 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="G12vyERc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552745; 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=Fubx2YvHL6SBTZx4vMOkPvsm0q8yavBOqWeP66VgBDA=; b=G12vyERc2Ud+mnry0lyvR2nMa2F0U8o2ozvkueTJeJjfVsQ7fbZYamWroEPYjlC1ILOLOK 032ue4Qc97ucIwnbMqlf5xdgwQnsCVIa/s/PPOZUrIBXJxkLVelu84P5O7qyT6giDmUa4c 8B+AAE35h+hNKAKG0W+p28U73A0tTGc= Received: from mx-prod-mc-05.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-330-oMCk6Pp5Pou3YEYefd1Jjg-1; Wed, 22 Jan 2025 08:32:23 -0500 X-MC-Unique: oMCk6Pp5Pou3YEYefd1Jjg-1 X-Mimecast-MFC-AGG-ID: oMCk6Pp5Pou3YEYefd1Jjg Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BBCCF1954185; Wed, 22 Jan 2025 13:32:22 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 34ED819560A7; Wed, 22 Jan 2025 13:32:22 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 2/7] iomap: factor out iomap length helper Date: Wed, 22 Jan 2025 08:34:29 -0500 Message-ID: <20250122133434.535192-3-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 In preparation to support more granular iomap iter advancing, factor the pos/len values as parameters to length calculation. Signed-off-by: Brian Foster --- include/linux/iomap.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 75bf54e76f3b..b6f7d96156f2 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -230,6 +230,16 @@ struct iomap_iter { int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); +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(len, end - pos); +} + /** * iomap_length - length of the current iomap iteration * @iter: iteration structure @@ -238,11 +248,7 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); */ static inline u64 iomap_length(const struct iomap_iter *iter) { - 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 iomap_length_trim(iter, iter->pos, iter->len); } /** From patchwork Wed Jan 22 13:34:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947284 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 CECE6211A3B for ; Wed, 22 Jan 2025 13:32:28 +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=1737552750; cv=none; b=B3OO6Wvg7PmYUMupF6Hgus02hhscyExXRt19LVoAOwVkZmnA58pcOSQ+NKLR2m4Y4Zv/eHoSv76iAgrS5Tfj9WQwSUzpn7LFLs2ggUnLWc3UlCVO0cbwKb9qLpHNa/NLJ+FC9I2gGJxS8lNdATCpAT3fV3vXYKEmKWGjAkVs8Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552750; c=relaxed/simple; bh=TOr5oWgkH7Q9YZBsYXY+h3c0MXVUiTU0kiQvMSdB7rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c9ix8pNrXhKrYLwT1a9dJMd+70kJotisuJNTnDx1DHKADoHhJ0Y8BbSiiOVk0sImLmyo8u/uN40q0l7DHeYjrCWULAx534G+Qhn7CfOsveyzsFGJvZuNUWwIwgGX9CxCwRFtc7o8d+o612oCWS+Ae1C5sxs4VwsmhDjjNAptWdI= 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=eQktUS+X; 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="eQktUS+X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552747; 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=JEoq9O+sN6/C9lYpYN4gpK7SEnLTWIvXxcVRZYusifI=; b=eQktUS+XJUeDRZY/ce2g9FRapw4qXnS7stvrosEPP8C9Vom+FYmg5u7qY3VzyLKi+R8Vui TSaPVZAAUhmB0/GV42fn8GjdHTdHXg7mZHhjjQB8JzaBLqi6TWvfKmAf8t9jf34y0pDljx gcpL7e+pSrMfMK12qH70HCfqOZtUOkY= 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-550-M8mAoWQNNl2FFwpSe2brZw-1; Wed, 22 Jan 2025 08:32:24 -0500 X-MC-Unique: M8mAoWQNNl2FFwpSe2brZw-1 X-Mimecast-MFC-AGG-ID: M8mAoWQNNl2FFwpSe2brZw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 7C7C119560B4; Wed, 22 Jan 2025 13:32:23 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE5F419560A7; Wed, 22 Jan 2025 13:32:22 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 3/7] iomap: refactor iter and advance continuation logic Date: Wed, 22 Jan 2025 08:34:30 -0500 Message-ID: <20250122133434.535192-4-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 | 54 +++++++++++++++++++++++-------------------- include/linux/iomap.h | 1 + 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 731ea7267f27..260ec702ddd5 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -15,31 +15,19 @@ 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) +s64 iomap_iter_advance(struct iomap_iter *iter, s64 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))) return -EIO; iter->pos += count; iter->len -= count; - if (!iter->len || (!count && !stale)) - ret = 0; - return ret; + return iomap_length(iter); } static inline void iomap_iter_done(struct iomap_iter *iter) @@ -71,9 +59,15 @@ static inline void iomap_iter_done(struct iomap_iter *iter) */ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) { - int ret; + s64 ret; + bool stale = iter->iomap.flags & IOMAP_F_STALE; - if (iter->iomap.length && ops->iomap_end) { + if (!iter->iomap.length) { + trace_iomap_iter(iter, ops, _RET_IP_); + 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 +75,25 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) return ret; } - /* advance and clear state from the previous iteration */ + /* + * 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. + */ trace_iomap_iter(iter, ops, _RET_IP_); - if (iter->iomap.length) { - ret = iomap_iter_advance(iter, iter->processed); - iomap_iter_reset_iomap(iter); - if (ret <= 0) - return ret; - } + ret = iomap_iter_advance(iter, iter->processed); + if (!ret) + ret = iter->len; + 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 b6f7d96156f2..88bde0259035 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); +s64 iomap_iter_advance(struct iomap_iter *iter, s64 count); static inline u64 iomap_length_trim(const struct iomap_iter *iter, loff_t pos, u64 len) From patchwork Wed Jan 22 13:34:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947283 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 A0A371805B for ; Wed, 22 Jan 2025 13:32:27 +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=1737552749; cv=none; b=BTq03ZvHHjmAOHOPptN9s/sPhyOHtzmDG4ULrACRRbfbuFaweXi+iodf09azw5f+Du6HtyQOIWppe4m57PPPeLUFnRBT7oFvimmJUk967i9PbM6Id0TrBOM24nDtZL2R/fvSlXj8p0ihep9/yG5c97RhpTkPVjBjrBBsGuCUTjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552749; c=relaxed/simple; bh=z4IOxpwg7m38o5rBDHCM8b7YriJ5ilTeqiIsaX4pvzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Gc0UxJHL4Mgh8rj8LXnJXAgfsKUMsdSAntxaM7KczLJV0o68vN82GEE45T/uRhfnQjpAJNKmZF6mTmdP4yxRzUXTNLju0N76dNljAN0Y2mwE8HICDt2le6q91lT9b1Kd0xWhXS4kv+FcRRzCu0ebtTdc8GTIs6mMxvb8QH3Akx4= 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=WdjS0wOk; 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="WdjS0wOk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552746; 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=6WKOAxT8IJe6f0d/3nAl0CkQjJPq7V0QFs8Ayh8xcUU=; b=WdjS0wOkkvgWcIM9dLx5AvH8B8q4VH2m92tWvlcO6VvMMciaX0ohALm70BwY2jfvCXYEpo pgEy7Wafmyu9r5r2wcYXPLMv6osjNT3lv7LDXIs+SnAD4jqtjbuu9IWXjqN/rQ96oL18mQ Yc7SySkMnMzE9uAawG/EsKAIJUx1QHM= 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-554-lkIA_WbeMpesQ5MZ5VJB4w-1; Wed, 22 Jan 2025 08:32:25 -0500 X-MC-Unique: lkIA_WbeMpesQ5MZ5VJB4w-1 X-Mimecast-MFC-AGG-ID: lkIA_WbeMpesQ5MZ5VJB4w Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 58FEE1955F2D; Wed, 22 Jan 2025 13:32:24 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CBE1A19560A7; Wed, 22 Jan 2025 13:32:23 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 4/7] iomap: support incremental iomap_iter advances Date: Wed, 22 Jan 2025 08:34:31 -0500 Message-ID: <20250122133434.535192-5-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 --- 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 260ec702ddd5..191c54976c9f 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -37,6 +37,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); @@ -61,23 +63,39 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) { s64 ret; bool stale = iter->iomap.flags & IOMAP_F_STALE; + ssize_t advanced = iter->processed > 0 ? iter->processed : 0; + u64 olen = iter->len; if (!iter->iomap.length) { trace_iomap_iter(iter, ops, _RET_IP_); 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; } /* - * 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) @@ -87,7 +105,7 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) ret = iomap_iter_advance(iter, iter->processed); if (!ret) ret = iter->len; - 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 88bde0259035..24fefc5fa868 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 Wed Jan 22 13:34:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947286 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 D21212139CF for ; Wed, 22 Jan 2025 13:32:30 +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=1737552752; cv=none; b=EpBzTzNcIU4LpKpx2pxV5+C6p3ArxMro6FSGhxpOLUH8ukpCXmITjV4anuzunL9oBagehg5K9oQ2KAz9jkWx6tqb4uy9Id9MGmq1K7A2xDPJO4ZMwlWEpQVSOkytwqD1qu9zcS3qOnWpQSL/czFULK8uHKywWmWzcmgxR+tD56w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552752; c=relaxed/simple; bh=1S0yP/HCLrsDKKnvySfXDGW0JgfruBOW9SNeC2TS2Yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fXnzaQFXSS34sg/7BICrmEeBgey5EmyQT8WFSxI7tGPx6gp61xUPpL8t5auEqf2Ly4JFj/+K7A4R+Qos33wozbTo2CqtV1q0aNDo6zibUutMtkjN2CIe9f6vZEpJqrI2PLdFJp/znZYDyIG2qVFJP/MuO9SguLo9e9ZJPRkG7WM= 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=gXw4ASmS; 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="gXw4ASmS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552749; 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=9ni4MtcmObBcpCLvWoh0Vb2qmmliPfRLxpaAasXPoxU=; b=gXw4ASmS9Gh4sfBIjAxmA5bqB0SFR5I1f1tsWvPla7VoqTCOOky6npbm/tCeOvT0u6+GMQ dbYaURJLRTN1sSOEW+roPr0wkRBKXKJdtolCqnKnRtgtAbuYC+gAALsAWKAlnjOnsERZzB dAFHHgjqk7rOtjPCSv+SoX1FxledURk= 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-556-WzXHk217OE2LtaS5J4G18g-1; Wed, 22 Jan 2025 08:32:26 -0500 X-MC-Unique: WzXHk217OE2LtaS5J4G18g-1 X-Mimecast-MFC-AGG-ID: WzXHk217OE2LtaS5J4G18g Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 1FC411955DCD; Wed, 22 Jan 2025 13:32:25 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 91B4119560A7; Wed, 22 Jan 2025 13:32:24 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 5/7] iomap: advance the iter directly on buffered writes Date: Wed, 22 Jan 2025 08:34:32 -0500 Message-ID: <20250122133434.535192-6-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 --- fs/iomap/buffered-io.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d303e6c8900c..5ce5ac13765a 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; @@ -924,6 +922,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ size_t 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 Wed Jan 22 13:34:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947287 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 C57982139DF for ; Wed, 22 Jan 2025 13:32:31 +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=1737552753; cv=none; b=URvuGNnb0gOsEb+j7i+XnouBdMLBLi5czF6vdWFjWd1QLYWfE19OcsxTsbu8T8aibgSK9RLiILprLGFLBBAZUBZMYPRJW6JPn3LPzrWtNyESm09KNBT13xSBA0qAAUxFfjWeJ0k+fJAw3rpxvgBe/5ZsJYQvKsLS5cf5ZbHxve8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552753; c=relaxed/simple; bh=lcxzeyS7a0otdRQgwjckI/OoCYvCmPjueqIrN+nQ05g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=obw3ZuSX5TusLADb4SPZmljYaX3APKa4LmgefXwnob9WE4Ip4qF2FCJ/N9h1sRRIp8wA8MhqwsEJNkBIwLFDQBpTRwKn8VZH6Z+n60bHkMzxGFJ6UtpviOm3x7dIVHKDDFl+hP8Z7paUUikoiFKkFQFbgibICotAc/KjlckiWvo= 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=IgjGwat9; 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="IgjGwat9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552751; 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=WGxCjJpOVgRhQ7tRIZNKtyYICibtpE7J7ZlY21+0Ln8=; b=IgjGwat9sUxP0Xuqy/yDiuUKmjSIJ4xlHiwHVgrR9GaVS7wINPJnzM9Npvd2ibggg2xcI7 5K9qJhcRKnkUm3PMlRBRaBc3FwrHCjogam6/ag65ShliCzEg8fpBbmsiUnSa6u6/YNA+C1 3g82ikck8jJruwqppZjaVjuJ7nNp75I= 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-526-y9HWeXfQOKO1tsfCSvCDIw-1; Wed, 22 Jan 2025 08:32:27 -0500 X-MC-Unique: y9HWeXfQOKO1tsfCSvCDIw-1 X-Mimecast-MFC-AGG-ID: y9HWeXfQOKO1tsfCSvCDIw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 DA06F1956087; Wed, 22 Jan 2025 13:32:25 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 575CE19560A7; Wed, 22 Jan 2025 13:32:25 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 6/7] iomap: advance the iter directly on unshare range Date: Wed, 22 Jan 2025 08:34:33 -0500 Message-ID: <20250122133434.535192-7-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 --- fs/iomap/buffered-io.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 5ce5ac13765a..ea140d3098ff 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; + size_t bytes = iomap_length(iter); if (!iomap_want_unshare_iter(iter)) - return length; + return 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,10 @@ 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); + } while ((bytes = iomap_iter_advance(iter, bytes)) > 0); - return written; + return bytes < 0 ? bytes : 0; } int From patchwork Wed Jan 22 13:34:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13947285 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 6FB8B2135DE for ; Wed, 22 Jan 2025 13:32:30 +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=1737552752; cv=none; b=i0N9neyXJEElF1cAkcEgGlaWdzFuWI3g8a2MRfLvvBYUHxzuOeAkcwaEkHROBCpLGN0jyl8kjSvDvMIuf/AeuKBGc7azdssFLQCIKUIHQY5fMUq4N51gVASeNSZwIsGZ9I4Y2GuKhErxzkP0WsaM7wwAckM5y/gXyr9v4bFzJdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737552752; c=relaxed/simple; bh=lwG2BDVsDqAqG9hTBHindPdECeSDnbfuTslTxwHs88g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tTvPUj1iaxGn8SzNe8j0Y8h4HL0uy+qpkJqHK1uJwIeNXXtXWf2XSEHEWbOyxA2bzc7tjn5zF9+7VyVnFhzH3nAxqVGpiyCE266A9+EDPBsPDOxnNGqFfWwkjciB/XDbeZMervbgN3nMI2FtkNOfT2xrvdNpLgjqKEhXdAq7g6g= 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=Ml+7bstN; 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="Ml+7bstN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737552749; 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=c8ow9AvUlMusll3m0l7rcYElRLAAREVFTuTJeL7Pt4g=; b=Ml+7bstNGFN0m9mkHfAp2aSCX9acQlvZC44pJCr9XAgZ0QyL/TO7aszuw7x/uYaIMRLQt3 7EqKJ9sqgYvkKAhiX/+9XOd2LtZ8WNQsSU7SxLKL6dwD9gqUU0rXdOg+qs7CuAKb7H8yfH oYcGK80LMq6pWpMN2dHcgjuHrHQL21Q= Received: from mx-prod-mc-03.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-584-rgT2jz7fPu2AkEbIQa3fEg-1; Wed, 22 Jan 2025 08:32:27 -0500 X-MC-Unique: rgT2jz7fPu2AkEbIQa3fEg-1 X-Mimecast-MFC-AGG-ID: rgT2jz7fPu2AkEbIQa3fEg Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D05A819560BB; Wed, 22 Jan 2025 13:32:26 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.118]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E65A19560A7; Wed, 22 Jan 2025 13:32:25 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH v2 7/7] iomap: advance the iter directly on zero range Date: Wed, 22 Jan 2025 08:34:34 -0500 Message-ID: <20250122133434.535192-8-bfoster@redhat.com> In-Reply-To: <20250122133434.535192-1-bfoster@redhat.com> References: <20250122133434.535192-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.0 on 10.30.177.12 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 --- fs/iomap/buffered-io.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ea140d3098ff..83ef6715a4b6 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1341,17 +1341,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; + size_t bytes = iomap_length(iter); 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; @@ -1371,15 +1370,11 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) __iomap_put_folio(iter, pos, bytes, folio); if (WARN_ON_ONCE(!ret)) return -EIO; - - pos += bytes; - length -= bytes; - written += bytes; - } while (length > 0); + } while ((bytes = iomap_iter_advance(iter, bytes)) > 0); if (did_zero) *did_zero = true; - return written; + return bytes < 0 ? bytes : 0; } int