Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 10 additions & 19 deletions src/.clang-format
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 0
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 100
PenaltyExcessCharacter: 100
MaxEmptyLinesToKeep: 2
BreakBeforeBraces: Attach
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignTrailingComments: true
PointerAlignment: Right
KeepEmptyLinesAtTheStartOfBlocks: false
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInSquareBrackets: false
ReflowComments: true
CommentPragmas: '^\\s*\\*'
SortIncludes: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackParameters: false
AlignAfterOpenBracket: Align
BinPackArguments: false
InsertNewlineAtEOF: true
ColumnLimit: 120
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyBreakAssignment: 100
PenaltyBreakOpenParenthesis: 1000
ReflowComments: false
SkipMacroDefinitionBody: true
AllowShortEnumsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
BreakBeforeBinaryOperators: NonAssignment
4 changes: 3 additions & 1 deletion src/.clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ sha1.*
sha256.*
siphash.c
strl.c
trace/trace_*
trace/trace_*
server.h
valkeymodule.h
125 changes: 79 additions & 46 deletions src/acl.c

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/ae.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
#define AE_NONE 0 /* No events registered. */
#define AE_READABLE 1 /* Fire when descriptor is readable. */
#define AE_WRITABLE 2 /* Fire when descriptor is writable. */
#define AE_BARRIER 4 /* With WRITABLE, never fire the event if the \
READABLE event already fired in the same event \
loop iteration. Useful when you want to persist \
things to disk before sending replies, and want \
#define AE_BARRIER 4 /* With WRITABLE, never fire the event if the \
READABLE event already fired in the same event \
loop iteration. Useful when you want to persist \
things to disk before sending replies, and want \
Comment on lines +45 to +48

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change was unexpected. Why did this occur?

to do that in a group fashion. */

#define AE_FILE_EVENTS (1 << 0)
Expand Down
4 changes: 3 additions & 1 deletion src/ae_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) {
aeApiState *state = eventLoop->apidata;
int retval, numevents = 0;

retval = epoll_wait(state->epfd, state->events, eventLoop->setsize,
retval = epoll_wait(state->epfd,
state->events,
eventLoop->setsize,
tvp ? (tvp->tv_sec * 1000 + (tvp->tv_usec + 999) / 1000) : -1);
if (retval > 0) {
int j;
Expand Down
43 changes: 28 additions & 15 deletions src/allocator_defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,11 @@ static inline unsigned jeSize2BinIndexLgQ3(size_t sz) {
unsigned exp = 64 - leading_zeros; // Effective log2(sz)

/* Calculate the size's position within its group */
unsigned within_group_offset = size_class_group_size -
(((1ULL << exp) - sz) >> (exp - lg_quantum_3_first_pow2));
unsigned within_group_offset = size_class_group_size - (((1ULL << exp) - sz) >> (exp - lg_quantum_3_first_pow2));

/* Calculate the final bin index */
return within_group_offset +
((exp - (lg_quantum_3_first_pow2 + 3)) - 1) * size_class_group_size +
lg_quantum_3_offset;
return within_group_offset + ((exp - (lg_quantum_3_first_pow2 + 3)) - 1) * size_class_group_size
+ lg_quantum_3_offset;
}
/* -----------------------------------------------------------------------------
* Interface functions to get fragmentation info from jemalloc
Expand Down Expand Up @@ -222,13 +220,22 @@ static inline int binQueryHelperInitialization(jeBinInfoKeys *helper, unsigned b
char mallctl_name[128];

/* Mib of fetch number of used regions in the bin */
snprintf(mallctl_name, sizeof(mallctl_name), "stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.curregs", bin_index);
snprintf(mallctl_name,
sizeof(mallctl_name),
"stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.curregs",
bin_index);
if (jeQueryKeyInit(mallctl_name, &helper->curr_regs) != 0) return -1;
/* Mib of fetch number of current slabs in the bin */
snprintf(mallctl_name, sizeof(mallctl_name), "stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.curslabs", bin_index);
snprintf(mallctl_name,
sizeof(mallctl_name),
"stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.curslabs",
bin_index);
if (jeQueryKeyInit(mallctl_name, &helper->curr_slabs) != 0) return -1;
/* Mib of fetch nonfull slabs */
snprintf(mallctl_name, sizeof(mallctl_name), "stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.nonfull_slabs", bin_index);
snprintf(mallctl_name,
sizeof(mallctl_name),
"stats.arenas." STRINGIFY(ARENA_TO_QUERY) ".bins.%d.nonfull_slabs",
bin_index);
if (jeQueryKeyInit(mallctl_name, &helper->nonfull_slabs) != 0) return -1;

return 0;
Expand Down Expand Up @@ -366,7 +373,9 @@ static inline int makeDefragDecision(jeBinInfo *bin_info, jemallocBinUsageData *
if (1000 * nalloced < bin_info->nregs * UTILIZATION_THRESHOLD_FACTOR_MILLI) return 1;

/* Don't defrag if the slab usage is greater than the average usage (+ 12.5%) */
if (1000 * nalloced * bin_usage->curr_nonfull_slabs > (1000 + UTILIZATION_THRESHOLD_FACTOR_MILLI) * allocated_nonfull) return 0;
if (1000 * nalloced * bin_usage->curr_nonfull_slabs
> (1000 + UTILIZATION_THRESHOLD_FACTOR_MILLI) * allocated_nonfull)
return 0;

/* Otherwise, defrag! */
return 1;
Expand All @@ -387,10 +396,7 @@ int allocatorShouldDefrag(void *ptr) {
for (unsigned j = 0; j < BATCH_QUERY_ARGS_OUT; j++) {
out[j] = -1;
}
je_mallctlbymib(je_cb.util_batch_query.key,
je_cb.util_batch_query.keylen,
out, &out_sz,
&ptr, in_sz);
je_mallctlbymib(je_cb.util_batch_query.key, je_cb.util_batch_query.keylen, out, &out_sz, &ptr, in_sz);
/* handle results with appropriate quantum value */
assert(SLAB_NUM_REGS(out, 0) > 0);
assert(SLAB_LEN(out, 0) > 0);
Expand Down Expand Up @@ -428,8 +434,15 @@ float getAllocatorFragmentation(size_t *out_frag_bytes) {
float rss_pct = ((float)resident / allocated) * 100 - 100;
size_t rss_bytes = resident - allocated;
if (out_frag_bytes) *out_frag_bytes = frag_smallbins_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);
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;
}

Expand Down
9 changes: 4 additions & 5 deletions src/allocator_defrag.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include <jemalloc/jemalloc.h>
/* We can enable the server defrag capabilities only if we are using Jemalloc
* and the version that has the experimental.utilization namespace in mallctl . */
#if (defined(VALKEY_VENDORED_JEMALLOC) && defined(JEMALLOC_VERSION_MAJOR) && \
(JEMALLOC_VERSION_MAJOR > 5 || \
(JEMALLOC_VERSION_MAJOR == 5 && JEMALLOC_VERSION_MINOR > 2) || \
(JEMALLOC_VERSION_MAJOR == 5 && JEMALLOC_VERSION_MINOR == 2 && JEMALLOC_VERSION_BUGFIX >= 1))) || \
defined(DEBUG_FORCE_DEFRAG)
#if (defined(VALKEY_VENDORED_JEMALLOC) && defined(JEMALLOC_VERSION_MAJOR) \
&& (JEMALLOC_VERSION_MAJOR > 5 || (JEMALLOC_VERSION_MAJOR == 5 && JEMALLOC_VERSION_MINOR > 2) \
|| (JEMALLOC_VERSION_MAJOR == 5 && JEMALLOC_VERSION_MINOR == 2 && JEMALLOC_VERSION_BUGFIX >= 1))) \
|| defined(DEBUG_FORCE_DEFRAG)
#define HAVE_DEFRAG
#endif
#endif
Expand Down
12 changes: 5 additions & 7 deletions src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ int anetKeepAlive(char *err, int fd, int interval) {
* we want the compiler to emit warnings of unused variables if the preprocessor directives
* somehow fail, and other than those platforms, just omit these warnings if they happen.
*/
#if !(defined(_AIX) || defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__illumos__) || \
defined(__linux__) || defined(__NetBSD__) || defined(__sun))
#if !(defined(_AIX) || defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__illumos__) \
|| defined(__linux__) || defined(__NetBSD__) || defined(__sun))
UNUSED(interval);
UNUSED(idle);
UNUSED(intvl);
Expand Down Expand Up @@ -666,8 +666,7 @@ int anetRetryAcceptOnError(int err) {
* the server receives and queues it in the pending connections queue (the SYN queue),
* but before accept() is called, the connection is aborted.
* in such cases we can continue accepting other connections. ß*/
if (err == ECONNABORTED)
return 1;
if (err == ECONNABORTED) return 1;

#if defined(__linux__)
/* https://www.man7.org/linux/man-pages/man2/accept4.2 suggests that:
Expand All @@ -679,9 +678,8 @@ int anetRetryAcceptOnError(int err) {
EAGAIN by retrying. In the case of TCP/IP, these are ENETDOWN,
EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP,
and ENETUNREACH. */
if (err == ENETDOWN || err == EPROTO || err == ENOPROTOOPT ||
err == EHOSTDOWN || err == ENONET || err == EHOSTUNREACH ||
err == EOPNOTSUPP || err == ENETUNREACH) {
if (err == ENETDOWN || err == EPROTO || err == ENOPROTOOPT || err == EHOSTDOWN || err == ENONET
|| err == EHOSTUNREACH || err == EOPNOTSUPP || err == ENETUNREACH) {
return 1;
}
#endif
Expand Down
Loading
Loading