leaves12138 commented on code in PR #128:
URL: 
https://github.com/apache/paimon-vector-index/pull/128#discussion_r4583643098


##########
core/src/diskann_io.rs:
##########
@@ -1693,6 +1766,58 @@ impl<R: SeekRead> DiskAnnIndexReader<R> {
         self.last_search_stats
     }
 
+    pub(crate) fn with_graph_cache_budget<T>(
+        &mut self,
+        borrow_raw: bool,
+        operation: impl FnOnce(Option<Arc<Vec<u8>>>) -> io::Result<T>,
+    ) -> io::Result<T> {
+        if !borrow_raw {
+            return operation(None);
+        }
+        let resident = self
+            .resident
+            .as_ref()
+            .ok_or_else(|| invalid_data("DiskANN resident state is missing"))?
+            .clone();
+        let cache_bytes = resident
+            .raw_vector_cache
+            .total_capacity()
+            .saturating_add(resident.adjacency_cache.total_capacity());
+        let length = cache_bytes.saturating_sub(64).min(16 * 1024 * 1024).min(
+            (self.header.sections.adjacency.length as usize)
+                .saturating_sub(self.hot_adjacency.len()),
+        ) / DISKANN_PAGE_SIZE as usize
+            * DISKANN_PAGE_SIZE as usize;
+        let mut loan = AdjacencyCacheLoan::new(
+            &resident.adjacency_cache,
+            &resident.raw_vector_cache,
+            if length > 0 { cache_bytes } else { 0 },
+        )?;
+        let extension = if length > 0 {
+            let mut payload = Vec::new();
+            payload
+                .try_reserve_exact(length)

Review Comment:
   [P2] Release query-local vector references before lending their cache 
allowance
   
   The loan only evicts the shared LRUs, but successful 
rerank/rerank_candidate_batch_streaming calls retain raw-vector payloads in 
query_scratch.vector_windows, and retained batch workers can hold the same kind 
of references. Neither this helper nor take_batch_workers clears those windows 
before this allocation. On a warmed Reader or a subsequent large-batch chunk, 
lowering the shared cache capacities to zero therefore does not actually free 
the bytes being lent to the prefix. I reproduced this against the unchanged 
production modules: with a 64 KiB raw-cache allowance and 1 KiB adjacency-cache 
allowance, a preceding search left 64 KiB of vector payloads alive (verified 
through Weak references) while this helper allocated a 16 KiB prefix, retaining 
80 KiB against a combined 65 KiB cache allowance. Dropping the parent query 
scratch first made those old allocations disappear. Please release the parent 
and worker raw-vector window references before borrowing their allowance, or 
account
  for still-live payloads when sizing the prefix, and cover a 
warmed/second-chunk batch in the budget regression test; checking restored 
capacity counters alone misses this low-memory regression.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to