From patchwork Fri Feb 7 14:32:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13965117 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 5A26D23F278 for ; Fri, 7 Feb 2025 14:30: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=1738938646; cv=none; b=sMD4J3s+/wpmknSuagJ1Yn3ewtDLczjs0tqX2WpymaGWzl14FjNvP4mo44Czw//mPHVhcbm8lyCeCiBLoyJPxOepcQN6hONridehEKob8V3ft85Hiv9TF42beZKkmk5cxDPKH0Aurwi789TwZAAWka0IkVhdZveXNi90tAM27z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738938646; c=relaxed/simple; bh=VxUEtXygQEv9MTYLdcDHOBW8Luc1WgzkSSM9iVDR3uM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RXdIbUeLtiTQ8fjMHBHaL+as8wtXFmytWAmUixk9M8V36mVLmpcvvD1q9XLxydsc5nMmpPk3pO2LxoFN86qx1+iXlJI538tmcKAtbpHr1OTMK4cIjwsgktguvpJruzEgO11TiCx40hTmod9ewa+S98t63YtvODj/TdwegVcdlC4= 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=WpflGlJ6; 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="WpflGlJ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738938643; 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=EatKyd0bvTBoT1BNAaLTQ7nQTs0xc2M1UPIx6snl7nQ=; b=WpflGlJ6I9e6/vE15bhPiUvMuqhJ138cMov3jSfbRxgJ/IcroW0PETPOhELMqZP8Dhj/Ai WNPQ1+mfWUQNhXrmOOZFwG5oPLrqc2waWQD0jQSdZnQuJ7FTffMl4u9hN1wMCutFO6YsDe lhs2QnIYz3Rb6ipDnHKmM4YLPoasxSI= 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-199-8anW0pWhMimQbO9itgc9nw-1; Fri, 07 Feb 2025 09:30:39 -0500 X-MC-Unique: 8anW0pWhMimQbO9itgc9nw-1 X-Mimecast-MFC-AGG-ID: 8anW0pWhMimQbO9itgc9nw Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 858201801A3D; Fri, 7 Feb 2025 14:30:38 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.88.48]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9F2A2180087A; Fri, 7 Feb 2025 14:30:37 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, Christoph Hellwig , "Darrick J . Wong" Subject: [PATCH v6 09/10] iomap: advance the iter directly on unshare range Date: Fri, 7 Feb 2025 09:32:52 -0500 Message-ID: <20250207143253.314068-10-bfoster@redhat.com> In-Reply-To: <20250207143253.314068-1-bfoster@redhat.com> References: <20250207143253.314068-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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 Reviewed-by: "Darrick J. Wong" --- 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