@@ -247,7 +247,6 @@ class MapAllocatorCache {
247
247
// The cache is initially empty
248
248
LRUHead = CachedBlock::InvalidEntry;
249
249
LRUTail = CachedBlock::InvalidEntry;
250
- LastUnreleasedEntry = CachedBlock::InvalidEntry;
251
250
252
251
// Available entries will be retrieved starting from the beginning of the
253
252
// Entries array
@@ -322,10 +321,9 @@ class MapAllocatorCache {
322
321
}
323
322
CachedBlock PrevEntry = Quarantine[QuarantinePos];
324
323
Quarantine[QuarantinePos] = Entry;
324
+ if (OldestTime == 0 )
325
+ OldestTime = Entry.Time ;
325
326
Entry = PrevEntry;
326
- // Update the entry time to reflect the time that the
327
- // quarantined memory is placed in the Entries array
328
- Entry.Time = Time;
329
327
}
330
328
331
329
// All excess entries are evicted from the cache
@@ -336,6 +334,9 @@ class MapAllocatorCache {
336
334
}
337
335
338
336
insert (Entry);
337
+
338
+ if (OldestTime == 0 )
339
+ OldestTime = Entry.Time ;
339
340
} while (0 );
340
341
341
342
for (MemMapT &EvictMemMap : EvictionMemMaps)
@@ -534,9 +535,6 @@ class MapAllocatorCache {
534
535
Entries[LRUHead].Prev = static_cast <u16>(FreeIndex);
535
536
}
536
537
537
- if (LastUnreleasedEntry == CachedBlock::InvalidEntry)
538
- LastUnreleasedEntry = static_cast <u16>(FreeIndex);
539
-
540
538
Entries[FreeIndex] = Entry;
541
539
Entries[FreeIndex].Next = LRUHead;
542
540
Entries[FreeIndex].Prev = CachedBlock::InvalidEntry;
@@ -554,9 +552,6 @@ class MapAllocatorCache {
554
552
555
553
Entries[I].invalidate ();
556
554
557
- if (I == LastUnreleasedEntry)
558
- LastUnreleasedEntry = Entries[LastUnreleasedEntry].Prev ;
559
-
560
555
if (I == LRUHead)
561
556
LRUHead = Entries[I].Next ;
562
557
else
@@ -598,37 +593,35 @@ class MapAllocatorCache {
598
593
}
599
594
}
600
595
601
- inline void release (CachedBlock &Entry) {
602
- DCHECK (Entry.Time != 0 );
596
+ void releaseIfOlderThan (CachedBlock &Entry, u64 Time) REQUIRES(Mutex) {
597
+ if (!Entry.isValid () || !Entry.Time )
598
+ return ;
599
+ if (Entry.Time > Time) {
600
+ if (OldestTime == 0 || Entry.Time < OldestTime)
601
+ OldestTime = Entry.Time ;
602
+ return ;
603
+ }
603
604
Entry.MemMap .releaseAndZeroPagesToOS (Entry.CommitBase , Entry.CommitSize );
604
605
Entry.Time = 0 ;
605
606
}
606
607
607
608
void releaseOlderThan (u64 Time) EXCLUDES(Mutex) {
608
609
ScopedLock L (Mutex);
609
- if (!EntriesCount)
610
+ if (!EntriesCount || OldestTime == 0 || OldestTime > Time )
610
611
return ;
611
-
612
- for (uptr I = 0 ; I < Config::getQuarantineSize (); I++) {
613
- CachedBlock &ReleaseEntry = Quarantine[I];
614
- if (!ReleaseEntry.isValid () || !ReleaseEntry.Time ||
615
- ReleaseEntry.Time > Time)
616
- continue ;
617
- release (ReleaseEntry);
618
- }
619
-
620
- // Release oldest entries first by releasing from decommit base
621
- while (LastUnreleasedEntry != CachedBlock::InvalidEntry &&
622
- Entries[LastUnreleasedEntry].Time <= Time) {
623
- release (Entries[LastUnreleasedEntry]);
624
- LastUnreleasedEntry = Entries[LastUnreleasedEntry].Prev ;
625
- }
612
+ OldestTime = 0 ;
613
+ for (uptr I = 0 ; I < Config::getQuarantineSize (); I++)
614
+ releaseIfOlderThan (Quarantine[I], Time);
615
+ for (uptr I = 0 ; I < Config::getEntriesArraySize (); I++)
616
+ releaseIfOlderThan (Entries[I], Time);
626
617
}
618
+
627
619
HybridMutex Mutex;
628
620
u32 EntriesCount GUARDED_BY (Mutex) = 0;
629
621
u32 QuarantinePos GUARDED_BY (Mutex) = 0;
630
622
atomic_u32 MaxEntriesCount = {};
631
623
atomic_uptr MaxEntrySize = {};
624
+ u64 OldestTime GUARDED_BY (Mutex) = 0;
632
625
atomic_s32 ReleaseToOsIntervalMs = {};
633
626
u32 CallsToRetrieve GUARDED_BY (Mutex) = 0;
634
627
u32 SuccessfulRetrieves GUARDED_BY (Mutex) = 0;
@@ -643,9 +636,6 @@ class MapAllocatorCache {
643
636
u16 LRUTail GUARDED_BY (Mutex) = 0;
644
637
// The AvailableHead is the top of the stack of available entries
645
638
u16 AvailableHead GUARDED_BY (Mutex) = 0;
646
- // The LastUnreleasedEntry is the least recently used entry that has not
647
- // been released
648
- u16 LastUnreleasedEntry GUARDED_BY (Mutex) = 0;
649
639
};
650
640
651
641
template <typename Config> class MapAllocator {
0 commit comments