{"record":{"id":"55db727e7e1a1ac3","repo":"microsoft/garnet","slug":"segment-segmentsize-must-be-at-least-of-page-s","errorCode":null,"errorMessage":"Segment ({SegmentSize}) must be at least of page size ({PageSize})","messagePattern":"Segment \\((.+?)\\) must be at least of page size \\((.+?)\\)","errorType":"validation","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs","lineNumber":639,"sourceCode":"                MaxAllocatedPageCount = logSettings.PageCount > 0 ? logSettings.PageCount : (int)(logSettings.MemorySize / PageSize);\n            }\n            else\n            {\n                if (logSettings.PageCount <= 0)\n                    throw new TsavoriteException($\"Log Memory size or PageCount must be specified\");\n                MaxAllocatedPageCount = logSettings.PageCount;\n            }\n            BufferSize = (int)NextPowerOf2(MaxAllocatedPageCount);\n\n            BufferSizeMask = BufferSize - 1;\n\n            logMutableFraction = logSettings.MutableFraction;\n\n            // Segment size\n            LogSegmentSizeBits = logSettings.SegmentSizeBits;\n            SegmentSize = 1L << LogSegmentSizeBits;\n            if (SegmentSize < PageSize)\n                throw new TsavoriteException($\"Segment ({SegmentSize}) must be at least of page size ({PageSize})\");\n\n            PageStatusIndicator = new FullPageStatus[BufferSize];\n\n            if (!IsNullDevice)\n            {\n                PendingFlush = new PendingFlushList[BufferSize];\n                for (int i = 0; i < BufferSize; i++)\n                    PendingFlush[i] = new PendingFlushList();\n            }\n            device = logSettings.LogDevice;\n            sectorSize = (int)device.SectorSize;\n\n            if (PageSize < sectorSize)\n                throw new TsavoriteException($\"Page size must be at least of device sector size ({sectorSize} bytes). Set PageSizeBits accordingly.\");\n\n            AlignedPageSizeBytes = RoundUp(PageSize, sectorSize);\n\n            if (BufferSize > 0)","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs#L621-L657","documentation":"Thrown in the segment-size step: SegmentSize (1 << SegmentSizeBits) must be >= PageSize (1 << PageSizeBits), because segments are groups of pages and cannot be smaller than a single page. Even when each of PageSizeBits and SegmentSizeBits is individually in range (errors 222 and 225), a large page combined with a smaller segment trips this; e.g. PageSizeBits=25 (32MiB) with SegmentSizeBits=12 (4KiB) => 4KiB < 32MiB.","triggerScenarios":"Setting SegmentSizeBits < PageSizeBits, or raising PageSizeBits above the existing SegmentSizeBits without also raising the segment size.","commonSituations":"Tuning PageSizeBits up for fewer, larger flush units and forgetting to bump SegmentSizeBits; mirroring a config where the two were changed independently.","solutions":["Ensure SegmentSizeBits >= PageSizeBits (so each segment holds at least one page).","When raising PageSizeBits, raise SegmentSizeBits to match or exceed it.","Keep the defaults (PageSizeBits=25, SegmentSizeBits=30) unless you have measured reason to change both consistently."],"exampleFix":"// before\nlogSettings.PageSizeBits   = 25;  // 32MiB page\nlogSettings.SegmentSizeBits = 12;  // 4KiB segment -> < page\n// after\nlogSettings.SegmentSizeBits = 30;  // 1GiB segment >= 32MiB page","handlingStrategy":"validation","validationCode":"// Segment must be >= page: SegmentSizeBits >= PageSizeBits.\nif (logSettings.SegmentSizeBits < logSettings.PageSizeBits)\n    logSettings.SegmentSizeBits = logSettings.PageSizeBits;  // or larger, e.g. +5","typeGuard":null,"tryCatchPattern":"try { new TsavoriteKV<K,V>(logSettings, ...); }\ncatch (TsavoriteException ex) when (ex.Message.Contains(\"Segment\") && ex.Message.Contains(\"at least of page size\"))\n{ /* raise SegmentSizeBits to >= PageSizeBits and recreate */ }","preventionTips":["Always keep SegmentSizeBits >= PageSizeBits.","When tuning PageSizeBits up, recheck SegmentSizeBits in the same change.","Add a config assertion: SegmentSizeBits >= PageSizeBits."],"tags":["storage","configuration","log-settings","segment-size","page-size"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}