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 EAC0D37C934 for ; Mon, 5 Oct 2026 07:13:28 +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=1791184410; cv=none; b=jQ+/acLwYf/tcNsiSf1fNwuGOzuIOD319gwMJYyfQ0I9dCKM87S8whE82FKW+YzWlKg4pLCyNxEhbsn1IXu1ufPSR8tESxHLoRj1JbsHN8rx7yDilgmJmoMa9Ufe1WlAnIveoTfI6lHNvuW0wc0dWU/I7vE7NcQMmZl4UVGLmxs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791184410; c=relaxed/simple; bh=HZA5CFOFD887ZTFSGIWLrvWV55ELOg3W3Gbq+RYIH5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=urjslkJdLn3YUpUkB0NLI2QZvw0+BfvvD5GJv2z1KdCWoNgfOfe+ahPw273OpAkv18xbVnYxNBPHcP3Zmt2/ZUH7H1PJYombi8Yef8xa24x2kqdu+1czYkr8DHHDF5YPwEjD8cSZQAX62O26jqT+r3KoS0T6UUylAQNLdtu+VpE= 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=AHjMfgHV; 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="AHjMfgHV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791184408; 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=FVmWyzHrsJfkLiiTwuWnaVPVIFsXKntmftTzOmV6DXQ=; b=AHjMfgHVLZit4u8FvZtLR/jfjUE7KR+a6Y3rlHhFymos5T1340S8mmysZGp8p+MYJ+4KIL h84/iitTH9cXT1eahSxI2nJNER2d+wcILLM/SPabkDecbuE9R4jNMqep1WAWtOjZ44u8t6 8dMIXYlZYZ0pwS50s8kO7HnJw2BFhZQ= 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-637-VCidjrCbMV6HA-brrefZKA-1; Mon, 05 Oct 2026 03:13:23 -0400 X-MC-Unique: VCidjrCbMV6HA-brrefZKA-1 X-Mimecast-MFC-AGG-ID: VCidjrCbMV6HA-brrefZKA_1791184401 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 606A91800D8D; Mon, 5 Oct 2026 07:13:21 +0000 (UTC) Received: from warthog.com (unknown [10.44.32.90]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 929C030000E3; Mon, 5 Oct 2026 07:13:16 +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 Subject: [PATCH v12 5/8] netfs: Provide a func to load the readahead buffers into a bvecq chain Date: Mon, 5 Oct 2026 08:12:22 +0100 Message-ID: <20261005071227.147182-6-dhowells@redhat.com> In-Reply-To: <20261005071227.147182-1-dhowells@redhat.com> References: <20261005071227.147182-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.4 In netfslib, provide a function to load the readahead buffers into a bvecq chain by preallocating the bvecq chain and then iterating directly over the pagecache to extract all the folios. This builds on the preceding patch to note the folio count in the readahead_control struct. Signed-off-by: David Howells Reviewed-by: Paulo Alcantara cc: Matthew Wilcox cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/bvecq.c | 60 +++++++++++++++++++++++++++++++++++++++++++ include/linux/bvecq.h | 1 + 2 files changed, 61 insertions(+) diff --git a/fs/netfs/bvecq.c b/fs/netfs/bvecq.c index 1493e028bb17..2edc0045c245 100644 --- a/fs/netfs/bvecq.c +++ b/fs/netfs/bvecq.c @@ -592,3 +592,63 @@ size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size, pos->offset = offset; return size; } + +/** + * bvecq_load_from_ra - Allocate a bvecq chain and load from readahead + * @pos: Blank position object to attach the new chain to. + * @ractl: The readahead control context. + * + * Decant the set of folios to be read from the readahead context into a bvecq + * chain. Each folio occupies one bio_vec element. + * + * Return: Amount of data loaded or -ENOMEM on allocation failure. + */ +ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl) +{ + XA_STATE(xas, &ractl->mapping->i_pages, ractl->_index); + struct folio *folio; + struct bvecq *bq; + unsigned int slot = 0; + size_t loaded = 0; + + bq = bvecq_alloc_chain(ractl->_nr_folios, GFP_KERNEL, false); + if (!bq) + return -ENOMEM; + + pos->bvecq = bq; + pos->slot = 0; + pos->offset = 0; + + rcu_read_lock(); + + xas_for_each(&xas, folio, ractl->_index + ractl->_nr_pages - 1) { + size_t len; + + if (xas_retry(&xas, folio)) + continue; + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + + len = folio_size(folio); + bvec_set_folio(&bq->bv[slot], folio, len, 0); + loaded += len; + slot++; + trace_netfs_folio(folio, netfs_folio_trace_read); + + if (slot >= bq->max_slots) { + bvecq_filled_to(bq, slot); + bq = bq->next; + if (!bq) + break; + slot = 0; + } + } + + rcu_read_unlock(); + + if (bq) + bvecq_filled_to(bq, slot); + + ractl->_index += ractl->_nr_pages; + ractl->_nr_pages = 0; + return loaded; +} diff --git a/include/linux/bvecq.h b/include/linux/bvecq.h index f1513f507cfb..389f6407cb84 100644 --- a/include/linux/bvecq.h +++ b/include/linux/bvecq.h @@ -77,6 +77,7 @@ void bvecq_pos_advance(struct bvecq_pos *pos, size_t amount); ssize_t bvecq_zero(struct bvecq_pos *pos, size_t amount); size_t bvecq_slice(struct bvecq_pos *pos, size_t max_size, unsigned int max_slots, unsigned int *_nr_slots); +ssize_t bvecq_load_from_ra(struct bvecq_pos *pos, struct readahead_control *ractl); /** * bvecq_alloc_buffer - Allocate a bvecq chain and populate with buffers