microsoft/garnet · error · TsavoriteException

{nameof(logSettings.PageCount)} or {nameof(logSettings.Memor

Error message

{nameof(logSettings.PageCount)} or {nameof(logSettings.MemorySize)} must be specified

What it means

Constructor validation in AllocatorBase: the in-memory circular buffer must be sized, and you must supply at least one of logSettings.MemorySize (bytes) or logSettings.PageCount. With both at 0 the allocator cannot decide how many pages to keep resident, so construction aborts. Note MemorySize defaults to 1L<<34 (16GiB), so this only fires when a caller explicitly set MemorySize = 0 and left PageCount = 0.

Source

Thrown at libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs:548

        {
            var logSettings = allocatorSettings.LogSettings;
            var evictCallback = allocatorSettings.evictCallback;
            var epoch = allocatorSettings.epoch;
            var flushCallback = allocatorSettings.flushCallback;
            IsReadCache = allocatorSettings.IsReadCache;

            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)

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Set logSettings.MemorySize to a positive value within [1<<13, 1<<62] (default 1<<34 is fine), or
  2. Set logSettings.PageCount to at least kMinPageCount (2); for ReadOnly logs PageCount is the recommended sizing knob.
  3. If you intended a ReadOnly log, keep MemorySize = 0 but set PageCount explicitly.

Example fix

// before
var s = new LogSettings { LogDevice = dev, MemorySize = 0, PageCount = 0 };
// after (readonly-style sizing)
var s = new LogSettings { LogDevice = dev, MemorySize = 0, PageCount = 64 };
// or simply rely on the default MemorySize by not zeroing it
Defensive patterns

Strategy: validation

Validate before calling

static void EnsureSized(LogSettings s)
{
    if (s.MemorySize == 0 && s.PageCount == 0)
        throw new ArgumentException("Set LogSettings.MemorySize (>0) or LogSettings.PageCount (>0); both are 0.");
}

// call before constructing TsavoriteKV/TsavoriteLog
EnsureSized(logSettings);

Try / catch

try { new TsavoriteLog(logSettings); }
catch (TsavoriteException ex) when (ex.Message.Contains("PageCount") && ex.Message.Contains("MemorySize") && ex.Message.Contains("must be specified"))
{ /* set MemorySize or PageCount, then recreate */ }

Prevention

When it happens

Trigger: Constructing TsavoriteKV/TsavoriteLog with `new LogSettings { MemorySize = 0, PageCount = 0, ... }`, or with a ReadOnly log where MemorySize was zeroed but PageCount was never set.

Common situations: Building a ReadOnly TsavoriteLog and copying a minimal-config template that zeroed MemorySize without adding PageCount; shrinking RAM footprint by setting MemorySize=0 believing PageCount would default; migrating from an older sample that set fields differently.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/8e95be37c7df1b28. Report an issue: GitHub.