Skip to content

server: defrag 2#7254

Draft
abhijat wants to merge 27 commits intomainfrom
abhijat/hack/defrag-2
Draft

server: defrag 2#7254
abhijat wants to merge 27 commits intomainfrom
abhijat/hack/defrag-2

Conversation

@abhijat
Copy link
Copy Markdown
Contributor

@abhijat abhijat commented May 3, 2026

No description provided.

@abhijat abhijat force-pushed the abhijat/hack/defrag-2 branch 25 times, most recently from 0183083 to 05d88dc Compare May 4, 2026 16:19
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
@abhijat abhijat force-pushed the abhijat/hack/defrag-2 branch from 05d88dc to f326f23 Compare May 4, 2026 20:27
abhijat added 3 commits May 5, 2026 02:47
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
abhijat added 5 commits May 5, 2026 04:20
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
abhijat added 4 commits May 6, 2026 14:59
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
@abhijat abhijat force-pushed the abhijat/hack/defrag-2 branch from a7f5a82 to 3bce4c0 Compare May 6, 2026 16:07
@abhijat
Copy link
Copy Markdown
Contributor Author

abhijat commented May 7, 2026

afl error is from build failure, not fuzzer

https://github.com/dragonflydb/dragonfly/actions/runs/25446794970/job/74652993045

abhijat added 2 commits May 7, 2026 12:51
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
@abhijat abhijat force-pushed the abhijat/hack/defrag-2 branch from 3bce4c0 to 76db21e Compare May 7, 2026 07:21
abhijat added 2 commits May 7, 2026 12:59
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
@abhijat

This comment was marked as resolved.

abhijat and others added 10 commits May 7, 2026 14:41
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Introduce two experiment scripts for measuring and comparing
defrag algorithm performance:

- defrag_run.sh: end-to-end single experiment driver.
  Starts a CPU-pinned single-shard Dragonfly, creates heap
  fragmentation via defrag_baseline.py, then iterates
  MEMORY DEFRAGMENT until arena waste falls below a target
  or a cycle cap is reached. Results written as JSONL.
  Accepts phased|legacy mode and exposes all key params as
  CLI flags (-m, -c, -w, -p, -t, -s, -o, -b) with env-var
  fallback.

- defrag_sweep.sh: batch sweep over MUL × mode combinations.
  Calls defrag_run.sh for every combination, captures per-run
  stdout to .log and JSONL files under runs/sweep/. MUL series,
  cycle count, mode subset, and output dir are all configurable
  via flags or env vars. Extra flags can be forwarded to
  defrag_run.sh after --.

Signed-off-by: Gil Levkovich <69595609+glevkovich@users.noreply.github.com>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
ClassifyForTarget() decides whether a census page is a defrag
target. It covered three cases (no observed blocks, already
empty, stale observation) but fell through to kKeep when
observed_movable_blocks < used_blocks, i.e. when mimalloc
reports more live blocks than the census ever saw as movable.

Those extra blocks are immovable (internal metadata, objects
arriving after the census walk). Selecting such a page as a
target causes EVACUATE to spin trying to drain blocks it can
never move.

Add the missing branch to return kHasImmovableData, making
kKeep reachable only when observed == used (all live blocks
were observed as movable).

Fixes TargetPlanTest.AppliesFilterClassification.

Signed-off-by: Gil Levkovich <69595609+glevkovich@users.noreply.github.com>
The phased defragmenter (CENSUS + EVACUATE) can now optionally
defrag key allocations (it->first) in addition to values,
controlled by --defrag_keys (default: false).

- Add ShouldDefragKeys() virtual to PageUsage; CensusTaker and
  Evacuator override it to read the flag
- Wire key defrag into RunPrimeTableSlice and RunPrimeTableHinted,
  guarded by defrag_keys in both paths
- Track per-key/value reallocation counts and bytes moved in
  DbSliceResult, DefragCycleStats, and EVACUATE log lines
- Add KeyDefragIntegrity test: verifies no corruption and that
  key/value realloc stats are non-zero after defrag
- Add -- passthrough support to defrag_run.sh for forwarding
  extra flags to the dragonfly binary

The flag defaults to false. Benchmarks at MUL=15 show key defrag
hurts throughput for short-key/large-value workloads: key moves
consume quota without emptying pages. Enable for workloads where
keys are a significant fraction of object memory (long metric
names, search indexes, time-series).

Signed-off-by: Gil Levkovich <69595609+glevkovich@users.noreply.github.com>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Signed-off-by: Abhijat Malviya <abhijat@dragonflydb.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants