Skip to content

Commit

Permalink
Revert THA
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Feb 26, 2022
1 parent 88dd50a commit a3fe2c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 45 deletions.
62 changes: 20 additions & 42 deletions cs/src/core/Allocator/AllocatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ public abstract partial class AllocatorBase<Key, Value> : IDisposable
/// </summary>
public long SafeHeadAddress;

/// <summary>
/// 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.
/// </summary>
public long TentativeHeadAddress;

/// <summary>
/// Flushed until address
/// </summary>
Expand Down Expand Up @@ -1267,29 +1261,6 @@ private void OnPagesMarkedReadOnly(long newSafeReadOnlyAddress)
}
}

/// <summary>
/// Action to be performed when all threads agree that
/// a page range is ready to close.
/// </summary>
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));
}
}

/// <summary>
/// Action to be performed for when all threads have
/// agreed that a page range is closed.
Expand All @@ -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)
Expand All @@ -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));
}

/// <summary>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/BlittableAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public override IFasterScanIterator<Key, Value> Scan(long beginAddress, long end
/// <inheritdoc />
internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver);

internal void MemoryPageScan(long beginAddress, long endAddress, IObserver<IFasterScanIterator<Key, Value>> observer)
private void MemoryPageScan(long beginAddress, long endAddress, IObserver<IFasterScanIterator<Key, Value>> observer)
{
using var iter = new BlittableScanIterator<Key, Value>(this, beginAddress, endAddress, ScanBufferingMode.NoBuffering, epoch, true);
observer?.OnNext(iter);
Expand Down
1 change: 0 additions & 1 deletion cs/src/core/Allocator/GenericAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,6 @@ public override IFasterScanIterator<Key, Value> Scan(long beginAddress, long end
/// <inheritdoc />
internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver);

/// <inheritdoc />
private void MemoryPageScan(long beginAddress, long endAddress, IObserver<IFasterScanIterator<Key, Value>> observer)
{
var page = (beginAddress >> LogPageSizeBits) % BufferSize;
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/VarLenBlittableAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public override IFasterScanIterator<Key, Value> Scan(long beginAddress, long end
/// <inheritdoc />
internal override void MemoryPageScan(long beginAddress, long endAddress) => MemoryPageScan(beginAddress, endAddress, OnEvictionObserver);

internal void MemoryPageScan(long beginAddress, long endAddress, IObserver<IFasterScanIterator<Key, Value>> observer)
private void MemoryPageScan(long beginAddress, long endAddress, IObserver<IFasterScanIterator<Key, Value>> observer)
{
using var iter = new VariableLengthBlittableScanIterator<Key, Value>(this, beginAddress, endAddress, ScanBufferingMode.NoBuffering, epoch, true);
observer?.OnNext(iter);
Expand Down

0 comments on commit a3fe2c6

Please sign in to comment.