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.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 D8E85403EB3 for ; Mon, 8 Jun 2026 14:55:31 +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=1780930533; cv=none; b=jDSYcCjKitITKVtDPbaHhgXkDOMB9mxtT7wKq4JG9mFbufwU7cYcHdXlSiNfBaYy8RMiDLPvj/1VB6TMyVNnz475IxMBqZkHYvGmyALgF5NY7EbRRTSZwlWNc9v4HE8tj9fh2T5h4RFfZGgOw8WNRYKBjChYwj55AaZiYOKVShQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780930533; c=relaxed/simple; bh=WXerj7RGtu33oTH5VH8v/x9NiUIiMf4VG85D69rQykA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=hy8Agflhg4TL+d1zIfg2tMxmWV8EfrC4OPmrjMPjsh9VCm0+sX841DyuML448Rh/5t/g5QE5dDqylV0dwxHLTx/gtyWllhswRkc6Dc7rOLajrMCkWboYvyEz+I3rRLCx/f0HJpBnjeMUyeCHGUqepUQy+BhdeP/eoodKAJY5HQ8= 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=O3rMN7WB; arc=none smtp.client-ip=170.10.129.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="O3rMN7WB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780930531; 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=HD9l3rshhdvjF/dR6TAQujaSrodzR3TFHgxLsri2Hp0=; b=O3rMN7WBZeyoYs2SeHoBAUVaQp/NRRaxqC8Sfir9EKTnpDeC5wa5FJw40AtWh3pIYg8Jqb Y2gYBUad3xnPAcDx21IH36vZ+Nwb7SNVY6t/0mHS+X1Dsp+uUdugbLqESOs8dGMKcrf3gY fpRqNUTUZl7uBHc4bZtXwkwruN36iyg= 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-561-X3VTno1NOkaZZyDJ3DO6Qg-1; Mon, 08 Jun 2026 10:55:27 -0400 X-MC-Unique: X3VTno1NOkaZZyDJ3DO6Qg-1 X-Mimecast-MFC-AGG-ID: X3VTno1NOkaZZyDJ3DO6Qg_1780930524 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 DA83C1800BEE; Mon, 8 Jun 2026 14:55:23 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.44.32.43]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 01D9D3008B39; Mon, 8 Jun 2026 14:55:16 +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 , Eric Van Hensbergen , Dominique Martinet , Ilya Dryomov , Trond Myklebust , 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 v3 04/22] mm: Make readahead store folio count in readahead_control Date: Mon, 8 Jun 2026 15:54:12 +0100 Message-ID: <20260608145432.681865-5-dhowells@redhat.com> In-Reply-To: <20260608145432.681865-1-dhowells@redhat.com> References: <20260608145432.681865-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: netfs@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-MFC-PROC-ID: xTKXR0U9eQghKvbQWSL0CMmgRSXOxtCsUx4_zr0LT6A_1780930524 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 31a848485ad9..1de60ecfd6e3 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1350,6 +1350,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; @@ -1529,6 +1530,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 7b05082c89ea..eba194f4635f 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -177,6 +177,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)); } @@ -292,6 +293,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; } @@ -459,6 +461,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; @@ -802,6 +805,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; } @@ -831,6 +835,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;