Add Memory Usage Calculation for eStore Data Structure#2
Open
sggeorgiev wants to merge 1 commit intomoticless:redesign-expirefrom
Open
Add Memory Usage Calculation for eStore Data Structure#2sggeorgiev wants to merge 1 commit intomoticless:redesign-expirefrom
sggeorgiev wants to merge 1 commit intomoticless:redesign-expirefrom
Conversation
moticless
pushed a commit
that referenced
this pull request
Mar 12, 2026
…#14845) ## Problem PR redis#14787 introduced **Tcl 9 support for the test suite**, but it still fails on my machine (**macOS 26.3, Tcl 9.0.3**). Some tests fail and the runner may hang. Example: ```bash $ tclsh <<<'puts $tcl_version' 9.0.3 $ make test [err]: BITCOUNT against test vector #2 Expected [r bitcount str] == 4 ``` This is caused by **behavior changes in Tcl 9**, including: - `string length` returning **character count** instead of **byte count** - binary sockets rejecting characters with code points **>255** - differences in `string is wideinteger` Parts of the Redis Tcl test framework rely on **byte-oriented behavior**, which breaks under Tcl 9. ## Changes ### 1. Fix IPC payload encoding in test runner `tests/unit/memefficiency.tcl` contains a **non-ASCII quote character**: https://github.com/redis/redis/blob/fe16003e667407973296ae11b039baa2f9d088c2/tests/unit/memefficiency.tcl#L826 Under Tcl 9 this can corrupt the IPC stream when the test runner serializes Tcl code blocks, causing the runner to hang. Instead of fixing only this character, the IPC payload is now explicitly encoded using: ```tcl encoding convertto utf-8 ``` This makes the protocol robust against future non-ASCII characters. ### 2. Avoid Tcl 9 glob backtracking issue Replaced: ```tcl string match "*[^\u0000-\u00ff]*" $a ``` with: ```tcl regexp {[^\u0000-\u00ff]} $a ``` This avoids a **catastrophic backtracking issue in Tcl 9's glob matcher** while preserving the same behavior. ### 3. Update DIGEST validation The previous check relied on:`string is wideinteger` which behaves differently in Tcl 9. The assertion now validates the **expected DIGEST format directly**.
moticless
pushed a commit
that referenced
this pull request
Mar 31, 2026
redis#14072) Compiled Redis with COVERAGE_TEST, while using the fork API encountered the following issue: - Forked process calls `RedisModule_ExitFromChild` - child process starts to report its COW while performing IO operations - Parent process terminates child process with `RedisModule_KillForkChild` - Child process signal handler gets called while an IO operation is called - exit() is called because COVERAGE_TEST was on during compilation. - exit() tries to perform more IO operations in its exit handlers. - process gets deadlocked Backtrace snippet: ``` #0 futex_wait (private=0, expected=2, futex_word=0x7e1220000c50) at ../sysdeps/nptl/futex-internal.h:146 #1 __GI___lll_lock_wait_private (futex=0x7e1220000c50) at ./nptl/lowlevellock.c:34 #2 0x00007e1234696429 in __GI__IO_flush_all () at ./libio/genops.c:698 #3 0x00007e123469680d in _IO_cleanup () at ./libio/genops.c:843 #4 0x00007e1234647b74 in __run_exit_handlers (status=status@entry=255, listp=<optimized out>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at ./stdlib/exit.c:129 #5 0x00007e1234647bbe in __GI_exit (status=status@entry=255) at ./stdlib/exit.c:138 #6 0x00005ef753264e13 in exitFromChild (retcode=255) at /home/jonathan/CLionProjects/redis/src/server.c:263 redis#7 sigKillChildHandler (sig=<optimized out>) at /home/jonathan/CLionProjects/redis/src/server.c:6794 redis#8 <signal handler called> redis#9 0x00007e1234685b94 in _IO_fgets (buf=buf@entry=0x7e122dafdd90 "KSM:", ' ' <repeats 19 times>, "0 kB\n", n=n@entry=1024, fp=fp@entry=0x7e1220000b70) at ./libio/iofgets.c:47 redis#10 0x00005ef75326c5e0 in fgets (__stream=<optimized out>, __n=<optimized out>, __s=<optimized out>, __s=<optimized out>, __n=<optimized out>, __stream=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/stdio2.h:200 redis#11 zmalloc_get_smap_bytes_by_field (field=0x5ef7534c42fd "Private_Dirty:", pid=<optimized out>) at /home/jonathan/CLionProjects/redis/src/zmalloc.c:928 redis#12 0x00005ef75338ab1f in zmalloc_get_private_dirty (pid=-1) at /home/jonathan/CLionProjects/redis/src/zmalloc.c:978 redis#13 sendChildInfoGeneric (info_type=CHILD_INFO_TYPE_MODULE_COW_SIZE, keys=0, progress=-1, pname=0x5ef7534c95b2 "Module fork") at /home/jonathan/CLionProjects/redis/src/childinfo.c:71 redis#14 0x00005ef75337962c in sendChildCowInfo (pname=0x5ef7534c95b2 "Module fork", info_type=CHILD_INFO_TYPE_MODULE_COW_SIZE) at /home/jonathan/CLionProjects/redis/src/server.c:6895 redis#15 RM_ExitFromChild (retcode=0) at /home/jonathan/CLionProjects/redis/src/module.c:11468 ``` Change is to make the exit() _exit() calls conditional based on a parameter to exitFromChild function. The signal handler should exit without io operations since it doesn't know its history.(If we were in the middle of IO operations before it was called) --------- Co-authored-by: Yuan Wang <wangyuancode@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Introduces comprehensive memory usage tracking for ebuckets and estore data structures to enable better memory profiling and optimization.
Changes
ebMemUsage(): Calculates memory footprint of individual ebuckets instances
estoreMemUsage(): Calculates total memory usage across all buckets in an estore
Key Features
Stack Type: Recursively calculates L1/L2 levels plus L3 vector segments
Rax Type: Accounts for rax structure, nodes, keys, and segment headers
List Type: Returns 0 (items stored inline)
Empty Buckets: Fast-path returns 0
Cluster-aware: Optimized calculation for clustered vs non-clustered modes
Test Coverage
✅ Empty buckets return 0
✅ List-based buckets return 0 (inline storage)
✅ Rax-based buckets with multiple segments
✅ Extended segments with NextSegHdr
✅ Stack-based buckets with L1/L2/L3 levels
Use Cases
Memory profiling and debugging
Resource usage monitoring
Performance optimization analysis