Skip to content

Introduce CursorState to consolidate per-cursor memory tracking#1832

Merged
renanmagagnin merged 1 commit into
awslabs:feature/memory-limitfrom
passaro:mem/cursor-state
May 15, 2026
Merged

Introduce CursorState to consolidate per-cursor memory tracking#1832
renanmagagnin merged 1 commit into
awslabs:feature/memory-limitfrom
passaro:mem/cursor-state

Conversation

@passaro
Copy link
Copy Markdown
Contributor

@passaro passaro commented May 14, 2026

Consolidates per-cursor state in the memory limiter into a single CursorState struct, eliminating hot-path lookups from the backpressure controller and cursor read path.

Previously, per-cursor data was split across two maps in MemoryLimiter: one for reservation balances and one for active FUSE read ranges. Every reserve, try_reserve, set_active_read, and clear_active_read call performed an independent lookup on the hot path. This change introduces CursorState, a shared struct holding both the reservation counter and active read state, and a CursorHandle wrapper for setting active reads. The BackpressureController and Cursor directly hold a reference to CursorState, so reservation and active-read operations no longer require any lookup. The map is now only accessed on cursor creation, release, and in the on_pool_reserve callback (same as before, but unified into a single map).

Does this change impact existing behavior?

No behavioral changes. Existing unit tests adapted to the new API.

Does this change need a changelog entry? Does it require a version change?

No.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the Developer Certificate of Origin (DCO).

Consolidates per-cursor state in the memory limiter into a single CursorState struct, eliminating hot-path DashMap lookups from the backpressure controller and cursor read path.
Previously, per-cursor data was split across two DashMaps in MemoryLimiter: one for reservation balances (mem_reserved_per_cursor) and one for active FUSE read ranges (active_reads). Every reserve, try_reserve, set_active_read, and clear_active_read call performed an independent DashMap lookup on the hot path. This change introduces CursorState, a shared struct holding both the reservation counter and active read state, and a CursorHandle wrapper for setting active reads. The BackpressureController and Cursor hold a direct Arc<CursorState>, so reservation and active-read operations no longer require any DashMap lookup. The DashMap is now only accessed on cursor creation, release, and in the on_pool_reserve callback (same as before, but unified into a single map).

No behavioral changes. Existing unit tests adapted to the new API.

Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
@passaro passaro temporarily deployed to PR integration tests May 14, 2026 17:08 — with GitHub Actions Inactive
@passaro passaro marked this pull request as ready for review May 15, 2026 11:07
Copy link
Copy Markdown
Contributor

@yerzhan7 yerzhan7 left a comment

Choose a reason for hiding this comment

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

Nice refactor! LGTM

Copy link
Copy Markdown
Contributor

@renanmagagnin renanmagagnin left a comment

Choose a reason for hiding this comment

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

LGTM

@renanmagagnin renanmagagnin merged commit e97ad59 into awslabs:feature/memory-limit May 15, 2026
49 checks passed
yerzhan7 added a commit to yerzhan7/mountpoint-s3 that referenced this pull request May 15, 2026
Pulls in awslabs#1832 (CursorState consolidation). The conflict in
mountpoint-s3-fs/src/memory/pool.rs was in the delegation block: upstream
removed reserve/try_reserve/release_cursor/next_cursor_id/inner_stats/
inner_limiter in favor of a unified `create_cursor`, while this branch had
added `mem_limit`/`data_buffer_budget` accessors used by `WriteHandleLimiter`.
Resolved by keeping both — upstream's `create_cursor` plus our two
accessors — and dropped the now-unused test-only `inner_stats`/`inner_limiter`
helpers along with their TODO.

Signed-off-by: Yerzhan Mazhkenov <20302932+yerzhan7@users.noreply.github.com>
@passaro passaro deleted the mem/cursor-state branch May 18, 2026 10:47
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.

3 participants