From patchwork Tue Nov 19 15:46:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13880202 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 2978D1D173E for ; Tue, 19 Nov 2024 15:45:28 +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=1732031133; cv=none; b=tqF0OnCUEQX3vD3KAe+SmzKrbG5bBWyzI9wiQ13t45ybl/VwwofvVUpAOqIHDPuP6rDnwUzvmYhnDKegPccdeT3n2W8v/ijgdNnV6WCrlC4jHQ5mjF8WyoXZHpbfD8xbk1LfSf+KyhmxhzlmK2gSt0yocCVhzjIwuGfcuvci6Gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; c=relaxed/simple; bh=DUqTZuX3ibPNvI0oVsl5z3VIK6xmqdlnQ95TwMVcteo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SgzHl8/ewoN5cgL46bTlI1L80aQF64fX4CCIwUK5PIkylv4/c3BWkA9KJBdnVmDDNffRtSN1nej1Q1Fo6sbGmkf1zX9ienUFc1ZW7I4RiVzVLOxAXIWEcBiockd6kNe7CeEp+rJKCVswPCpz73mVvmddpr5cdDArsdEf9Td30PI= 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=aDBKlvJV; 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="aDBKlvJV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732031127; 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=hjZU7g2vo6uZ/HXSxZz5fNHUtmju3LrZ0LlIZ9RX0h4=; b=aDBKlvJVKuJ3ez6Lf4oIStYrUXlDRnXce9YMASU06GScsXJmGYV363mUfCS2oagDR/BaTx 0vI45cIyJtpkg4Nr1gTrAAWcvR8jbF9dO+gW337kFQK0RR5BCkspwkznQzHzgEa09rz7cb lq1IAbgs3yZmaBwbkY315TWM06EQHUc= 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-505-4m05kcxjMXy3WLJZNo6vmg-1; Tue, 19 Nov 2024 10:45:24 -0500 X-MC-Unique: 4m05kcxjMXy3WLJZNo6vmg-1 X-Mimecast-MFC-AGG-ID: 4m05kcxjMXy3WLJZNo6vmg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 54107195608D; Tue, 19 Nov 2024 15:45:23 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.120]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AFFDE1956054; Tue, 19 Nov 2024 15:45:22 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH RFC 1/4] iomap: allow passing a folio into write begin path Date: Tue, 19 Nov 2024 10:46:53 -0500 Message-ID: <20241119154656.774395-2-bfoster@redhat.com> In-Reply-To: <20241119154656.774395-1-bfoster@redhat.com> References: <20241119154656.774395-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.0 on 10.30.177.40 To facilitate batch processing of dirty folios for zero range, tweak the write begin path to allow the caller to optionally pass in its own folio/pos combination. Signed-off-by: Brian Foster --- fs/iomap/buffered-io.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index ce73d2a48c1e..d1a86aea1a7a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -781,7 +781,7 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, { const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); - struct folio *folio; + struct folio *folio = *foliop; int status = 0; BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); @@ -794,9 +794,15 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (!mapping_large_folio_support(iter->inode->i_mapping)) len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); - folio = __iomap_get_folio(iter, pos, len); - if (IS_ERR(folio)) - return PTR_ERR(folio); + /* + * XXX: Might want to plumb batch handling down through here. For now + * let the caller do it. + */ + if (!folio) { + folio = __iomap_get_folio(iter, pos, len); + if (IS_ERR(folio)) + return PTR_ERR(folio); + } /* * Now we have a locked folio, before we do anything with it we need to @@ -918,7 +924,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0; do { - struct folio *folio; + struct folio *folio = NULL; loff_t old_size; size_t offset; /* Offset into folio */ size_t bytes; /* Bytes to write to folio */ @@ -1281,7 +1287,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) return length; do { - struct folio *folio; + struct folio *folio = NULL; int status; size_t offset; size_t bytes = min_t(u64, SIZE_MAX, length); @@ -1385,7 +1391,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero, } do { - struct folio *folio; + struct folio *folio = NULL; int status; size_t offset; size_t bytes = min_t(u64, SIZE_MAX, length); From patchwork Tue Nov 19 15:46:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13880200 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 0F10B1CF7BE for ; Tue, 19 Nov 2024 15:45:29 +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=1732031133; cv=none; b=q6as0nJ7DQ8rB/9AzvDpABO1smlj9MausXyDwZwI64qlNoR+FnHHLcQQFXrCLpqA0R1+4A3tED7Ra9QdWbEpx3A/zQnOuqzbgcQhrqvk6PhAccgCUiOcp7wRTuUhwizLBXtJ5q847vyTFXEUGkO/AiZC8HhjGf3V5DY3wTDdn2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; c=relaxed/simple; bh=kJvpJZ2rB/n1fbKdG94ZaOzMLFaxvHxVYfCJhvP4wIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b4JOBH9aqJBr/coV0J6Mm2pFxSxRKfcBa/gdBW/vKmzSn5JOlks6zgs+YV6dal5c9ZrFjWrFY/guP0QjwSpfVYD2peC137/IDbnTuD07gQWRHTKsJF4gbW6VUL0ZDsl4zd20wpvrHqtxfTxxe3l3HygS8gGmYIX67VnnYElEJaU= 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=T2Fu5KnA; 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="T2Fu5KnA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732031128; 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=bHqlysNI/yd9h9n6zI5JWgrvL8hrKLdDCdZulMRML+I=; b=T2Fu5KnATSp8L8/hyxbTOehIvHIbUOqf0qtnqm068gk1pASJfS04gSVFL1L38zzNON8W2m siQsvIxhqHlhLqamcigLuPPqaGdWYHR7K/D0NZfRiaJGhbZVV719KWXUuCHWaA6kvYYA+m dAb/Q7FbOHGpqk6oct1wdNUJwKsgXrQ= 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-50-D1EBFa-LMOGKNfeK6OjVTw-1; Tue, 19 Nov 2024 10:45:25 -0500 X-MC-Unique: D1EBFa-LMOGKNfeK6OjVTw-1 X-Mimecast-MFC-AGG-ID: D1EBFa-LMOGKNfeK6OjVTw Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 3E2D119560AA; Tue, 19 Nov 2024 15:45:24 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.120]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 979AE1956054; Tue, 19 Nov 2024 15:45:23 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH RFC 2/4] iomap: optional zero range dirty folio processing Date: Tue, 19 Nov 2024 10:46:54 -0500 Message-ID: <20241119154656.774395-3-bfoster@redhat.com> In-Reply-To: <20241119154656.774395-1-bfoster@redhat.com> References: <20241119154656.774395-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.0 on 10.30.177.40 The only way zero range can currently process unwritten mappings with dirty pagecache is to check whether the range is dirty before mapping lookup and then flush when at least one underlying mapping is unwritten. This ordering is required to prevent iomap lookup from racing with folio writeback and reclaim. Since zero range can skip ranges of unwritten mappings that are clean in cache, this operation can be improved by allowing the filesystem to provide the set of folios backed by such mappings that require zeroing up. In turn, rather than flush or iterate file offsets, zero range can process each folio as normal and skip any clean or uncached ranges in between. As a first pass prototype solution, stuff a folio_batch in struct iomap, provide a helper that the fs can use to populate the batch at lookup time, and define a flag to indicate the mapping was checked. Note that since the helper is intended for use under internal fs locks, it trylocks folios in order to filter out clean folios. This loosely follows the logic from filemap_range_has_writeback(). Signed-off-by: Brian Foster --- fs/iomap/buffered-io.c | 73 ++++++++++++++++++++++++++++++++++++++++-- fs/iomap/iter.c | 2 ++ include/linux/iomap.h | 5 +++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d1a86aea1a7a..6ed8dc8dcdd9 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1363,6 +1363,10 @@ 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; + bool has_folios = !!(iter->iomap.flags & IOMAP_F_HAS_FOLIOS); + + if (WARN_ON_ONCE(has_folios && srcmap->type != IOMAP_UNWRITTEN)) + return -EIO; /* * We must zero subranges of unwritten mappings that might be dirty in @@ -1381,7 +1385,8 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero, * post-eof ranges can be dirtied via mapped write and the flush * triggers writeback time post-eof zeroing. */ - if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN) { + if (!has_folios && + (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN)) { if (*range_dirty) { *range_dirty = false; return iomap_zero_iter_flush_and_stale(iter); @@ -1395,8 +1400,28 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero, int status; size_t offset; size_t bytes = min_t(u64, SIZE_MAX, length); + size_t skipped = 0; bool ret; + if (has_folios) { + folio = folio_batch_next(&iter->iomap.fbatch); + if (!folio) { + written += length; + break; + } + folio_get(folio); + folio_lock(folio); + if (pos < folio_pos(folio)) { + skipped = folio_pos(folio) - pos; + if (WARN_ON_ONCE(skipped >= length)) + break; + pos += skipped; + length -= skipped; + bytes = min_t(u64, SIZE_MAX, length); + } else + WARN_ON_ONCE(pos >= folio_pos(folio) + folio_size(folio)); + } + status = iomap_write_begin(iter, pos, bytes, &folio); if (status) return status; @@ -1417,7 +1442,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero, pos += bytes; length -= bytes; - written += bytes; + written += bytes + skipped; } while (length > 0); if (did_zero) @@ -1425,6 +1450,50 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero, return written; } +loff_t +iomap_fill_dirty_folios( + struct inode *inode, + struct iomap *iomap, + loff_t offset, + loff_t length) +{ + struct address_space *mapping = inode->i_mapping; + struct folio_batch fbatch; + pgoff_t start, end; + loff_t end_pos; + + folio_batch_init(&fbatch); + folio_batch_init(&iomap->fbatch); + + end_pos = offset + length; + start = offset >> PAGE_SHIFT; + end = (end_pos - 1) >> PAGE_SHIFT; + + while (filemap_get_folios(mapping, &start, end, &fbatch) && + folio_batch_space(&iomap->fbatch)) { + struct folio *folio; + while ((folio = folio_batch_next(&fbatch))) { + if (folio_trylock(folio)) { + bool clean = !folio_test_dirty(folio) && + !folio_test_writeback(folio); + folio_unlock(folio); + if (clean) + continue; + } + + folio_get(folio); + if (!folio_batch_add(&iomap->fbatch, folio)) { + end_pos = folio_pos(folio) + folio_size(folio); + break; + } + } + folio_batch_release(&fbatch); + } + + return end_pos; +} +EXPORT_SYMBOL_GPL(iomap_fill_dirty_folios); + int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index 79a0614eaab7..3c87b5c2b1d9 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -25,6 +25,8 @@ static inline int iomap_iter_advance(struct iomap_iter *iter) /* handle the previous iteration (if any) */ if (iter->iomap.length) { + if (iter->iomap.flags & IOMAP_F_HAS_FOLIOS) + folio_batch_release(&iter->iomap.fbatch); if (iter->processed < 0) return iter->processed; if (!iter->processed && !stale) diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 27048ec10e1c..7e9d86c3defa 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -9,6 +9,7 @@ #include #include #include +#include struct address_space; struct fiemap_extent_info; @@ -77,6 +78,7 @@ struct vm_fault; */ #define IOMAP_F_SIZE_CHANGED (1U << 8) #define IOMAP_F_STALE (1U << 9) +#define IOMAP_F_HAS_FOLIOS (1U << 10) /* * Flags from 0x1000 up are for file system specific usage: @@ -102,6 +104,7 @@ struct iomap { void *inline_data; void *private; /* filesystem private */ const struct iomap_folio_ops *folio_ops; + struct folio_batch fbatch; u64 validity_cookie; /* used with .iomap_valid() */ }; @@ -301,6 +304,8 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len); bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio); int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, const struct iomap_ops *ops); +loff_t iomap_fill_dirty_folios(struct inode *inode, struct iomap *iomap, + loff_t offset, loff_t length); int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops); int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, From patchwork Tue Nov 19 15:46:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13880203 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 58A0D1D175F for ; Tue, 19 Nov 2024 15:45:30 +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=1732031133; cv=none; b=KWjNx0B6X/CD9qCMXlShZuZr8qqE7VFhPHZaZ7qZfksBsQcfGtvfAG50bJt9tb1M17PYBJ4no8mS8CddlFwkB582BoZGtCGX8EpGjfj55gOwTqymPe9Lt/P5nyyQGsxO0mOQYYZuSxXRGnKAeo70yHowJ834zyuGUv41s4Tfvck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; c=relaxed/simple; bh=chq172AyjyM/iZFpfyYDd/V8b53y57CNzSUdA6qOcV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ac7CLMcrUiCZ3/H/G/fH8y4iYBfA+2M5nI7DJZwBxxEzc590khp2W0/xkGQ/6Da6Rhvvl4/ylmLjsj3YGQ+YkkOk7cZ5SM7t1AuTUr+lhcUVcBhLUQ6XRxjSmr6mSYGN+OJt3yYMT+RBFmA1tBW5jPqF4z5kte8ScqEiMRLX3jk= 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=avrFsRYz; 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="avrFsRYz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732031129; 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=MHORF4G4Jsb1yaGbLK+HoWRyvTj4g/Fx1gHFlkLoziw=; b=avrFsRYzhgDEcTUQirF/gYC4Hs956/jyHuMW9omh3tbTqlmgKLo9BDvYBqNnzoriFtKmvG gioB8ralPUywefsdKqXxOSKgGITgoQ2P5RvxRZMuZvkZzn9ByCJkWb6dpje04bRztEPji5 T8TJ9ZzWHhQdT9OxO1ehfF8mRUROed4= 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-385-ioXXfXXQPea8dp236fnqVQ-1; Tue, 19 Nov 2024 10:45:26 -0500 X-MC-Unique: ioXXfXXQPea8dp236fnqVQ-1 X-Mimecast-MFC-AGG-ID: ioXXfXXQPea8dp236fnqVQ Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 2AE0219560B0; Tue, 19 Nov 2024 15:45:25 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.120]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 811021956054; Tue, 19 Nov 2024 15:45:24 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH RFC 3/4] xfs: always trim mapping to requested range for zero range Date: Tue, 19 Nov 2024 10:46:55 -0500 Message-ID: <20241119154656.774395-4-bfoster@redhat.com> In-Reply-To: <20241119154656.774395-1-bfoster@redhat.com> References: <20241119154656.774395-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.0 on 10.30.177.40 Refactor and tweak the IOMAP_ZERO logic in preparation to support filling the folio batch for unwritten mappings. Drop the superfluous imap offset check since the hole case has already been filtered out. Split the the delalloc case handling into a sub-branch, and always trim the imap to the requested offset/count so it can be more easily used to bound the range to lookup in pagecache. Signed-off-by: Brian Foster --- fs/xfs/xfs_iomap.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 86da16f54be9..ed42a28973bb 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1029,17 +1029,16 @@ xfs_buffered_write_iomap_begin( * block. If it starts beyond the EOF block, convert it to an * unwritten extent. */ - if ((flags & IOMAP_ZERO) && imap.br_startoff <= offset_fsb && - isnullstartblock(imap.br_startblock)) { - xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); - - if (offset_fsb >= eof_fsb) - goto convert_delay; - if (end_fsb > eof_fsb) { - end_fsb = eof_fsb; - xfs_trim_extent(&imap, offset_fsb, - end_fsb - offset_fsb); + if (flags & IOMAP_ZERO) { + if (isnullstartblock(imap.br_startblock)) { + xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); + + if (offset_fsb >= eof_fsb) + goto convert_delay; + if (end_fsb > eof_fsb) + end_fsb = eof_fsb; } + xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb); } /* From patchwork Tue Nov 19 15:46:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 13880201 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 01AC31CFEB0 for ; Tue, 19 Nov 2024 15:45:29 +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=1732031133; cv=none; b=J3p7/UNqH5e8FHmnucRKU4aQYtimhpg9IvMKG/SFsgex1jZlVevs83KtqUdr6iVXmNH/D3tR5di17hY8rMJaPS6cEzaxzkbr8BwqkHThc6l8AW6RVm12hAsIUCYKEdLOmlQv5k0Q/M0RaqjjGjqC/ZkDBid+GSe4de7Y5SeUuxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732031133; c=relaxed/simple; bh=Up3cclIyE+AvTp4pGY/iLJVrtvPIKk/vFgFUeo+opMQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W7F2rIHNbPU/0Yp7T62J17OC+dS6iQSuImj8NM3uDjhf/GonziwH2b5BZT/amlajwP49j+HogCmN3B8Qp1baJbcDEiMYKZAr2eG9b7R1c1jL9Yj+a7eabI8PCvV1LYZR3TPh2HTYkNV4+wBgD4C2uS2TqQgV50K3WjVQ5qdRTIg= 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=X11X8PJN; 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="X11X8PJN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732031128; 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=8f8HKbKWh0kuU3b7VdbwercA9aW0MwtWzpz5jhuYWvU=; b=X11X8PJNNh+XesNqKtrUyXPIZzSkKo4jwxIGrsrfyMZUIHowCF6n6MSqTIcfnUuiUGNJ8e DuomWYqFjJ0BbyXMVWIBiIXWXmKejSiAxGghHG9sc58HQROJ2qF/zqNgXzJbZBI9Y37s/q GsZt56q2wAetkyA6Gq/G6qpHFnfI5rU= 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-277-J0OgBZk7OrqsTVbKWd7sEw-1; Tue, 19 Nov 2024 10:45:27 -0500 X-MC-Unique: J0OgBZk7OrqsTVbKWd7sEw-1 X-Mimecast-MFC-AGG-ID: J0OgBZk7OrqsTVbKWd7sEw Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 3236D19560B5; Tue, 19 Nov 2024 15:45:26 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.80.120]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BE411956054; Tue, 19 Nov 2024 15:45:25 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org Subject: [PATCH RFC 4/4] xfs: fill dirty folios on zero range of unwritten mappings Date: Tue, 19 Nov 2024 10:46:56 -0500 Message-ID: <20241119154656.774395-5-bfoster@redhat.com> In-Reply-To: <20241119154656.774395-1-bfoster@redhat.com> References: <20241119154656.774395-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.0 on 10.30.177.40 Use the iomap folio batch mechanism to identify which folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely) and set the HAS_FOLIOS flag to inform iomap that pagecache has been checked for dirty folios. Signed-off-by: Brian Foster --- fs/xfs/xfs_iomap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index ed42a28973bb..d84b7abf540c 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1037,6 +1037,15 @@ xfs_buffered_write_iomap_begin( goto convert_delay; if (end_fsb > eof_fsb) end_fsb = eof_fsb; + } else if (imap.br_state == XFS_EXT_UNWRITTEN) { + u64 end; + + xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb); + end = iomap_fill_dirty_folios(VFS_I(ip), iomap, + XFS_FSB_TO_B(mp, imap.br_startoff), + XFS_FSB_TO_B(mp, imap.br_blockcount)); + end_fsb = min_t(xfs_fileoff_t, end_fsb, XFS_B_TO_FSB(mp, end)); + iomap_flags |= IOMAP_F_HAS_FOLIOS; } xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb); }