-
Notifications
You must be signed in to change notification settings - Fork 652
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
Introduce FORCE_DEFRAG compilation option to allow activedefrag run when allocator is not jemalloc #1303
base: unstable
Are you sure you want to change the base?
Introduce FORCE_DEFRAG compilation option to allow activedefrag run when allocator is not jemalloc #1303
Changes from all commits
5044dfc
c62beb2
31a04dc
a42e565
1f26c5d
f36ee08
27f4290
c1862eb
4643d97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ if (VALKEY_RELEASE_BUILD) | |
set_property(TARGET valkey-server PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) | ||
endif () | ||
|
||
if (FORCE_DEFRAG) | ||
message(STATUS "Forcing Active Defrag run on valkey-server") | ||
target_compile_definitions(valkey-server PRIVATE FORCE_DEFRAG) | ||
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer a slightly more verbose and descriptive name, like, "DEBUG_FORCE_DEFRAG" or something, to indicate this isn't really used for production. |
||
target_compile_definitions(valkey-server PRIVATE HAVE_DEFRAG) | ||
endif () | ||
|
||
# Target: valkey-cli | ||
list(APPEND CLI_LIBS "linenoise") | ||
valkey_build_and_install_bin(valkey-cli "${VALKEY_CLI_SRCS}" "${VALKEY_SERVER_LDFLAGS}" "${CLI_LIBS}" "redis-cli") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,6 +755,15 @@ void defragScanCallback(void *privdata, const dictEntry *de) { | |
* or not, a false detection can cause the defragmenter to waste a lot of CPU | ||
* without the possibility of getting any results. */ | ||
float getAllocatorFragmentation(size_t *out_frag_bytes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of feels like you should override computeDefragCycles instead, and have that should always set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with it (makes sense) I do not, however want to break tests which are checking the active_defrag_running, so maybe I can just use the active-defrag-cycle-max as the return value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This intuitively makes a bit more sense to me, since defrag shouldn't really work correctly since we are completely breaking defrag here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the tests already are checking for jemalloc memory to enable the defragmentation, so I think that the tests should all still be skipped anyways? |
||
/* In case we are forcing defrag to run without Jemalloc support we cannot get any | ||
* good statistics from the allocator regarding external fragmentation. | ||
* This is why we are forcing the report to reflect fragmented system conditions based on the existing configurations. */ | ||
#if defined(FORCE_DEFRAG) || !defined(USE_JEMALLOC) | ||
|
||
*out_frag_bytes = server.active_defrag_ignore_bytes + 1; | ||
return server.active_defrag_threshold_upper; | ||
#else | ||
|
||
size_t resident, active, allocated, frag_smallbins_bytes; | ||
zmalloc_get_allocator_info(&allocated, &active, &resident, NULL, NULL, &frag_smallbins_bytes); | ||
|
||
|
@@ -769,6 +778,7 @@ float getAllocatorFragmentation(size_t *out_frag_bytes) { | |
serverLog(LL_DEBUG, "allocated=%zu, active=%zu, resident=%zu, frag=%.2f%% (%.2f%% rss), frag_bytes=%zu (%zu rss)", | ||
allocated, active, resident, frag_pct, rss_pct, frag_smallbins_bytes, rss_bytes); | ||
return frag_pct; | ||
#endif | ||
} | ||
|
||
/* Defrag scan callback for the pubsub dictionary. */ | ||
|
@@ -956,7 +966,7 @@ void activeDefragCycle(void) { | |
mstime_t latency; | ||
int all_stages_finished = 0; | ||
int quit = 0; | ||
|
||
#if !defined(FORCE_DEFRAG) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still kind of think you should have to turn defrag on. I'm okay with overriding it so it always runs if you do, but it it's sort of counter intuitive to comment out this block of code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial thought as well but I went all the way :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm okay with this, it makes sense to me. |
||
if (!server.active_defrag_enabled) { | ||
if (server.active_defrag_running) { | ||
/* if active defrag was disabled mid-run, start from fresh next time. */ | ||
|
@@ -975,7 +985,10 @@ void activeDefragCycle(void) { | |
} | ||
return; | ||
} | ||
|
||
#else | ||
/* Avoid compiler warning */ | ||
if (0) goto update_metrics; | ||
#endif | ||
if (hasActiveChildProcess()) return; /* Defragging memory while there's a fork will just do damage. */ | ||
|
||
/* Once a second, check if the fragmentation justfies starting a scan | ||
|
@@ -1134,6 +1147,13 @@ void activeDefragCycle(void) { | |
} | ||
} | ||
|
||
#if defined(FORCE_DEFRAG) || !defined(JEMALLOC_FRAG_HINT) | ||
int je_get_defrag_hint(void *ptr) { | ||
UNUSED(ptr); | ||
return 1; | ||
} | ||
#endif | ||
|
||
#else /* HAVE_DEFRAG */ | ||
|
||
void activeDefragCycle(void) { | ||
|
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.
We should add this to some CI presumably. The daily ASAN probably?
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.
Yes I agree. maybe it can also be run as part of the CI, depending on the extra time it would take.