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

Add setting to control the maximum swap space #10978

Merged
merged 40 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2130e4d
moved from 'temporary_file_manager' branch
Tishj Mar 1, 2024
d20a0f7
Merge branch 'temporary_file_manager' into maximum_swap_space
Tishj Mar 1, 2024
9d5d254
Merge branch 'temporary_file_manager' into maximum_swap_space
Tishj Mar 1, 2024
1e441a6
create the exception, thrown whenever we try to increase the temp dir…
Tishj Mar 1, 2024
b7d9997
increase to 5x memory limit
Tishj Mar 7, 2024
3d10568
collect information about the disk when possible
Tishj Mar 8, 2024
a0d98f4
further thinking
Tishj Mar 8, 2024
8c8ffe6
test that explicitly set values are not overridden when we create the…
Tishj Mar 8, 2024
d3ecab6
add initial tests
Tishj Mar 8, 2024
a97bcb7
more tests with different max swap sizes
Tishj Mar 8, 2024
0227e2d
fix up comment
Tishj Mar 8, 2024
d56137a
check if the config was set explicitly or not in DatabaseInstance::Co…
Tishj Mar 8, 2024
b37d193
avoid modifying the passed in DBConfig
Tishj Mar 8, 2024
1491dd7
fix up some behavior
Tishj Mar 8, 2024
8b2b5cd
make the in-memory database detection better
Tishj Mar 8, 2024
96fc46e
initialize temp_directory to '.tmp' for every version of in-memory co…
Tishj Mar 8, 2024
8ad8353
use 90% of the available disk space by default
Tishj Mar 8, 2024
63e37c9
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 11, 2024
29678c5
RESET temp_directory should use the same behavior as DatabaseInstance…
Tishj Mar 11, 2024
9e5d10f
add missing PRAGMA statement, because of a bug the temp directory was…
Tishj Mar 11, 2024
dfc5e70
the tight constraints we set are broken when --force-storage is used,…
Tishj Mar 12, 2024
0eee4f2
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 13, 2024
95df992
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 20, 2024
4848acf
move the setting into the buffer manager + temporary directory handle
Tishj Mar 21, 2024
1708612
get rid of FileSizeMonitor, just pass along the TemporaryFileManager &
Tishj Mar 21, 2024
03fc90e
remove named connection, should be stripped when it gets into the dat…
Tishj Mar 21, 2024
eebc24c
test error when setting a limit that's too low
Tishj Mar 21, 2024
5774dc6
delay the available disk space lookup until we have made sure the dir…
Tishj Mar 23, 2024
fb8315c
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 27, 2024
b82b9c1
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 28, 2024
affb50b
fix merge conflicts
Tishj Mar 28, 2024
80f6b7d
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Mar 30, 2024
815c155
remove dead code, fix tidy issue
Tishj Apr 2, 2024
a8de19b
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Apr 3, 2024
df40291
use INVALID_INDEX-1 to indicate unlimited swap space
Tishj Apr 9, 2024
180e4a2
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Apr 9, 2024
6b8c631
test setting the maximum swap space to unlimited
Tishj Apr 9, 2024
da941a5
Merge remote-tracking branch 'upstream/main' into maximum_swap_space
Tishj Apr 11, 2024
5e4938b
create an assertion out of this, TemporaryDirectoryHandle should neve…
Tishj Apr 12, 2024
c93ab90
handle failing GetAvailableDiskSpace
Tishj Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create the exception, thrown whenever we try to increase the temp dir…
…ectory size beyond the max
  • Loading branch information
Tishj committed Mar 1, 2024
commit 1e441a68212c9fcefce95d2b63d8622e6e9985a5
5 changes: 3 additions & 2 deletions src/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static ConfigurationOption internal_options[] = {DUCKDB_GLOBAL(AccessModeSetting
DUCKDB_LOCAL(IntegerDivisionSetting),
DUCKDB_LOCAL(MaximumExpressionDepthSetting),
DUCKDB_GLOBAL(MaximumMemorySetting),
DUCKDB_GLOBAL(MaximumTempDirectorySize),
DUCKDB_GLOBAL(OldImplicitCasting),
DUCKDB_GLOBAL_ALIAS("memory_limit", MaximumMemorySetting),
DUCKDB_GLOBAL_ALIAS("null_order", DefaultNullOrderSetting),
Expand Down Expand Up @@ -261,9 +262,9 @@ void DBConfig::SetDefaultMaxMemory() {

void DBConfig::SetDefaultMaxSwapSpace() {
auto memory_limit = options.maximum_memory;
if (!TryMultiplyOperator::Operation(memory_limit, 2, options.maximum_memory)) {
if (!TryMultiplyOperator::Operation(memory_limit, static_cast<idx_t>(2), options.maximum_swap_space)) {
// Can't default to 2x memory: fall back to 5GB instead
options.maximum_memory = ParseMemoryLimit("5GB");
options.maximum_swap_space = ParseMemoryLimit("5GB");
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,6 @@ Value MaximumMemorySetting::GetSetting(ClientContext &context) {
//===--------------------------------------------------------------------===//
void MaximumTempDirectorySize::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) {
config.options.maximum_swap_space = DBConfig::ParseMemoryLimit(input.ToString());
if (db) {
BufferManager::GetBufferManager(*db).SetLimit(config.options.maximum_swap_space);
}
}

void MaximumTempDirectorySize::ResetGlobal(DatabaseInstance *db, DBConfig &config) {
Expand Down
15 changes: 14 additions & 1 deletion src/storage/temporary_file_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ TemporaryFileManager::TemporaryFileManager(DatabaseInstance &db, const string &t

TemporaryFileManager::~TemporaryFileManager() {
files.clear();
D_ASSERT(size_on_disk.load() == 0);
}

TemporaryFileManager::TemporaryManagerLock::TemporaryManagerLock(mutex &mutex) : lock(mutex) {
Expand Down Expand Up @@ -308,7 +307,21 @@ idx_t TemporaryFileManager::GetTotalUsedSpaceInBytes() {
}

void TemporaryFileManager::IncreaseSizeOnDisk(idx_t bytes) {
auto &config = DBConfig::GetConfig(db);
auto max_swap_space = config.options.maximum_swap_space;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to be able to adjust this at run-time while the temporary directory is in use? Currently this implementation allows for it - but similarly to the temp directory setting we could also say that this has to be specified prior to creating the temp directory.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to allow this, then we need to read from config.options.maximum_swap_space here at every iteration to make sure it has not changed in the meantime.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also, if we want to allow for this, what do we do if the setting is lowered while the limit is already exceeded?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this as a test using e.g. a temporary table with a low memory limit.


auto current_size_on_disk = size_on_disk.load();
size_on_disk += bytes;
if (size_on_disk.load() > max_swap_space) {
auto used = StringUtil::BytesToHumanReadableString(current_size_on_disk);
auto max = StringUtil::BytesToHumanReadableString(max_swap_space);
auto data_size = StringUtil::BytesToHumanReadableString(bytes);
throw OutOfMemoryException(R"(failed to offload data block of size %s (%s/%s used).
This limit was set by the 'max_temp_directory_size' setting.
This defaults to twice the size of 'max_memory'.
You can adjust this setting, by using (for example) PRAGMA max_temp_directory_size='10GiB')",
data_size, used, max);
}
}

void TemporaryFileManager::DecreaseSizeOnDisk(idx_t bytes) {
Expand Down
Loading