Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory usage for strings in inode metadata #1346

Merged
merged 4 commits into from
Apr 3, 2025

Conversation

passaro
Copy link
Contributor

@passaro passaro commented Apr 2, 2025

Reduce memory usage for strings included in inode metadata, like object keys, etags, and inode names. Using a Box<str> instead of a String ensures that no slack capacity is wasted and saves the usize field to keep track of the buffer capacity.

Does this change impact existing behavior?

No functional changes.

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

Yes.


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

passaro added 3 commits April 2, 2025 16:40
Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 2, 2025 17:40 — with GitHub Actions Inactive
Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@passaro passaro temporarily deployed to PR integration tests April 3, 2025 07:22 — with GitHub Actions Inactive
@vladem vladem added the performance PRs to run benchmarks on label Apr 3, 2025
@vladem vladem temporarily deployed to PR benchmarks April 3, 2025 09:21 — with GitHub Actions Inactive
@vladem vladem temporarily deployed to PR benchmarks April 3, 2025 09:21 — with GitHub Actions Inactive
@vladem vladem temporarily deployed to PR benchmarks April 3, 2025 09:21 — with GitHub Actions Inactive
@vladem vladem temporarily deployed to PR benchmarks April 3, 2025 09:21 — with GitHub Actions Inactive
@vladem vladem temporarily deployed to PR benchmarks April 3, 2025 09:21 — with GitHub Actions Inactive
Copy link
Contributor

@vladem vladem left a comment

Choose a reason for hiding this comment

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

a couple of questions and I'd wait for benchmark results, but otherwise LGTM

@@ -344,9 +344,9 @@ impl InodeStat {
/// restored, and so we override their permissions to 000 and reject reads to them. We also warn
/// the first time we see an object like this, because FUSE enforces the 000 permissions on our
/// behalf so we might not see an attempted `open` call.
fn is_readable(storage_class: Option<String>, restore_status: Option<RestoreStatus>) -> bool {
fn is_readable(storage_class: Option<&str>, restore_status: Option<RestoreStatus>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

storage_class is still stored as String right? (don't see it changed to Box<str>)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not store it in the inodes, it's only used here to determine the is_readable flag.

// Allocate the new string with the correct capacity.
let mut key =
String::with_capacity(name_offset + name.len() + if kind == InodeKind::Directory { 1 } else { 0 });
key.push_str(&self.key);
key.push_str(&name);
Copy link
Contributor

Choose a reason for hiding this comment

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

ensures that no slack capacity is wasted

regarding this aspect from the description, do you think slack capacity was added here, when pushing to the string? my assumption would be that initial allocation self.as_ref().to_owned() would use exactly the right amount of memory, so for etag and storage_class the saving is exactly one usize (previously used to track capacity)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the slack capacity savings are only for keys. For etag and the children names we only save the usize field.

@passaro passaro marked this pull request as ready for review April 3, 2025 10:27
@passaro passaro requested a review from vladem April 3, 2025 12:04
@vladem vladem added this pull request to the merge queue Apr 3, 2025
Merged via the queue into awslabs:main with commit 6611aaf Apr 3, 2025
31 checks passed
@passaro passaro deleted the mem/strings branch April 3, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance PRs to run benchmarks on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants