@@ -112,6 +112,7 @@ public class UnifiedMemoryManager
112112 // Prescient policy
113113 private static PrescientPolicy _prescientPolicy ;
114114 private static IOTrace _ioTrace ;
115+ private static long _currentTime = 0 ;
115116
116117 // Pinned size of physical memory. Starts from 0 for each operation. Max is 70% of heap
117118 // This increases only if the input is not present in the cache and read from FS/rdd/fed/gpu
@@ -207,6 +208,66 @@ public static void cleanup() {
207208 _pinnedVirtualMemSize = 0 ;
208209 }
209210
211+ /**
212+ * Sets the I/O trace for the prescient policy.
213+ * This should be called once by the ExecutionContext after trace generation.
214+ * @param trace The generated IOTrace
215+ */
216+ public static void setTrace (IOTrace trace ) {
217+ _ioTrace = trace ;
218+ if (_evictionPolicy instanceof PrescientPolicy ) {
219+ _prescientPolicy = (PrescientPolicy ) _evictionPolicy ;
220+ _prescientPolicy .setTrace (_ioTrace );
221+ }
222+ else {
223+ // Optional: Log a warning if the trace is set but the policy isn't Prescient
224+ // LOG.warn("IOTrace was provided, but eviction policy is not prescient!");
225+ }
226+ }
227+
228+ /**
229+ * Updates the UMM's logical time.
230+ * This should be called by the ExecutionContext *before* each instruction.
231+ * @param logicalTime The new logical time
232+ */
233+ public static void updateTime (long logicalTime ) {
234+ _currentTime = logicalTime ;
235+ prefetch ();
236+ }
237+
238+ /**
239+ * Prefetches blocks that will be needed soon, based on the I/O trace.
240+ */
241+ private static void prefetch () {
242+ if (_ioTrace == null || _prescientPolicy == null ) {
243+ return ; // No trace or policy, cannot prefetch
244+ }
245+
246+ // Get the list of blocks to prefetch from our policy
247+ List <String > blocksToPrefetch = _prescientPolicy .getBlocksToPrefetch (_currentTime );
248+
249+ // A real implementation MUST use an asynchronous thread pool
250+ // (e.g., from _fClean) to load these blocks without blocking the main thread.
251+
252+ for (String blockID : blocksToPrefetch ) {
253+ synchronized (_mQueue ) {
254+ // Check again inside lock if block was already loaded or pinned
255+ if (_mQueue .containsKey (blockID ) || _pinnedEntries .contains (blockID )) {
256+ continue ; // Already in memory
257+ }
258+ }
259+
260+ // --- This is a simplified version for now ---
261+ // TODO: Submit an async prefetch task to _fClean's thread pool
262+ // The task should: 1. Get block size (from metadata)
263+ // 2. Call makeSpace(blockSize)
264+ // 3. Load block from disk
265+ // 4. Add block to _mQueue (synchronized)
266+
267+ System .out .println ("UMM PREFETCH [T=" +_currentTime +"]: Planning to prefetch " + blockID );
268+ }
269+ }
270+
210271 /**
211272 * Print current status of UMM, including all entries.
212273 * NOTE: use only for debugging or testing.
@@ -312,10 +373,35 @@ public static int makeSpace(long reqSpace) {
312373 synchronized (_mQueue ) {
313374 // Evict blobs to make room (by default FIFO)
314375 while (getUMMFree () < reqSpace && !_mQueue .isEmpty ()) {
315- //remove first unpinned entry from eviction queue
316- var entry = _mQueue .removeFirstUnpinned (_pinnedEntries );
317- String ftmp = entry .getKey ();
318- ByteBuffer bb = entry .getValue ();
376+ // --- NEW PRESCIENT LOGIC ---
377+ String ftmp ; // Block ID / filename to evict
378+
379+ if (_prescientPolicy != null && _ioTrace != null ) {
380+ // Use prescient policy to find the best block to evict
381+ ftmp = _prescientPolicy .evict (_mQueue .keySet (), _pinnedEntries , _currentTime );
382+ } else {
383+ // Fallback to default LRU if prescient policy isn't set or has no trace
384+ var entry = _mQueue .removeFirstUnpinned (_pinnedEntries );
385+ ftmp = (entry != null ) ? entry .getKey () : null ;
386+ }
387+
388+ if (ftmp == null ) {
389+ // Policy couldn't find a block to evict (e.g., all are pinned)
390+ if (!_pinnedEntries .containsAll (_mQueue .keySet ())) {
391+ // This case should ideally not be reached if unpinned blocks exist
392+ throw new DMLRuntimeException ("UMM: Eviction policy failed to find a candidate." );
393+ }
394+ // If we are here, all blocks are pinned, and we cannot make space.
395+ // The original exception will be thrown later.
396+ break ; // Exit the while loop
397+ }
398+
399+ // Remove the chosen block from the queue
400+ ByteBuffer bb = _mQueue .remove (ftmp );
401+ // //remove first unpinned entry from eviction queue
402+ // var entry = _mQueue.removeFirstUnpinned(_pinnedEntries);
403+ // String ftmp = entry.getKey();
404+ // ByteBuffer bb = entry.getValue();
319405
320406 if (bb != null ) {
321407 // Wait for pending serialization
0 commit comments