Repository navigation
feat: 64 分片 uint64_t 位掩码、O(1) 热点 box 缓存与 SWAR 快路径 - #13
Merged
Merged
Conversation
Contributor
|
感谢贡献。当前分支与 冲突文件
请 rebase 到最新 另外两点请一并跟进:
rebase 完成后欢迎再 ping 验证。 |
meta magic 升到 slotsboxobj64v3,和 v2 不兼容。公开 API 不变。 附 18_model_check 和 doc/perf-v3.md。
…eclaim & bugfixes
carsontung666
force-pushed
the
feat/slotsboxobj-v3
branch
from
October 19, 2026 11:13
b2f6272 to
b57221b
Compare
Collaborator
Author
|
感谢合并与发布 |
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.
本 PR 将
slotsboxobj升级至 v3:底层树节点由 v2 的uint8_t[8]逐位扫描重构为 64-aryuint64_tbitmask(配合单段连续clzll/ctzllO(1) 快路径与 6 步无分支 SWAR),并引入最高 64 个独立 shard、per-shard O(1) active box cache(alloc/free直接绕过树下探)以及空子树按需回收机制。相比main(v2),单线程吞吐提升 4.8x–761x(混合负载 20.33 Mops/s),16 线程吞吐提升 136x–331x(混合负载 248.46 Mops/s),并将多线程竞争下的假性分配失败率从 95% 降至 0%。改动概览
64-shard +
uint64_tbitmaskfree_mask/child_mask改为uint64_t(64-ary tree,节点480B,8B 对齐,移除packed)。clzll/ctzllO(1) 快路径;碎片 mask 走 6 步无分支 SWAR 计算sbo_mask_contmax与sbo_mask_find_run。data_size与head_size动态切分1..64(2 的幂)个独立 shard;sbo_alloc先trylock轮询再阻塞加锁,消除多线程竞争下的假 OOM。initial-execTLS 记录线程homeshard(含pid校验防fork冲突、步长 9 错开相邻线程 cache line、连续 4 次 miss 才迁移home防追逐抖动)。Hot-path 优化
sbo_lock_t的 64B cache line padding 存储 L1/L2/L3 的hot_id1与hot_base,sbo_alloc/sbo_free/sbo_allocated_size命中时直接 O(1) 定位目标 box,省去root -> L2 -> L1逐层下探。sbo_box_t中states[64]紧邻 32B header(位于前 1.5 条 cache line);sbo_box_format省去child_cap/children的 384Bmemset(由child_mask门控);sbo_free_obj_slots仅写单字节states[start] = SBO_FREE。sbo_reclaim_empty):常规 churn 保留空叶 box 避免反复分配/释放抖动;当父层满或pool_meta块不足时按需通过blocks_free回收空子树并合并回父 slot。Bug 修复
sbo_find_obj_node:校验level >= 2对象的低位偏移对齐((unit & ((1ULL << sh) - 1)) == 0),修复内部 8B 对齐偏移(如off + 8)误匹配父 slot 导致误 free /sbo_allocated_size返回非 0 的问题。sbo_init:在sbo_magic_ok(meta)前校验head_size <= sizeof(sbo_meta_t) + SBO_POOL_HDR,修复极小 buffer 下的 ASanheap-buffer-overflow。sbo_combined/sbo_propagate:max_obj_cap截断至SBO_MULT_MAX (63),并在comb == p_old时提前终止向上传播,修复空 box 虚报level + 1容量及64 <-> 63传播风暴。sbo_find_alloc:多层下钻前预检pool_meta剩余 block 数并在深层blocks_allocOOM 时回滚已分配的中间 box。tutorial/03_stress.c:DATA_SIZE改为合法的8 * 64^3 (2MB),修复ctest失败。Before / After 性能对比
测试环境:
gcc 13.2 -O3 -DNDEBUG,taskset -c 0-15,DATA_SIZE = 128MB,META_SIZE = 16MB,200k ops/thread,5 次运行取中位数。main)faafafe){8,64,512,4096}B{8,64,512,4096}B{8,64,512,4096}B{8,64,512,4096}B{8..64}B{8..64}B2048live,8B..64KB)2048live,8B..64KB)50kfill)验证
main)faafafe)ctest(make test, 10 项)03_stressfail)03_stressfail)tutorial/test.py(01–17)18_model_check(16T x 100k+ 边界/合并回归)sbo_init越界读sbo_init越界读16T并发压测)kvspace(01/05/06)