{"record":{"id":"e9a6e295fd6c10ca","repo":"microsoft/FASTER","slug":"nameof-indexsize-should-be-at-least-of-size-8-cache-line-512","errorCode":null,"errorMessage":"{nameof(IndexSize)} should be at least of size 8 cache line (512 bytes)","messagePattern":"(.+?) should be at least of size 8 cache line \\(512 bytes\\)","errorType":"validation","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/Index/Common/FasterKVSettings.cs","lineNumber":214,"sourceCode":"        /// <inheritdoc />\n        public override string ToString()\n        {\n            var retStr = $\"index: {Utility.PrettySize(IndexSize)}; log memory: {Utility.PrettySize(MemorySize)}; log page: {Utility.PrettySize(PageSize)}; log segment: {Utility.PrettySize(SegmentSize)}\";\n            retStr += $\"; log device: {(LogDevice == null ? \"null\" : LogDevice.GetType().Name)}\";\n            retStr += $\"; obj log device: {(ObjectLogDevice == null ? \"null\" : ObjectLogDevice.GetType().Name)}\";\n            retStr += $\"; mutable fraction: {MutableFraction}; locking mode: {this.ConcurrencyControlMode}\";\n            retStr += $\"; read cache (rc): {(ReadCacheEnabled ? \"yes\" : \"no\")}\";\n            retStr += $\"; read copy options: {ReadCopyOptions}\";\n            if (ReadCacheEnabled)\n                retStr += $\"; rc memory: {Utility.PrettySize(ReadCacheMemorySize)}; rc page: {Utility.PrettySize(ReadCachePageSize)}\";\n            return retStr;\n        }\n\n        internal long GetIndexSizeCacheLines()\n        {\n            long adjustedSize = Utility.PreviousPowerOf2(IndexSize);\n            if (adjustedSize < 512)\n                throw new FasterException($\"{nameof(IndexSize)} should be at least of size 8 cache line (512 bytes)\");\n            if (IndexSize != adjustedSize)  // Don't use string interpolation when logging messages because it makes it impossible to group by the message template.\n                logger?.LogInformation(\"Warning: using lower value {0} instead of specified {1} for {2}\", adjustedSize, IndexSize, nameof(IndexSize));\n            return adjustedSize / 64;\n        }\n\n        internal LogSettings GetLogSettings()\n        {\n            return new LogSettings\n            {\n                ReadCopyOptions = ReadCopyOptions,\n                LogDevice = LogDevice,\n                ObjectLogDevice = ObjectLogDevice,\n                MemorySizeBits = Utility.NumBitsPreviousPowerOf2(MemorySize),\n                PageSizeBits = Utility.NumBitsPreviousPowerOf2(PageSize),\n                SegmentSizeBits = Utility.NumBitsPreviousPowerOf2(SegmentSize),\n                MutableFraction = MutableFraction,\n                PreallocateLog = PreallocateLog,\n                ReadCacheSettings = GetReadCacheSettings()","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Index/Common/FasterKVSettings.cs#L196-L232","documentation":"FasterKVSettings.GetIndexSizeCacheLines enforces a minimum hash index size of 512 bytes (8 cache lines) by rounding IndexSize down to the previous power of 2 and validating it. An IndexSize below 512 is rejected because the hash index machinery assumes at least a full cache-line-set granularity.","triggerScenarios":"Constructing FasterKV (or calling GetIndexSizeCacheLines via the FasterKV ctor) with FasterKVSettings.IndexSize smaller than 512, e.g. IndexSize = 1L<<8 (256) or a tiny value like 64.","commonSituations":"Developers experimenting with minimal in-memory setups, unit tests with tiny indexes, misreading IndexSize units (it is a byte count of index memory, not an entry count).","solutions":["Set IndexSize to at least 512 in FasterKVSettings","Use a sensible power-of-2 value such as 1L<<20 or larger; the library rounds down to the previous power of 2 anyway"],"exampleFix":"// before\nvar settings = new FasterKVSettings<long, long> { IndexSize = 256 };\n// after\nvar settings = new FasterKVSettings<long, long> { IndexSize = 1L << 20 }; // >= 512 bytes, power of 2","handlingStrategy":"validation","validationCode":"if (settings.IndexSize < 512)\n    throw new ArgumentException(\"IndexSize must be at least 512 bytes (8 cache lines)\");","typeGuard":null,"tryCatchPattern":"try { var kv = new FasterKV<long, long>(settings); }\ncatch (FasterException ex) when (ex.Message.Contains(\"should be at least of size 8 cache line\"))\n{\n    settings.IndexSize = 512; // or a larger power-of-2\n    var kv = new FasterKV<long, long>(settings);\n}","preventionTips":["Treat IndexSize as bytes of index memory and keep it >= 512 (practically much larger)","Prefer power-of-2 values like 1L<<20 for index size in configuration templates","Add config validation at startup before constructing FasterKV"],"tags":["configuration","fasterkv","index-size","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}