microsoft/garnet · error · TsavoriteException
Log Memory size or PageCount must be specified
Error message
Log Memory size or PageCount must be specified
What it means
Thrown in the MaxAllocatedPageCount sizing step: the allocator needs either a positive MemorySize (to derive page count = MemorySize / PageSize) or a positive PageCount to size the circular buffer directly. With MemorySize <= 0 and PageCount <= 0 it cannot compute the buffer size. This overlaps with the constructor's error 221 guard but lives on the buffer-sizing path; it also catches a negative MemorySize that slipped past earlier validation.
Source
Thrown at libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs:626
// Page size
LogPageSizeBits = logSettings.PageSizeBits;
PageSize = 1 << LogPageSizeBits;
PageSizeMask = PageSize - 1;
// Total HLOG size and MaxAllocatedPageCount. There are a couple ways MaxAllocatedPageCount can be set here; once set it
// will never be exceeded by AllocatedPageCount, even if memory usage falls below logSettings.MemorySize. Memory
// size tracking will be enforced only if this.logSizeTracker is set; otherwise, we set the MaxAllocatedPageCount here and
// do not control heap memory usage.
if (logSettings.MemorySize > 0)
{
// If LogSettings.PageCount is specified it becomes MaxAllocatedPageCount; otherwise MaxAllocatedPageCount will be
// MaxMemorySize divided by page size.
MaxAllocatedPageCount = logSettings.PageCount > 0 ? logSettings.PageCount : (int)(logSettings.MemorySize / PageSize);
}
else
{
if (logSettings.PageCount <= 0)
throw new TsavoriteException($"Log Memory size or PageCount must be specified");
MaxAllocatedPageCount = logSettings.PageCount;
}
BufferSize = (int)NextPowerOf2(MaxAllocatedPageCount);
BufferSizeMask = BufferSize - 1;
logMutableFraction = logSettings.MutableFraction;
// Segment size
LogSegmentSizeBits = logSettings.SegmentSizeBits;
SegmentSize = 1L << LogSegmentSizeBits;
if (SegmentSize < PageSize)
throw new TsavoriteException($"Segment ({SegmentSize}) must be at least of page size ({PageSize})");
PageStatusIndicator = new FullPageStatus[BufferSize];
if (!IsNullDevice)
{View on GitHub (pinned to 951b0fc683)
Solutions
- Ensure at least one of MemorySize (>0) or PageCount (>0) is set before initialization; default MemorySize (16GiB) satisfies this.
- If you zeroed MemorySize for a ReadOnly log, set PageCount explicitly.
- Do not bypass the standard constructor validation; if you do, replicate these checks upstream.
Example fix
// before logSettings.MemorySize = 0; logSettings.PageCount = 0; // after logSettings.PageCount = 64; // size the ring by page count
Defensive patterns
Strategy: validation
Validate before calling
if (logSettings.MemorySize <= 0 && logSettings.PageCount <= 0)
throw new ArgumentException("Log MemorySize (>0) or PageCount (>0) must be specified for buffer sizing."); Try / catch
try { /* allocator init / Initialize */ }
catch (TsavoriteException ex) when (ex.Message.Contains("Memory size or PageCount must be specified"))
{ /* set MemorySize or PageCount to a positive value and reinitialize */ } Prevention
- Do not bypass the standard constructor validation; if you do, replicate this check upstream.
- Ensure MemorySize or PageCount is positive before any Initialize call.
- For ReadOnly logs keep MemorySize=0 but set PageCount.
When it happens
Trigger: Reaching page-buffer initialization with logSettings.MemorySize <= 0 and logSettings.PageCount <= 0 — e.g. a code path or subclass that bypassed the main validation block, or a negative MemorySize.
Common situations: Subclassing/customizing the allocator init sequence; a fork that reordered validation; calling an internal Initialize entry point directly with an under-specified LogSettings.
Related errors
- {nameof(logSettings.PageCount)} or {nameof(logSettings.Memor
- {nameof(logSettings.MemorySize)} must be between {1L << LogS
- {nameof(logSettings.MemorySize)} must be at least {LogSettin
- {nameof(rcs.MemorySize)} must be between {1L << LogSettings.
- {nameof(logSettings.MemorySize)} must be at least twice the
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/93ab4d9d294b973e.
Report an issue: GitHub.