Skip to content

Commit 3d10331

Browse files
authored
Introduce a builder to create PagedPool instances (#1833)
Replaces the 3 `new_with_candidate_sizes_` constructors by introducing `PagedPoolConfig`. ### Does this change impact existing behavior? No functional changes. ### 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)](https://developercertificate.org/). --------- Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
1 parent e97ad59 commit 3d10331

24 files changed

Lines changed: 351 additions & 136 deletions

File tree

mountpoint-s3-client/examples/client_benchmark.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ struct CliArgs {
222222
}
223223

224224
fn create_s3_client_config(region: &str, args: &CliArgs, nics: Vec<String>) -> S3ClientConfig {
225-
let pool = PagedPool::new_with_candidate_sizes_unlimited([args.part_size]);
225+
let pool = PagedPool::config()
226+
.with_candidate_sizes([args.part_size])
227+
.with_no_memory_limit()
228+
.build();
226229
let mut config = S3ClientConfig::new()
227230
.endpoint_config(EndpointConfig::new(region))
228231
.throughput_target_gbps(args.throughput_target_gbps)

mountpoint-s3-client/tests/common/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ pub fn set_up_client_config(config: S3ClientConfig) -> S3ClientConfig {
8080

8181
#[cfg(feature = "fs_pool_tests")]
8282
let config = config.memory_pool_factory(|options: mountpoint_s3_client::config::MemoryPoolFactoryOptions| {
83-
mountpoint_s3_fs::memory::PagedPool::new_with_candidate_sizes_unlimited([options.part_size()])
83+
mountpoint_s3_fs::memory::PagedPool::config()
84+
.with_candidate_sizes([options.part_size()])
85+
.with_no_memory_limit()
86+
.build()
8487
});
8588

8689
config

mountpoint-s3-fs/benches/cache_serialization.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ fn cache_read_benchmark(group: &mut BenchmarkGroup<'_, WallTime>, dir_path: &Pat
3939
block_size: BLOCK_SIZE,
4040
limit: mountpoint_s3_fs::data_cache::CacheLimit::Unbounded,
4141
};
42-
let pool = PagedPool::new_with_candidate_sizes_unlimited([BLOCK_SIZE as usize]);
42+
let pool = PagedPool::config()
43+
.with_candidate_sizes([BLOCK_SIZE as usize])
44+
.with_no_memory_limit()
45+
.build();
4346
let cache = DiskDataCache::new(config, pool);
4447
let cache_key = ObjectId::new("a".into(), ETag::for_tests());
4548
let bytes = ChecksummedBytes::new(data.to_owned().into());

mountpoint-s3-fs/examples/fs_benchmark.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ fn mount_file_system(
143143
throughput_target_gbps: Option<f64>,
144144
) -> FuseSession {
145145
let part_size = 8 * 1024 * 1024;
146-
let pool = PagedPool::new_with_candidate_sizes_minimally_limited([part_size]);
146+
let pool = PagedPool::config()
147+
.with_candidate_sizes([part_size])
148+
.with_minimum_memory_limit()
149+
.build();
147150
let mut config = S3ClientConfig::new().endpoint_config(EndpointConfig::new(region));
148151
config = config
149152
.read_backpressure(true)

mountpoint-s3-fs/examples/mount_from_config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ fn mount_filesystem(
310310
let mem_limit = config
311311
.memory_limit_bytes
312312
.unwrap_or(mountpoint_s3_fs::memory::MINIMUM_MEM_LIMIT);
313-
let pool = PagedPool::new_with_candidate_sizes([client_config.part_config.read_size_bytes], mem_limit);
313+
let pool = PagedPool::config()
314+
.with_candidate_sizes([client_config.part_config.read_size_bytes])
315+
.with_memory_limit(mem_limit)
316+
.build();
314317
let client = client_config
315318
.create_client(pool.clone(), None)
316319
.context("Failed to create S3 client")?;

mountpoint-s3-fs/examples/prefetch_benchmark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ fn main() -> anyhow::Result<()> {
167167
let args = CliArgs::parse();
168168

169169
let bucket = args.bucket.as_str();
170-
let pool = PagedPool::new_with_candidate_sizes(
171-
[args.part_size.unwrap_or(8 * 1024 * 1024) as usize],
172-
args.memory_target_in_bytes(),
173-
);
170+
let pool = PagedPool::config()
171+
.with_candidate_sizes([args.part_size.unwrap_or(8 * 1024 * 1024) as usize])
172+
.with_memory_limit(args.memory_target_in_bytes())
173+
.build();
174174
let client_config = args.s3_client_config().memory_pool(pool.clone());
175175
let client = S3CrtClient::new(client_config).context("failed to create S3 CRT client")?;
176176
let runtime = Runtime::new(client.event_loop_group());

mountpoint-s3-fs/examples/s3io_benchmark/executor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ impl Executor {
6565
};
6666

6767
let memory_target_bytes = (max_memory_target * 1024 * 1024) as u64;
68-
let pool = PagedPool::new_with_candidate_sizes([read_part_size, write_part_size], memory_target_bytes);
68+
let pool = PagedPool::config()
69+
.with_candidate_sizes([read_part_size, write_part_size])
70+
.with_memory_limit(memory_target_bytes)
71+
.build();
6972

7073
let mut endpoint_config = EndpointConfig::new(region);
7174
if let Some(url) = &global.endpoint_url {

mountpoint-s3-fs/examples/upload_benchmark.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ fn main() {
102102
// Default to 95% of total system memory (cgroup-aware)
103103
(effective_total_memory() as f64 * 0.95) as u64
104104
};
105-
let pool = PagedPool::new_with_candidate_sizes([args.write_part_size], max_memory_target);
105+
let pool = PagedPool::config()
106+
.with_candidate_sizes([args.write_part_size])
107+
.with_memory_limit(max_memory_target)
108+
.build();
106109
let config = S3ClientConfig::new()
107110
.endpoint_config(endpoint_config)
108111
.throughput_target_gbps(args.throughput_target_gbps as f64)

mountpoint-s3-fs/src/data_cache/disk_data_cache.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,10 @@ mod tests {
687687
#[test]
688688
fn get_path_for_block_key() {
689689
let cache_dir = PathBuf::from("mountpoint-cache/");
690-
let pool = PagedPool::new_with_candidate_sizes_unlimited([1024]);
690+
let pool = PagedPool::config()
691+
.with_candidate_sizes([1024])
692+
.with_no_memory_limit()
693+
.build();
691694
let data_cache = DiskDataCache::new(
692695
DiskDataCacheConfig {
693696
cache_directory: cache_dir,
@@ -719,7 +722,10 @@ mod tests {
719722
#[test]
720723
fn get_path_for_block_key_huge_block_index() {
721724
let cache_dir = PathBuf::from("mountpoint-cache/");
722-
let pool = PagedPool::new_with_candidate_sizes_unlimited([1024]);
725+
let pool = PagedPool::config()
726+
.with_candidate_sizes([1024])
727+
.with_no_memory_limit()
728+
.build();
723729
let data_cache = DiskDataCache::new(
724730
DiskDataCacheConfig {
725731
cache_directory: cache_dir,
@@ -761,7 +767,10 @@ mod tests {
761767
let object_2_size = data_2.len();
762768

763769
let cache_directory = tempfile::tempdir().unwrap();
764-
let pool = PagedPool::new_with_candidate_sizes_unlimited([pool_buffer_size]);
770+
let pool = PagedPool::config()
771+
.with_candidate_sizes([pool_buffer_size])
772+
.with_no_memory_limit()
773+
.build();
765774
let cache = DiskDataCache::new(
766775
DiskDataCacheConfig {
767776
cache_directory: cache_directory.path().to_path_buf(),
@@ -848,7 +857,10 @@ mod tests {
848857
let slice = data.slice(1..5);
849858

850859
let cache_directory = tempfile::tempdir().unwrap();
851-
let pool = PagedPool::new_with_candidate_sizes_unlimited([8 * 1024 * 1024]);
860+
let pool = PagedPool::config()
861+
.with_candidate_sizes([8 * 1024 * 1024])
862+
.with_no_memory_limit()
863+
.build();
852864
let cache = DiskDataCache::new(
853865
DiskDataCacheConfig {
854866
cache_directory: cache_directory.path().to_path_buf(),
@@ -930,7 +942,10 @@ mod tests {
930942
let small_object_key = ObjectId::new("small".into(), ETag::for_tests());
931943

932944
let cache_directory = tempfile::tempdir().unwrap();
933-
let pool = PagedPool::new_with_candidate_sizes_unlimited([BLOCK_SIZE]);
945+
let pool = PagedPool::config()
946+
.with_candidate_sizes([BLOCK_SIZE])
947+
.with_no_memory_limit()
948+
.build();
934949
let cache = DiskDataCache::new(
935950
DiskDataCacheConfig {
936951
cache_directory: cache_directory.path().to_path_buf(),
@@ -1113,7 +1128,10 @@ mod tests {
11131128
// "Corrupt" the serialized value with an invalid length.
11141129
replace_u64_at(&mut buf, offset, u64::MAX);
11151130

1116-
let pool = PagedPool::new_with_candidate_sizes_unlimited([MAX_LENGTH as usize]);
1131+
let pool = PagedPool::config()
1132+
.with_candidate_sizes([MAX_LENGTH as usize])
1133+
.with_no_memory_limit()
1134+
.build();
11171135
let err =
11181136
DiskBlock::read(&mut Cursor::new(buf), MAX_LENGTH, &pool, None).expect_err("deserialization should fail");
11191137
match length_to_corrupt {
@@ -1130,7 +1148,10 @@ mod tests {
11301148
fn test_concurrent_access() {
11311149
let block_size = 1024 * 1024;
11321150
let cache_directory = tempfile::tempdir().unwrap();
1133-
let pool = PagedPool::new_with_candidate_sizes_unlimited([block_size]);
1151+
let pool = PagedPool::config()
1152+
.with_candidate_sizes([block_size])
1153+
.with_no_memory_limit()
1154+
.build();
11341155
let data_cache = DiskDataCache::new(
11351156
DiskDataCacheConfig {
11361157
cache_directory: cache_directory.path().to_path_buf(),

mountpoint-s3-fs/src/data_cache/multilevel_cache.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ mod tests {
131131

132132
fn create_disk_cache() -> (TempDir, Arc<DiskDataCache>) {
133133
let cache_directory = tempfile::tempdir().unwrap();
134-
let pool = PagedPool::new_with_candidate_sizes_unlimited([BLOCK_SIZE as usize, PART_SIZE]);
134+
let pool = PagedPool::config()
135+
.with_candidate_sizes([BLOCK_SIZE as usize, PART_SIZE])
136+
.with_no_memory_limit()
137+
.build();
135138
let cache = DiskDataCache::new(
136139
DiskDataCacheConfig {
137140
cache_directory: cache_directory.path().to_path_buf(),

0 commit comments

Comments
 (0)