Skip to content

Commit

Permalink
Merge branch 'master' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc authored Dec 8, 2021
2 parents ef5be45 + 29c8bc6 commit 014ffb9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions cs/src/core/Utilities/BufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ public override string ToString()
public sealed class SectorAlignedBufferPool
{
/// <summary>
/// Disable buffer pool
/// Disable buffer pool.
/// This static option should be enabled on program entry, and not modified once FASTER is instantiated.
/// </summary>
public static bool Disabled = false;

/// <summary>
/// Unpin objects when they are returned to the pool, so that we do not hold pinned objects long term.
/// If set, we will unpin when objects are returned and re-pin when objects are returned from the pool.
/// This static option should be enabled on program entry, and not modified once FASTER is instantiated.
/// </summary>
public static bool UnpinOnReturn = false;

private const int levels = 32;
private readonly int recordSize;
private readonly int sectorSize;
Expand Down Expand Up @@ -164,7 +172,14 @@ public void Return(SectorAlignedMemory page)
page.valid_offset = 0;
Array.Clear(page.buffer, 0, page.buffer.Length);
if (!Disabled)
{
if (UnpinOnReturn)
{
page.handle.Free();
page.handle = default;
}
queue[page.level].Enqueue(page);
}
else
{
page.handle.Free();
Expand Down Expand Up @@ -210,6 +225,12 @@ public unsafe SectorAlignedMemory Get(int numRecords)

if (!Disabled && queue[index].TryDequeue(out SectorAlignedMemory page))
{
if (UnpinOnReturn)
{
page.handle = GCHandle.Alloc(page.buffer, GCHandleType.Pinned);
page.aligned_pointer = (byte*)(((long)page.handle.AddrOfPinnedObject() + (sectorSize - 1)) & ~((long)sectorSize - 1));
page.offset = (int)((long)page.aligned_pointer - (long)page.handle.AddrOfPinnedObject());
}
return page;
}

Expand Down Expand Up @@ -239,7 +260,8 @@ public void Free()
if (queue[i] == null) continue;
while (queue[i].TryDequeue(out SectorAlignedMemory result))
{
result.handle.Free();
if (!UnpinOnReturn)
result.handle.Free();
result.buffer = null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/_pages/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ header:
url: "/docs/quick-start-guide/"
excerpt: >
A fast concurrent persistent key-value store and log, in C# and C++.<br />
<small><a href="https://github.com/microsoft/FASTER/releases/tag/v1.9.6">Latest release v1.9.6</a></small>
<small><a href="https://github.com/microsoft/FASTER/releases/tag/v1.9.9">Latest release v1.9.9</a></small>
features:
- image_path: /assets/images/faster-feature-1.png
alt: "feature1"
Expand Down

0 comments on commit 014ffb9

Please sign in to comment.