diff --git a/cs/src/core/Allocator/AllocatorBase.cs b/cs/src/core/Allocator/AllocatorBase.cs index 379ba65ec..ed6c2a915 100644 --- a/cs/src/core/Allocator/AllocatorBase.cs +++ b/cs/src/core/Allocator/AllocatorBase.cs @@ -147,12 +147,6 @@ public abstract partial class AllocatorBase : IDisposable /// public long SafeHeadAddress; - /// - /// Tentative head address. Threads do not take any record locks earlier than this point. - /// Records earlier than this address undergo eviction, before HeadAddress is moved. - /// - public long TentativeHeadAddress; - /// /// Flushed until address /// @@ -1267,29 +1261,6 @@ private void OnPagesMarkedReadOnly(long newSafeReadOnlyAddress) } } - /// - /// Action to be performed when all threads agree that - /// a page range is ready to close. - /// - private void OnPagesReadyToClose(long oldHeadAddress, long newHeadAddress) - { - if (ReadCache) - EvictCallback(oldHeadAddress, newHeadAddress); - - for (long closePageAddress = oldHeadAddress & ~PageSizeMask; closePageAddress < newHeadAddress; closePageAddress += PageSize) - { - long start = oldHeadAddress > closePageAddress ? oldHeadAddress : closePageAddress; - long end = newHeadAddress < (closePageAddress + PageSize) ? newHeadAddress : (closePageAddress + PageSize); - MemoryPageLockEvictionScan(start, end); - } - - if (Utility.MonotonicUpdate(ref HeadAddress, newHeadAddress, out oldHeadAddress)) - { - Debug.WriteLine("Allocate: Moving head offset from {0:X} to {1:X}", oldHeadAddress, newHeadAddress); - epoch.BumpCurrentEpoch(() => OnPagesClosed(newHeadAddress)); - } - } - /// /// Action to be performed for when all threads have /// agreed that a page range is closed. @@ -1303,10 +1274,15 @@ private void OnPagesClosed(long newSafeHeadAddress) if (IsNullDevice) Utility.MonotonicUpdate(ref BeginAddress, newSafeHeadAddress, out _); + if (ReadCache) + EvictCallback(oldSafeHeadAddress, newSafeHeadAddress); + for (long closePageAddress = oldSafeHeadAddress & ~PageSizeMask; closePageAddress < newSafeHeadAddress; closePageAddress += PageSize) { long start = oldSafeHeadAddress > closePageAddress ? oldSafeHeadAddress : closePageAddress; long end = newSafeHeadAddress < closePageAddress + PageSize ? newSafeHeadAddress : closePageAddress + PageSize; + + MemoryPageLockEvictionScan(start, end); MemoryPageScan(start, end); if (newSafeHeadAddress < closePageAddress + PageSize) @@ -1331,24 +1307,25 @@ private void OnPagesClosed(long newSafeHeadAddress) } } - internal void DebugPrintAddresses(long closePageAddress) + private void DebugPrintAddresses() { + var _begin = BeginAddress; + var _closedUntil = ClosedUntilAddress; + var _safehead = SafeHeadAddress; + var _head = HeadAddress; var _flush = FlushedUntilAddress; - var _readonly = ReadOnlyAddress; var _safereadonly = SafeReadOnlyAddress; + var _readonly = ReadOnlyAddress; var _tail = GetTailAddress(); - var _thead = TentativeHeadAddress; - var _head = HeadAddress; - var _safehead = SafeHeadAddress; - Console.WriteLine("ClosePageAddress: {0}.{1}", GetPage(closePageAddress), GetOffsetInPage(closePageAddress)); - Console.WriteLine("FlushedUntil: {0}.{1}", GetPage(_flush), GetOffsetInPage(_flush)); - Console.WriteLine("Tail: {0}.{1}", GetPage(_tail), GetOffsetInPage(_tail)); - Console.WriteLine("TentativeHead: {0}.{1}", GetPage(_thead), GetOffsetInPage(_thead)); - Console.WriteLine("Head: {0}.{1}", GetPage(_head), GetOffsetInPage(_head)); + Console.WriteLine("BeginAddress: {0}.{1}", GetPage(_begin), GetOffsetInPage(_begin)); + Console.WriteLine("ClosedUntilAddress: {0}.{1}", GetPage(_closedUntil), GetOffsetInPage(_closedUntil)); Console.WriteLine("SafeHead: {0}.{1}", GetPage(_safehead), GetOffsetInPage(_safehead)); - Console.WriteLine("ReadOnly: {0}.{1}", GetPage(_readonly), GetOffsetInPage(_readonly)); + Console.WriteLine("Head: {0}.{1}", GetPage(_head), GetOffsetInPage(_head)); + Console.WriteLine("FlushedUntil: {0}.{1}", GetPage(_flush), GetOffsetInPage(_flush)); Console.WriteLine("SafeReadOnly: {0}.{1}", GetPage(_safereadonly), GetOffsetInPage(_safereadonly)); + Console.WriteLine("ReadOnly: {0}.{1}", GetPage(_readonly), GetOffsetInPage(_readonly)); + Console.WriteLine("Tail: {0}.{1}", GetPage(_tail), GetOffsetInPage(_tail)); } /// @@ -1392,9 +1369,10 @@ public long ShiftHeadAddress(long desiredHeadAddress) newHeadAddress = currentFlushedUntilAddress; } - if (Utility.MonotonicUpdate(ref TentativeHeadAddress, newHeadAddress, out long oldTentativeHeadAddress)) + if (Utility.MonotonicUpdate(ref HeadAddress, newHeadAddress, out long oldHeadAddress)) { - epoch.BumpCurrentEpoch(() => OnPagesReadyToClose(oldTentativeHeadAddress, newHeadAddress)); + Debug.WriteLine("Allocate: Moving head offset from {0:X} to {1:X}", oldHeadAddress, newHeadAddress); + epoch.BumpCurrentEpoch(() => OnPagesClosed(newHeadAddress)); } return newHeadAddress; diff --git a/cs/src/core/Allocator/BlittableAllocator.cs b/cs/src/core/Allocator/BlittableAllocator.cs index 931110249..d65a7d6f1 100644 --- a/cs/src/core/Allocator/BlittableAllocator.cs +++ b/cs/src/core/Allocator/BlittableAllocator.cs @@ -344,7 +344,7 @@ public override IFasterScanIterator Scan(long beginAddress, long end /// internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver); - internal void MemoryPageScan(long beginAddress, long endAddress, IObserver> observer) + private void MemoryPageScan(long beginAddress, long endAddress, IObserver> observer) { using var iter = new BlittableScanIterator(this, beginAddress, endAddress, ScanBufferingMode.NoBuffering, epoch, true); observer?.OnNext(iter); diff --git a/cs/src/core/Allocator/GenericAllocator.cs b/cs/src/core/Allocator/GenericAllocator.cs index 1f4e8b7ef..c12218f09 100644 --- a/cs/src/core/Allocator/GenericAllocator.cs +++ b/cs/src/core/Allocator/GenericAllocator.cs @@ -1035,7 +1035,6 @@ public override IFasterScanIterator Scan(long beginAddress, long end /// internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver); - /// private void MemoryPageScan(long beginAddress, long endAddress, IObserver> observer) { var page = (beginAddress >> LogPageSizeBits) % BufferSize; diff --git a/cs/src/core/Allocator/VarLenBlittableAllocator.cs b/cs/src/core/Allocator/VarLenBlittableAllocator.cs index 2ef731bb2..105cd0d31 100644 --- a/cs/src/core/Allocator/VarLenBlittableAllocator.cs +++ b/cs/src/core/Allocator/VarLenBlittableAllocator.cs @@ -468,7 +468,7 @@ public override IFasterScanIterator Scan(long beginAddress, long end /// internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver); - internal void MemoryPageScan(long beginAddress, long endAddress, IObserver> observer) + private void MemoryPageScan(long beginAddress, long endAddress, IObserver> observer) { using var iter = new VariableLengthBlittableScanIterator(this, beginAddress, endAddress, ScanBufferingMode.NoBuffering, epoch, true); observer?.OnNext(iter);