-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make MemorySize a multiple of page size and not necessarily a power of two #233
Conversation
if (settings.MemorySizeBits != 0 && (settings.MemorySizeBits < LogSettings.kMinMemorySizeBits || settings.MemorySizeBits > LogSettings.kMaxMemorySizeBits)) | ||
throw new TsavoriteException($"{nameof(settings.MemorySizeBits)} must be between {LogSettings.kMinMemorySizeBits} and {LogSettings.kMaxMemorySizeBits}, or may be 0 for ReadOnly TsavoriteLog"); | ||
if (settings.MemorySizePages != 0 && (settings.MemorySizePages < LogSettings.kMinMemorySizePages || settings.MemorySizePages > LogSettings.kMaxMemorySizePages)) | ||
throw new TsavoriteException($"{nameof(settings.MemorySizePages)} must be between {LogSettings.kMinMemorySizePages} and {LogSettings.kMaxMemorySizePages}, or may be 0 for ReadOnly TsavoriteLog"); | ||
if (settings.MutableFraction < 0.0 || settings.MutableFraction > 1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in LogSetting regarding kMaxMemorySizePages
/// <summary>Minimum number of pages for the size of the in-memory portion of the log</summary> | ||
public const int kMinMemorySizePages = 1; // At least one page | ||
/// <summary>Maximum number of pages for the size of the in-memory portion of the log</summary> | ||
public const int kMaxMemorySizePages = int.MaxValue; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this to reach the old kMaxMemorySizeBits equivalent, the PageSizeBits would have to be 31. Instead, I think it's better to keep a kMemorySizeMax = 1 << 62, then verify in AllocatorBase that the specified config does not exceed this
@@ -204,7 +204,7 @@ internal LogSettings GetLogSettings() | |||
LogDevice = LogDevice, | |||
PageSizeBits = Utility.NumBitsPreviousPowerOf2(PageSize), | |||
SegmentSizeBits = Utility.NumBitsPreviousPowerOf2(SegmentSize), | |||
MemorySizeBits = ReadOnlyMode ? 0 : Utility.NumBitsPreviousPowerOf2(MemorySize), | |||
MemorySizePages = ReadOnlyMode ? 0 : (int)(MemorySize / (1L << Utility.NumBitsPreviousPowerOf2(PageSize))), | |||
ReadCopyOptions = ReadCopyOptions.None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use PageSizeBits instead of repeating Utility.NumBitsPreviousPowerOf2
MemorySize is currently enforced to be a power of two. If memory is configured to be not a power of two, then the size is adjusted dynamically using EmptyPageCount. Also, the EmptyPageCount is not enforced during recovery.
This change removes the power of two constraint for MemorySize. With this, the memory size is constrained to be a multiple of PageSize. This makes MemorySize to be constant during recovery as well as regular operation.
The EmptyPageCount would still be used to control Object Store GC heap memory size.