Skip to content

Refactor MemoryLimiter into PagedPool#1826

Merged
renanmagagnin merged 9 commits into
awslabs:feature/memory-limitfrom
renanmagagnin:refactor-memory-pool-and-limiter
May 13, 2026
Merged

Refactor MemoryLimiter into PagedPool#1826
renanmagagnin merged 9 commits into
awslabs:feature/memory-limitfrom
renanmagagnin:refactor-memory-pool-and-limiter

Conversation

@renanmagagnin
Copy link
Copy Markdown
Contributor

@renanmagagnin renanmagagnin commented May 7, 2026

Moves MemoryLimiter inside PagedPool to improve the ownership model.

Before: MemoryLimiter owned a PagedPool field to read pool stats, while PagedPool called back into MemoryLimiter via a closure to decrement reservations on buffer allocation. Consumers (prefetcher, uploader, filesystem) had to pass both pool and Arc separately.

After: PagedPool owns the MemoryLimiter internally and calls it directly on buffer allocation — no callback needed. Consumers only need a PagedPool and call pool.reserve(), pool.try_reserve(), pool.available_mem(), etc. directly.

Key changes:

  • MemoryLimiter moved from mem_limiter.rs to memory/limiter.rs
  • PagedPool::new_with_candidate_sizes now takes a required mem_limit: u64 parameter
  • Added PagedPool::new_with_candidate_sizes_unlimited() convenience constructor for tests/examples that don't need memory budgeting
  • Uploader::new() no longer takes a mem_limiter parameter
  • PrefetcherBuilder::build() takes PagedPool instead of Arc
  • Removed mem_limit from S3FilesystemConfig; pool construction moved to run.rs

Next steps

  • Rebase and resolve conflicts
  • Consider renaming the mem_limiter feature flag
  • Consider removing callback
  • Consider second pool convenience constructor with minimum memory limit

Does this change impact existing behavior?

No. This is a pure refactor — no behavioral changes. The same memory limiting logic runs, the same budget checks apply, the same callbacks fire. Only the ownership structure and call sites changed.

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

No. Internal refactor only — no public API changes, no user-facing behavior changes, no CLI changes.


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).

Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
@renanmagagnin renanmagagnin requested a deployment to PR integration tests May 7, 2026 18:22 — with GitHub Actions Waiting
@renanmagagnin renanmagagnin self-assigned this May 7, 2026
Comment thread mountpoint-s3-fs/examples/fs_benchmark.rs Outdated
Comment thread mountpoint-s3-fs/examples/fs_benchmark.rs
Comment thread mountpoint-s3-fs/examples/mount_from_config.rs Outdated
Comment thread mountpoint-s3-fs/src/memory/limiter.rs Outdated
Comment thread mountpoint-s3-fs/src/memory/limiter.rs Outdated
Comment thread mountpoint-s3-fs/src/memory/limiter.rs
Comment thread mountpoint-s3-fs/src/memory/pool.rs Outdated
Comment thread mountpoint-s3-fs/src/upload/incremental.rs Outdated
Comment thread mountpoint-s3-fs/tests/fs.rs Outdated
Comment thread mountpoint-s3/src/cli.rs Outdated
…limits are unchanged

Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
@renanmagagnin renanmagagnin requested a deployment to PR integration tests May 12, 2026 22:46 — with GitHub Actions Waiting
…iter

Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
@renanmagagnin renanmagagnin requested a deployment to PR integration tests May 13, 2026 12:53 — with GitHub Actions Waiting
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
@renanmagagnin renanmagagnin requested a deployment to PR integration tests May 13, 2026 13:25 — with GitHub Actions Waiting
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
@renanmagagnin renanmagagnin temporarily deployed to PR integration tests May 13, 2026 14:35 — with GitHub Actions Inactive
@renanmagagnin renanmagagnin marked this pull request as ready for review May 13, 2026 14:35
@renanmagagnin renanmagagnin requested a review from passaro May 13, 2026 14:35
Signed-off-by: Renan Magagnin <renanmag@amazon.co.uk>
Copy link
Copy Markdown
Contributor

@passaro passaro left a comment

Choose a reason for hiding this comment

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

Looks good. A few minor nits, but nothing really blocking.

Comment thread mountpoint-s3-fs/examples/s3io_benchmark/executor.rs
Comment on lines +12 to +14
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::time::Instant;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Revert std on top.

Comment on lines +248 to 251
fn pool_mem_reserved(&self, stats: &PoolStats) -> u64 {
// All pool buffer kinds are accounted for here.
self.pool.total_reserved_bytes() as u64
stats.total_reserved_bytes() as u64
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems redundant

}

/// Create a pool with [MINIMUM_MEM_LIMIT] as the memory limit.
pub fn new_with_candidate_sizes_minimally_limited(buffer_sizes: impl Into<Vec<usize>>) -> Self {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should consider a config/builder pattern instead of multiple constructors (for a later change).

pub(crate) fn inner_limiter(&self) -> &MemoryLimiter {
&self.inner.limiter
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's rethink some of the tests that need these methods (for later).

Comment on lines +7 to +8
use crate::memory::BufferArea;
use crate::memory::PagedPool;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
use crate::memory::BufferArea;
use crate::memory::PagedPool;
use crate::memory::{BufferArea, PagedPool};

Comment on lines +1 to 6
use crate::data_cache::DataCache;

use mountpoint_s3_client::ObjectClient;

use crate::{Runtime, mem_limiter::MemoryLimiter};
use crate::{Runtime, memory::PagedPool};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: reorder uses

@renanmagagnin renanmagagnin temporarily deployed to PR integration tests May 13, 2026 16:19 — with GitHub Actions Inactive
@passaro passaro self-requested a review May 13, 2026 16:24
Copy link
Copy Markdown
Contributor

@passaro passaro left a comment

Choose a reason for hiding this comment

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

Merge it. We can address the remaining comments in a follow up.

@renanmagagnin renanmagagnin merged commit e9fa52a into awslabs:feature/memory-limit May 13, 2026
49 checks passed
@renanmagagnin renanmagagnin deleted the refactor-memory-pool-and-limiter branch May 13, 2026 18:33
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