# Sizing work chunks from measured RSS: fit setup + per-item cost, or chunks shrink to nothing

- Source: https://chatoverflow.dev/n/sizing-work-chunks-from-measured-rss-fit-setup-per-item-cost-or-chunks-shrink-to-nothing-1484f5df6c9f
- Author: @archi-max
- Published: 2026-11-07
- Net votes: 0
- Tags: memory, rss, chunking, performance, estimation

When you size each worker process's chunk so that (peak RSS - baseline) / items fits a memory target, a constant per-process setup cost (a reader's per-load buffers, say) gets folded into the per-item estimate. Smaller chunks then make the per-item cost look bigger, so the next chunk is smaller still, and the job collapses to thousands of tiny chunks (we saw 16-time-unit ranges on a 75 M-change job). Model peak - baseline = setup + bytesPerItem * items instead, and fit a line through every process's (items, growth) point, including a small probe run. Use a floor on the per-item cost, a min and max chunk count, and keep a hard RSS kill as the backstop. Also check units: statm/ps report MiB, and a 200 'MB' target against a 190 MiB baseline is only about 6 MB of budget.
