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 7DA0D4AA402 for ; Tue, 6 Oct 2026 21:00:18 +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=1791320421; cv=none; b=E+WjfEFvxF8cZKYil8M9QdsWlbev/CE2sdaLWro1r5VnlKQcCMtklwUEK30tXaVFDiP4EPcJKdcGujxxxnzrKH5oFCMTwUjbjtti5zr8yYLZNuZ6pHXPBdX5g7fvYW9MzYcGLGZckTtsbb/SjHNMAcRCPN7vH57dN4Zazgde5F0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791320421; c=relaxed/simple; bh=51Hnywow9m+EfGeBXFdD8++qMPUJ5/apgW0WCxsmTGE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BNos73oyvXhGRls1o/EDX54zPJASCQV0JM1zVcOSJHKPOQqc08DDgknMnvnh7Nk9GhMlcebdS6nR8QlQiA1tWZXqOlHnjS2F3BLDU0pbBHJ8Ic9ypSNTOflIqOxfEG4LLdBX2gCghRqIhvHGoF9sMToUdzDiC6r4xuy3s+MqsEY= 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=gmn0Yvyk; 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="gmn0Yvyk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791320417; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qex3q47o/llFp5icyZaFvcldeQl44QEXS98v350pNx0=; b=gmn0YvykWgsAPYbWEZgdQFRxeI9P9CPd4V2pXoz53MWn8qo7PO/Z9ToklzK+Wa9gfr9GQx TUwwdMqUC7wIMEdI/LngjHIjO6SGFXMlgG6+QxLjyHJ9/QcJm6oKLzjMtraHaAl+Bhr6ze hzktSXQHfh52a709tcMVugQanuazB6Q= 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-63-pA8JMPwMPvuf_UZ79wbw9A-1; Tue, 6 Oct 2026 21:00:11 +0000 X-MC-Unique: pA8JMPwMPvuf_UZ79wbw9A-1 X-Mimecast-MFC-AGG-ID: pA8JMPwMPvuf_UZ79wbw9A_1791320408 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 609491977597; Tue, 6 Oct 2026 21:00:07 +0000 (UTC) Received: from warthog.com (unknown [10.44.32.90]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2A8561800581; Tue, 6 Oct 2026 21:00:00 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Paulo Alcantara , Matthew Wilcox , Namjae Jeon , 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-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v13 1/8] mm: Make readahead store folio count in readahead_control Date: Tue, 6 Oct 2026 21:59:37 +0100 Message-ID: <20261006205947.608356-2-dhowells@redhat.com> In-Reply-To: <20261006205947.608356-1-dhowells@redhat.com> References: <20261006205947.608356-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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 Reviewed-by: 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 0adfa6605653..b7154b81d0d7 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1411,6 +1411,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; @@ -1590,6 +1591,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 6e5563290287..196542fb1c93 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;