Skip to content

Commit

Permalink
[C#] Added check for minimum page size to ensure it is at least of si…
Browse files Browse the repository at this point in the history
…ze one sector (#380)

* Added check for minimum page size to ensure it is at least of size one sector.

* Update 23-fasterkv-tuning.md
  • Loading branch information
badrishc authored Nov 29, 2020
1 parent a27f0b5 commit 1c1e1a6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cs/src/core/Allocator/AllocatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ public AllocatorBase(LogSettings settings, IFasterEqualityComparer<Key> 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));
}

Expand Down
2 changes: 1 addition & 1 deletion cs/test/BlittableIterationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Setup()
{
log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableIterationTests.log", deleteOnClose: true);
fht = new FasterKV<KeyStruct, ValueStruct>
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 });
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 });
}

[TearDown]
Expand Down
2 changes: 1 addition & 1 deletion cs/test/BlittableLogCompactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Setup()
{
log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableLogCompactionTests.log", deleteOnClose: true);
fht = new FasterKV<KeyStruct, ValueStruct>
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 });
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 });
}

[TearDown]
Expand Down
2 changes: 1 addition & 1 deletion cs/test/BlittableLogScanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Setup()
{
log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/BlittableFASTERScanTests.log", deleteOnClose: true);
fht = new FasterKV<KeyStruct, ValueStruct>
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 7 });
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9 });
}

[TearDown]
Expand Down
3 changes: 2 additions & 1 deletion docs/_docs/23-fasterkv-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (2<sup>P</sup>). For example, when `PageSizeBits` P is set to 12, it represents pages of size 4KB
(since 2<sup>P</sup> = 2<sup>10</sup> = 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, 2<sup>M</sup> is the number of bytes used totally by the log. Since each page is of size 2<sup>P</sup>, the
Expand Down

0 comments on commit 1c1e1a6

Please sign in to comment.