Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 3B3B13CF207 for ; Tue, 14 Jul 2026 18:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784052545; cv=none; b=ZPqRmqgl67hfMoqdXdCvtGIeR301GKpET4BV3fplv97itOBN1MghxvgqT8kGIkgPsTsfNevo9RkRz7wjiPVBEKD8Amdff5fjeLvdVzKm8OVVQmu3FQ6C7LsO4wz55dmQQtdyS6EmS3xhRwO0s0UQIOh+eHiejR4XUdArfSirBpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784052545; c=relaxed/simple; bh=Lw40jyktagBKmKyTPhylc68MXLNyf8w2Dxqx+1bwK8g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h0amVHVtFVLSw/GVVgyhCeQNUC5ubnhy9ghQ0fwsf3mo4Q+59vbdpjA2Il+W+ScsspxT7jtqrpNQFZmbVoniq8JDBm03mInfHHvYMYT6IIn7fffGpPcVmtUy9D0QE3S5vkqgdZPYyvXBE9lm12zHKtU8+E6D/velJ186mnA8Ddw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=FLCTSY0e; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="FLCTSY0e" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=JGWLaE5LHgNyGyBZ/Hr6+ukHTVnQ5dW0HCqJh0ZEjKQ=; b=FLCTSY0e+ZE58xViFxOqb9u3mI 5l4QxS1C1D2ZpcdQF7G+Cf8y/QirOAcVIvBkj/BpEBg5rZyinNMyedMwqfOZ7Z5J3nFh4tpfZM75U JTaCEHeEwoNVJiOH+/KMqBAefe3QmB7qmP1L2t+Y5EfyYLt1plB31InXfB40krvyUuIc7REgTCevY WIv3wBYMC1cU0vB5jeXP9cErdhsTnNWQnRi8j/oNMwKHL/SjqByajb2RruJHUIM1KBUqLoD27ezQV Su1zQh2rk89NkPZIpBSKiTWoTbOsPUM3QDtdTI0lNZI1ozF9xgZ2n5qevDkXYoRD17G8LMYN7yYMQ +o5OdReg==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wjhYh-0000000Fegh-2Dz3; Tue, 14 Jul 2026 18:08:43 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , Jane Chu , linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Muchun Song , Oscar Salvador , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Jan Kara , linux-fsdevel@vger.kernel.org, Christian Brauner Subject: [PATCH v3 8/9] filemap: Add support for authoritative mappings Date: Tue, 14 Jul 2026 19:08:38 +0100 Message-ID: <20260714180840.3731244-9-willy@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260714180840.3731244-1-willy@infradead.org> References: <20260714180840.3731244-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit An authoritative mapping knows about all the folios in the mapping. If read() finds a missing folio, there's no reason to allocate one and try to read it because we know it's a zero region of the file. We can just call iov_iter_zero() instead. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 11 +++++++++++ mm/filemap.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 346b77fa95ef..bd6a6275a4e9 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -210,6 +210,7 @@ enum mapping_flags { AS_WRITEBACK_MAY_DEADLOCK_ON_RECLAIM = 9, AS_KERNEL_FILE = 10, /* mapping for a fake kernel file that shouldn't account usage to user cgroups */ + AS_AUTHORITATIVE = 11, /* If we miss in the page cache, it's a hole */ /* Bits 16-25 are used for FOLIO_ORDER */ AS_FOLIO_ORDER_BITS = 5, AS_FOLIO_ORDER_MIN = 16, @@ -345,6 +346,16 @@ static inline bool mapping_writeback_may_deadlock_on_reclaim(const struct addres return test_bit(AS_WRITEBACK_MAY_DEADLOCK_ON_RECLAIM, &mapping->flags); } +static inline void mapping_set_authoritative(struct address_space *mapping) +{ + set_bit(AS_AUTHORITATIVE, &mapping->flags); +} + +static inline bool mapping_is_authoritative(const struct address_space *mapping) +{ + return test_bit(AS_AUTHORITATIVE, &mapping->flags); +} + static inline gfp_t mapping_gfp_mask(const struct address_space *mapping) { return mapping->gfp_mask; diff --git a/mm/filemap.c b/mm/filemap.c index 0f3ada4d8cff..f662cda81dc7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2697,6 +2697,8 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { DEFINE_READAHEAD(ractl, filp, &filp->f_ra, mapping, index); + if (mapping_is_authoritative(mapping)) + return 0; if (iocb->ki_flags & IOCB_NOIO) return -EAGAIN; if (iocb->ki_flags & IOCB_NOWAIT) @@ -2853,6 +2855,22 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, goto put_folios; end_offset = min_t(loff_t, isize, iocb->ki_pos + iter->count); + if (!folio_batch_count(&fbatch)) { + size_t fsize = mapping_min_folio_nrbytes(mapping); + size_t offset = iocb->ki_pos & (fsize - 1); + size_t bytes = min_t(loff_t, end_offset - iocb->ki_pos, + fsize - offset); + size_t copied = iov_iter_zero(bytes, iter); + + already_read += copied; + iocb->ki_pos += copied; + last_pos = iocb->ki_pos; + + if (copied < bytes) + error = -EFAULT; + continue; + } + /* * Once we start copying data, we don't want to be touching any * cachelines that might be contended: -- 2.47.3