From 92ae4af2a720fff5be223dee392bf7c660f347df Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Tue, 7 Dec 2021 16:28:27 -0800 Subject: [PATCH 1/2] [C#] Add static option to unpin objects when returning to SectorAlignedMemoryPool (#606) * Fix memory leak with bulk flushes during checkpoints. * Cherry pick fix from v2, for not throwing error when we run out of space in PendingFlushList. * nit * change testcase to use lower memory. * Option to unpin pool objects on return. * nit * update comment. * nit * formatting --- cs/src/core/Utilities/BufferPool.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cs/src/core/Utilities/BufferPool.cs b/cs/src/core/Utilities/BufferPool.cs index ae064ef83..525581eed 100644 --- a/cs/src/core/Utilities/BufferPool.cs +++ b/cs/src/core/Utilities/BufferPool.cs @@ -123,10 +123,18 @@ public override string ToString() public sealed class SectorAlignedBufferPool { /// - /// Disable buffer pool + /// Disable buffer pool. + /// This static option should be enabled on program entry, and not modified once FASTER is instantiated. /// public static bool Disabled = false; + /// + /// 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. + /// + public static bool UnpinOnReturn = false; + private const int levels = 32; private readonly int recordSize; private readonly int sectorSize; @@ -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(); @@ -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; } @@ -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; } } From 29c8bc642bb4b02b5ae8af473117974dc9b9afd3 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Tue, 7 Dec 2021 16:37:47 -0800 Subject: [PATCH 2/2] Update home.md --- docs/_pages/home.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_pages/home.md b/docs/_pages/home.md index 0188146f6..2ad096725 100644 --- a/docs/_pages/home.md +++ b/docs/_pages/home.md @@ -10,7 +10,7 @@ header: url: "/docs/quick-start-guide/" excerpt: > A fast concurrent persistent key-value store and log, in C# and C++.
- Latest release v1.9.6 + Latest release v1.9.9 features: - image_path: /assets/images/faster-feature-1.png alt: "feature1"