microsoft/garnet · error · TsavoriteException
{nameof(logSettings.PageCount)} must be less than or equal t
Error message
{nameof(logSettings.PageCount)} must be less than or equal to the maximum array length ({MemoryUtils.ArrayMaxLength}) What it means
Constructor validation: logSettings.PageCount must not exceed MemoryUtils.ArrayMaxLength (0x7FFFFFC7 = 2,147,483,591), because the page ring is backed by a single array indexed by page number. A PageCount above this cannot be allocated as a .NET array.
Source
Thrown at libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs:554
this.storeFunctions = storeFunctions;
_wrapper = wrapperCreator(this);
// Pre-bind the instance-method delegate once so the pending-IO hot path does
// not allocate a fresh DeviceIOCompletionCallback per AsyncGetFromDisk call.
asyncGetFromDiskCallbackDelegate = AsyncGetFromDiskCallback;
this.transientObjectIdMap = transientObjectIdMap;
// Validation
if (logSettings.PageCount == 0 && logSettings.MemorySize == 0)
throw new TsavoriteException($"{nameof(logSettings.PageCount)} or {nameof(logSettings.MemorySize)} must be specified");
if (logSettings.PageSizeBits < LogSettings.kMinPageSizeBits || logSettings.PageSizeBits > LogSettings.kMaxPageSizeBits)
throw new TsavoriteException($"{nameof(logSettings.PageSizeBits)} must be between {LogSettings.kMinPageSizeBits} and {LogSettings.kMaxPageSizeBits}");
if (logSettings.PageSizeBits < PageHeader.SizeBits)
throw new TsavoriteException($"{nameof(logSettings.PageSizeBits)} must be >= PageHeader.SizeBits {PageHeader.SizeBits}");
if (logSettings.PageCount > MemoryUtils.ArrayMaxLength)
throw new TsavoriteException($"{nameof(logSettings.PageCount)} must be less than or equal to the maximum array length ({MemoryUtils.ArrayMaxLength})");
if (logSettings.SegmentSizeBits < LogSettings.kMinMainLogSegmentSizeBits || logSettings.SegmentSizeBits > LogSettings.kMaxSegmentSizeBits)
throw new TsavoriteException($"{nameof(logSettings.SegmentSizeBits)} must be between {LogSettings.kMinMainLogSegmentSizeBits} and {LogSettings.kMaxSegmentSizeBits}");
if (logSettings.MemorySize != 0 && (logSettings.MemorySize < 1L << LogSettings.kMinMemorySizeBits || logSettings.MemorySize > 1L << LogSettings.kMaxMemorySizeBits))
throw new TsavoriteException($"{nameof(logSettings.MemorySize)} must be between {1L << LogSettings.kMinMemorySizeBits} and {1L << LogSettings.kMaxMemorySizeBits}, or may be 0 for ReadOnly TsavoriteLog");
if ((logSettings.MemorySize != 0) && (logSettings.MemorySize < (1L << logSettings.PageSizeBits) * LogSettings.kMinPageCount))
throw new TsavoriteException($"{nameof(logSettings.MemorySize)} must be at least {LogSettings.kMinPageCount}x the page size ({1L << logSettings.PageSizeBits})");
if (logSettings.MutableFraction < 0.0 || logSettings.MutableFraction > 1.0)
throw new TsavoriteException($"{nameof(logSettings.MutableFraction)} must be >= 0.0 and <= 1.0");
if (logSettings.ReadCacheSettings is not null)
{
var rcs = logSettings.ReadCacheSettings;
if (rcs.PageCount == 0 && rcs.MemorySize == 0)
throw new TsavoriteException($"{nameof(rcs.PageCount)} or {nameof(rcs.MemorySize)} must be specified");
if (rcs.PageSizeBits < LogSettings.kMinPageSizeBits || rcs.PageSizeBits > LogSettings.kMaxPageSizeBits)
throw new TsavoriteException($"{nameof(rcs.PageSizeBits)} must be between {LogSettings.kMinPageSizeBits} and {LogSettings.kMaxPageSizeBits}");
if (rcs.PageCount > MemoryUtils.ArrayMaxLength)
throw new TsavoriteException($"{nameof(rcs.PageCount)} must be less than or equal to the maximum array length ({MemoryUtils.ArrayMaxLength})");
if (rcs.MemorySize != 0 && (rcs.MemorySize < 1L << LogSettings.kMinMemorySizeBits || rcs.MemorySize > 1L << LogSettings.kMaxMemorySizeBits))View on GitHub (pinned to 951b0fc683)
Solutions
- Reduce PageCount to <= 0x7FFFFFC7; in practice keep it modest (hundreds to thousands of pages).
- If you derived PageCount from MemorySize, prefer leaving PageCount = 0 and letting the allocator compute it as MemorySize / PageSize.
- Re-check the arithmetic that produced the large number (likely a bytes/pages unit error).
Example fix
// before logSettings.PageCount = int.MaxValue; // after logSettings.PageCount = 0; // let allocator derive from MemorySize // or logSettings.PageCount = 4096;
Defensive patterns
Strategy: validation
Validate before calling
const int ArrayMaxLength = 0x7FFFFFC7; // MemoryUtils.ArrayMaxLength
if (logSettings.PageCount > ArrayMaxLength)
throw new ArgumentOutOfRangeException(nameof(logSettings.PageCount),
$"PageCount {logSettings.PageCount} exceeds ArrayMaxLength {ArrayMaxLength}"); Try / catch
try { new TsavoriteKV<K,V>(logSettings, ...); }
catch (TsavoriteException ex) when (ex.Message.Contains("PageCount") && ex.Message.Contains("maximum array length"))
{ /* reduce PageCount or leave it 0 to derive from MemorySize */ } Prevention
- Prefer leaving PageCount=0 and sizing via MemorySize.
- Clamp config-sourced PageCount to a sane ceiling (e.g. 1_000_000) before assignment.
- Verify bytes-vs-pages units when computing PageCount.
When it happens
Trigger: Setting `logSettings.PageCount = int.MaxValue` or computing it from a huge MemorySize expression and assigning a value above 0x7FFFFFC7.
Common situations: Trying to pre-size the buffer for an extreme workload by pushing PageCount to int.MaxValue; unit confusion (bytes vs pages) yielding billions of pages.
Related errors
- {nameof(rcs.PageCount)} must be less than or equal to the ma
- {nameof(logSettings.PageCount)} or {nameof(logSettings.Memor
- {nameof(logSettings.PageSizeBits)} must be between {LogSetti
- {nameof(logSettings.PageSizeBits)} must be >= PageHeader.Siz
- {nameof(logSettings.SegmentSizeBits)} must be between {LogSe
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/001189bf67dcb0bd.
Report an issue: GitHub.