Skip to content

Commit

Permalink
Improving cache tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Feb 27, 2022
1 parent 72bd490 commit 9ee8a26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions cs/samples/MemOnlyCache/CacheSizeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ public void OnNext(IFasterScanIterator<CacheKey, CacheValue> 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--;
}
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions cs/src/core/Index/FASTER/LogAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public void SetEmptyPageCount(int pageCount, bool wait = false)
public int BufferSize => allocator.BufferSize;

/// <summary>
/// Actual memory used by log (not including heap objects)
/// Actual memory used by log (not including heap objects) and overflow pages
/// </summary>
public long MemorySizeBytes => ((long)(allocator.AllocatedPageCount + allocator.OverflowPageCount)) << allocator.LogPageSizeBits;

/// <summary>
/// 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)
/// </summary>
public long AllocatableMemorySizeBytes => ((long)(allocator.BufferSize - allocator.EmptyPageCount + allocator.OverflowPageCount)) << allocator.LogPageSizeBits;
public bool PageAllocationStabilized() => allocator.AllocatedPageCount == allocator.BufferSize - allocator.EmptyPageCount + 1;

/// <summary>
/// Shift begin address to the provided untilAddress. Make sure address corresponds to record boundary if snapToPageStart is set to
Expand Down

0 comments on commit 9ee8a26

Please sign in to comment.