From mboxrd@z Thu Jan 1 00:00:00 1970 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 16E7C254AE4 for ; Mon, 14 Jul 2025 13:17: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=1752499053; cv=none; b=V/qbp+PD8DWTyDkV1i14+ZOX39wfAscAXTSJavQOu4W3H3kYpXlBj5UggSOzr+Np4bjHEWAowrrMAOWP7UsN2CDtyimE879Qd1b5ENDBy37V/k4Pwq+iYLMYQO81f5bbGx36aIsnQzC4GcGrmREFtbHGxj290QO+GHYTXlB2ajU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752499053; c=relaxed/simple; bh=yfHE5W4EiaGUdAjNI8RuEQwvF7vl3z7Da9nYX7b2HjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lIEH2qZZ0oI/74w6+9krOB2aURdBq5xq3qAeym04LSkOJfdxqqwCeDIsE+OjOTlNV1c7sr0aA/85Spzv9vqU01l7jxX3QchyqWmKqx9+oShVy2n5kqgpP9xfj6fVA1WLbIiRdI2GD8/LHLwrbxF9ZFTtpps9tzfcfbl6/uYTXh8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=CVvtZLaf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="CVvtZLaf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752499051; 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=J267WbbKYx/KqIj532GDLL47IG+HwfOERvZ7pNKCCbI=; b=CVvtZLafV/2aPqHFiTidHI/YTf8i0hIZNqPqIFWxj81E0RHQ+CYoUNIabJj9zwUHeI3/oK hdshZwIqq7b93ovPbSLwETR6l8EW/w27vH0rMPekIAu2nCNx1KElsoug5pvyeV7DcQDqtX 8AJzHl+99ihLmdQZDm7As96R/ny3i1g= 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-646-95_ARaa8PyCfYQmyS_E0og-1; Mon, 14 Jul 2025 09:17:26 -0400 X-MC-Unique: 95_ARaa8PyCfYQmyS_E0og-1 X-Mimecast-MFC-AGG-ID: 95_ARaa8PyCfYQmyS_E0og_1752499045 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 522E919560B9; Mon, 14 Jul 2025 13:17:25 +0000 (UTC) Received: from bfoster.redhat.com (unknown [10.22.64.43]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1AA3C18002B2; Mon, 14 Jul 2025 13:17:23 +0000 (UTC) From: Brian Foster To: linux-fsdevel@vger.kernel.org Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org, hch@infradead.org, djwong@kernel.org, willy@infradead.org Subject: [PATCH v2 5/7] xfs: fill dirty folios on zero range of unwritten mappings Date: Mon, 14 Jul 2025 09:20:57 -0400 Message-ID: <20250714132059.288129-6-bfoster@redhat.com> In-Reply-To: <20250714132059.288129-1-bfoster@redhat.com> References: <20250714132059.288129-1-bfoster@redhat.com> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Use the iomap folio batch mechanism to select folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely for current use cases) to distinguish between a range to skip and one that requires another iteration due to a full batch. Signed-off-by: Brian Foster --- fs/xfs/xfs_iomap.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index b5cf5bc6308d..63054f7ead0e 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1691,6 +1691,8 @@ xfs_buffered_write_iomap_begin( struct iomap *iomap, struct iomap *srcmap) { + struct iomap_iter *iter = container_of(iomap, struct iomap_iter, + iomap); struct xfs_inode *ip = XFS_I(inode); struct xfs_mount *mp = ip->i_mount; xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset); @@ -1762,6 +1764,7 @@ xfs_buffered_write_iomap_begin( */ if (flags & IOMAP_ZERO) { xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); + u64 end; if (isnullstartblock(imap.br_startblock) && offset_fsb >= eof_fsb) @@ -1769,6 +1772,26 @@ xfs_buffered_write_iomap_begin( if (offset_fsb < eof_fsb && end_fsb > eof_fsb) end_fsb = eof_fsb; + /* + * Look up dirty folios for unwritten mappings within EOF. + * Providing this bypasses the flush iomap uses to trigger + * extent conversion when unwritten mappings have dirty + * pagecache in need of zeroing. + * + * Trim the mapping to the end pos of the lookup, which in turn + * was trimmed to the end of the batch if it became full before + * the end of the mapping. + */ + if (imap.br_state == XFS_EXT_UNWRITTEN && + offset_fsb < eof_fsb) { + loff_t len = min(count, + XFS_FSB_TO_B(mp, imap.br_blockcount)); + + end = iomap_fill_dirty_folios(iter, offset, len); + end_fsb = min_t(xfs_fileoff_t, end_fsb, + XFS_B_TO_FSB(mp, end)); + } + xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb); } -- 2.50.0