From 1c1e1a6d03bc5e54a36461cbe71654df32edfcdc Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Sun, 29 Nov 2020 14:30:58 -0800 Subject: [PATCH] [C#] Added check for minimum page size to ensure it is at least of size one sector (#380) * Added check for minimum page size to ensure it is at least of size one sector. * Update 23-fasterkv-tuning.md --- cs/src/core/Allocator/AllocatorBase.cs | 4 ++++ cs/test/BlittableIterationTests.cs | 2 +- cs/test/BlittableLogCompactionTests.cs | 2 +- cs/test/BlittableLogScanTests.cs | 2 +- docs/_docs/23-fasterkv-tuning.md | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cs/src/core/Allocator/AllocatorBase.cs b/cs/src/core/Allocator/AllocatorBase.cs index d8c1ab0b4..94172126e 100644 --- a/cs/src/core/Allocator/AllocatorBase.cs +++ b/cs/src/core/Allocator/AllocatorBase.cs @@ -552,6 +552,10 @@ public AllocatorBase(LogSettings settings, IFasterEqualityComparer comparer device = settings.LogDevice; sectorSize = (int)device.SectorSize; + + if (PageSize < sectorSize) + throw new FasterException($"Page size must be at least of device sector size ({sectorSize} bytes). Set PageSizeBits accordingly."); + AlignedPageSizeBytes = ((PageSize + (sectorSize - 1)) & ~(sectorSize - 1)); } diff --git a/cs/test/BlittableIterationTests.cs b/cs/test/BlittableIterationTests.cs index 50d01c81a..3cda86124 100644 --- a/cs/test/BlittableIterationTests.cs +++ b/cs/test/BlittableIterationTests.cs @@ -25,7 +25,7 @@ public void Setup() { log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableIterationTests.log", deleteOnClose: true); fht = new FasterKV - (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 }); + (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 }); } [TearDown] diff --git a/cs/test/BlittableLogCompactionTests.cs b/cs/test/BlittableLogCompactionTests.cs index 8a57dcddb..b4081ea6d 100644 --- a/cs/test/BlittableLogCompactionTests.cs +++ b/cs/test/BlittableLogCompactionTests.cs @@ -25,7 +25,7 @@ public void Setup() { log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableLogCompactionTests.log", deleteOnClose: true); fht = new FasterKV - (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 }); + (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 }); } [TearDown] diff --git a/cs/test/BlittableLogScanTests.cs b/cs/test/BlittableLogScanTests.cs index 3599041fe..31e710105 100644 --- a/cs/test/BlittableLogScanTests.cs +++ b/cs/test/BlittableLogScanTests.cs @@ -26,7 +26,7 @@ public void Setup() { log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableFASTERScanTests.log", deleteOnClose: true); fht = new FasterKV - (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 }); + (1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 }); } [TearDown] diff --git a/docs/_docs/23-fasterkv-tuning.md b/docs/_docs/23-fasterkv-tuning.md index 1191e7582..11f7bf61f 100644 --- a/docs/_docs/23-fasterkv-tuning.md +++ b/docs/_docs/23-fasterkv-tuning.md @@ -36,7 +36,8 @@ the device via `IDisposable`. of bits. You get the actual size of the page by a simple computation of two raised to the power of the number specified (2P). For example, when `PageSizeBits` P is set to 12, it represents pages of size 4KB (since 2P = 210 = 4096 = 4KB). Generally you should not need to adjust page size from its -default value of 25 (= 32MB). +default value of 25 (= 32MB). You cannot use a page size smaller than the device sector size (512 bytes by +default), which translates to a `PageSizeBits` value of at least 9. * `MemorySizeBits`: This field (M) indicates the total size of memory used by the log. As before, for a setting of M, 2M is the number of bytes used totally by the log. Since each page is of size 2P, the