diff --git a/cs/samples/MemOnlyCache/CacheSizeTracker.cs b/cs/samples/MemOnlyCache/CacheSizeTracker.cs index e3ffedbe8..93ee92cb7 100644 --- a/cs/samples/MemOnlyCache/CacheSizeTracker.cs +++ b/cs/samples/MemOnlyCache/CacheSizeTracker.cs @@ -85,10 +85,13 @@ public void OnNext(IFasterScanIterator iter) AddTrackedSize(-size); // Adjust empty page count to drive towards desired memory utilization - if (TotalSizeBytes > TargetSizeBytes && store.Log.AllocatableMemorySizeBytes >= store.Log.MemorySizeBytes) - store.Log.EmptyPageCount++; - else if (TotalSizeBytes < TargetSizeBytes && store.Log.AllocatableMemorySizeBytes <= store.Log.MemorySizeBytes) - store.Log.EmptyPageCount--; + if (store.Log.PageAllocationStabilized()) + { + if (TotalSizeBytes > TargetSizeBytes) + store.Log.EmptyPageCount++; + else + store.Log.EmptyPageCount--; + } } /// diff --git a/cs/src/core/Index/FASTER/LogAccessor.cs b/cs/src/core/Index/FASTER/LogAccessor.cs index c35f2e52a..db20e1a11 100644 --- a/cs/src/core/Index/FASTER/LogAccessor.cs +++ b/cs/src/core/Index/FASTER/LogAccessor.cs @@ -92,14 +92,14 @@ public void SetEmptyPageCount(int pageCount, bool wait = false) public int BufferSize => allocator.BufferSize; /// - /// Actual memory used by log (not including heap objects) + /// Actual memory used by log (not including heap objects) and overflow pages /// public long MemorySizeBytes => ((long)(allocator.AllocatedPageCount + allocator.OverflowPageCount)) << allocator.LogPageSizeBits; /// - /// Memory allocatable on the log (not including heap objects) + /// Whether we have allocated exactly the requested number of pages on the log (based on BufferSize and EmptyPageCount) /// - public long AllocatableMemorySizeBytes => ((long)(allocator.BufferSize - allocator.EmptyPageCount + allocator.OverflowPageCount)) << allocator.LogPageSizeBits; + public bool PageAllocationStabilized() => allocator.AllocatedPageCount == allocator.BufferSize - allocator.EmptyPageCount + 1; /// /// Shift begin address to the provided untilAddress. Make sure address corresponds to record boundary if snapToPageStart is set to