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

sysfs: minimize heap allocations of sysfs paths #797

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

calebsander
Copy link
Contributor

11a0918 ("nvme: allow to overwrite base sysfs path") added support for changing the sysfs path via an environment variable. Unfortunately, it added a heap allocation
every time a sysfs path was requested.

Modify the callers to not free the paths, which allows a string constant to be returned if the path isn't overridden, avoiding an allocation. Cache the path in a static variable so that if it is overridden, the heap-allocated string only needs to be constructed once and afterwards can be reused.

Create a file sysfs.c to consolidate this logic
instead of spreading them across 3 files.
Also introduce a helper to factor out the duplicated code.

@calebsander calebsander force-pushed the opt/sysfs-paths branch 2 times, most recently from 6cf4c71 to 5491575 Compare March 19, 2024 20:34
11a0918 ("nvme: allow to overwrite base sysfs path")
added support for changing the sysfs path via an environment variable.
Unfortunately, it added a heap allocation
every time a sysfs path was requested.

Modify the callers to not free the paths, which allows a string constant
to be returned if the path isn't overridden, avoiding an allocation.
Cache the path in a static variable so that if it is overridden,
the heap-allocated string only needs to be constructed once
and afterwards can be reused.

Create a file sysfs.c to consolidate this logic
instead of spreading them across 3 files.
Also introduce a helper to factor out the duplicated code.

Fixes: 11a0918 ("nvme: allow to overwrite base sysfs path")
Signed-off-by: Caleb Sander Mateos <[email protected]>
@igaw igaw merged commit eb4f794 into linux-nvme:master Mar 20, 2024
14 checks passed
@igaw
Copy link
Collaborator

igaw commented Mar 20, 2024

Thanks!

@calebsander calebsander deleted the opt/sysfs-paths branch March 20, 2024 13:06
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