Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

yrajas
Copy link
Contributor

@yrajas yrajas commented Apr 4, 2024

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.

libs/server/Servers/GarnetServerOptions.cs Show resolved Hide resolved
libs/server/Servers/ServerOptions.cs Outdated Show resolved Hide resolved
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)
Copy link
Contributor

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;

Copy link
Contributor

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,
Copy link
Contributor

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

@yrajas yrajas closed this Apr 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2024
@yrajas yrajas deleted the yrajas/buffsiz branch June 21, 2024 18:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants