{"record":{"id":"93ab4d9d294b973e","repo":"microsoft/garnet","slug":"log-memory-size-or-pagecount-must-be-specified","errorCode":null,"errorMessage":"Log Memory size or PageCount must be specified","messagePattern":"Log Memory size or PageCount must be specified","errorType":"validation","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs","lineNumber":626,"sourceCode":"            // Page size\n            LogPageSizeBits = logSettings.PageSizeBits;\n            PageSize = 1 << LogPageSizeBits;\n            PageSizeMask = PageSize - 1;\n\n            // Total HLOG size and MaxAllocatedPageCount. There are a couple ways MaxAllocatedPageCount can be set here; once set it\n            // will never be exceeded by AllocatedPageCount, even if memory usage falls below logSettings.MemorySize. Memory\n            // size tracking will be enforced only if this.logSizeTracker is set; otherwise, we set the MaxAllocatedPageCount here and\n            // do not control heap memory usage.\n            if (logSettings.MemorySize > 0)\n            {\n                // If LogSettings.PageCount is specified it becomes MaxAllocatedPageCount; otherwise MaxAllocatedPageCount will be\n                // MaxMemorySize divided by page size.\n                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            {","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/AllocatorBase.cs#L608-L644","documentation":"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.","triggerScenarios":"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.","commonSituations":"Subclassing/customizing the allocator init sequence; a fork that reordered validation; calling an internal Initialize entry point directly with an under-specified LogSettings.","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."],"exampleFix":"// before\nlogSettings.MemorySize = 0;\nlogSettings.PageCount  = 0;\n// after\nlogSettings.PageCount = 64;   // size the ring by page count","handlingStrategy":"validation","validationCode":"if (logSettings.MemorySize <= 0 && logSettings.PageCount <= 0)\n    throw new ArgumentException(\"Log MemorySize (>0) or PageCount (>0) must be specified for buffer sizing.\");","typeGuard":null,"tryCatchPattern":"try { /* allocator init / Initialize */ }\ncatch (TsavoriteException ex) when (ex.Message.Contains(\"Memory size or PageCount must be specified\"))\n{ /* set MemorySize or PageCount to a positive value and reinitialize */ }","preventionTips":["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."],"tags":["storage","configuration","log-settings","memory"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}