From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0E97C44500 for ; Mon, 6 Jul 2026 15:34:40 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4gv7hH3Nmnz3bps; Tue, 07 Jul 2026 01:34:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1783352079; cv=none; b=HrKDdEvhvOQ6/lUTDFalLVDlSwFYpS1CBrx1lWrSbjMxUipAa4Gd9NW6sKDlqWzPafm+rxVaYOMPLzUJtmr6V60YIS8hvBKlxwawr8ofJE5YCn1sFqphGUn0MVAGmuDzOO7CQzwpQSu43A36HasT6R2TFZwgLd4uRDTmvATWh83bWl5zA7gq3IK9S+HIVIWgeD29IrrQvVcwJKytEfKDLY9XWYz4/nlGW9eyeac5cOkICa6zsjdBHeZDFfV83Zko098HurLgKi2oWxqKOSz5XBbyHMZ+Kn8gZL5pn4+OhHX2U+mT4Y2Y+FWvUiWvU8uUk50qyN2HGa/EiuBwdCwSsA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1783352079; c=relaxed/relaxed; bh=oAh3PBs47lZUHcwbeGXM5gS5ZzePV60tR0gQfqSs8Ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=TywEBkPBBSfE+dRIa9dzz43y4Xrq7CKbPMGgUkQ5uYaHbfbOX/+hqBXacObM8eJEGrkYcW9ygKlNhJaXnre9BQma9AVCFV9iuaP/3x0GvoSAGFbxNSo8M9sOEPD9FCLo+hSrlJ+yb7e4XksQhBcR/p1z5LnvcjkS7azBdF8KAJt6xQfzLeRlUu87fNhqarleij7aLEwo0vSKz3vw5LW6jw7jCBa7wrqY3sSrIOLNV0PfZw2C0wKC78553X8kWUkynS4lKXRO4NBTntHIpGbk37tNJYwq23lwsypRnUSW/Wb9F0coGO7s3OyndFmYMVikXCoY5CK2UsBSmqOjhYuo6w== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZIz5FcV+; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZIz5FcV+; dkim-atps=neutral; spf=pass (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=dhowells@redhat.com; receiver=lists.ozlabs.org) smtp.mailfrom=redhat.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZIz5FcV+; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZIz5FcV+; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=dhowells@redhat.com; receiver=lists.ozlabs.org) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4gv7hG3Scyz2yVZ for ; Tue, 07 Jul 2026 01:34:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783352075; 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=oAh3PBs47lZUHcwbeGXM5gS5ZzePV60tR0gQfqSs8Ac=; b=ZIz5FcV+kbTUoKL2tsm/rqRS54W21EmApWtwIury9xQPt41THFWC+qedKN5nJTDsq3hkv2 374rEvBqqwDyv0nlHRpoCKfSqNbvfusLFDH60Uo1WSK+nF7+rNl7HTwQNCmV0LO3kc8eUd nLUiGRYh/RP+CoKpm+1l1zaPO8xKZZ0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783352075; 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=oAh3PBs47lZUHcwbeGXM5gS5ZzePV60tR0gQfqSs8Ac=; b=ZIz5FcV+kbTUoKL2tsm/rqRS54W21EmApWtwIury9xQPt41THFWC+qedKN5nJTDsq3hkv2 374rEvBqqwDyv0nlHRpoCKfSqNbvfusLFDH60Uo1WSK+nF7+rNl7HTwQNCmV0LO3kc8eUd nLUiGRYh/RP+CoKpm+1l1zaPO8xKZZ0= Received: from mx-prod-mc-06.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-441-CzLBI2gxMbu0Oj7J76YUmg-1; Mon, 06 Jul 2026 11:34:30 -0400 X-MC-Unique: CzLBI2gxMbu0Oj7J76YUmg-1 X-Mimecast-MFC-AGG-ID: CzLBI2gxMbu0Oj7J76YUmg_1783352066 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08C511800A3A; Mon, 6 Jul 2026 15:34:26 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.44.33.159]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5CDE195604B; Mon, 6 Jul 2026 15:34:19 +0000 (UTC) From: David Howells To: Christian Brauner , Matthew Wilcox , Christoph Hellwig Cc: David Howells , Paulo Alcantara , Jens Axboe , Leon Romanovsky , Steve French , ChenXiaoSong , Marc Dionne , Stefan Metzmacher , Eric Van Hensbergen , Dominique Martinet , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 01/21] mm: Make readahead store folio count in readahead_control Date: Mon, 6 Jul 2026 16:33:47 +0100 Message-ID: <20260706153408.1231650-2-dhowells@redhat.com> In-Reply-To: <20260706153408.1231650-1-dhowells@redhat.com> References: <20260706153408.1231650-1-dhowells@redhat.com> X-Mailing-List: linux-erofs@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-MFC-PROC-ID: wAomgzP7il2LM7twV9HSRQFoZJ8HWy3yNgWf7Xzo5fg_1783352066 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Make readahead store folio count in readahead_control so that the filesystem can know in advance how many folios it needs to keep track of. This is cleared by read_pages() in case it is called from a loop. The count is accessed by the filesystem with readahead_folio_count(). Signed-off-by: David Howells cc: Paulo Alcantara (Red Hat) cc: Matthew Wilcox cc: netfs@lists.linux.dev cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- include/linux/pagemap.h | 10 ++++++++++ mm/readahead.c | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2c3718d592d6..e1e51bace388 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1348,6 +1348,7 @@ struct readahead_control { struct file_ra_state *ra; /* private: use the readahead_* accessors instead */ pgoff_t _index; + unsigned int _nr_folios; unsigned int _nr_pages; unsigned int _batch_count; bool dropbehind; @@ -1527,6 +1528,15 @@ static inline size_t readahead_batch_length(const struct readahead_control *rac) return rac->_batch_count * PAGE_SIZE; } +/** + * readahead_folio_count - Get the number of folios in this readahead request. + * @rac: The readahead request. + */ +static inline unsigned int readahead_folio_count(const struct readahead_control *rac) +{ + return rac->_nr_folios; +} + static inline unsigned long dir_pages(const struct inode *inode) { return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >> diff --git a/mm/readahead.c b/mm/readahead.c index 558c92957518..069ded56fd80 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -188,6 +188,7 @@ static void read_pages(struct readahead_control *rac) if (unlikely(rac->_workingset)) psi_memstall_leave(&rac->_pflags); rac->_workingset = false; + rac->_nr_folios = 0; BUG_ON(readahead_count(rac)); } @@ -303,6 +304,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, if (i == mark) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages; i += min_nrpages; } @@ -473,6 +475,7 @@ static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index, return err; } + ractl->_nr_folios++; ractl->_nr_pages += 1UL << order; ractl->_workingset |= folio_test_workingset(folio); return 0; @@ -822,6 +825,7 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages; ractl->_index = folio->index; } @@ -851,6 +855,7 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages; if (ra) { ra->size += min_nrpages;