Skip to content

sprandom: Fix several issues found in the sprandom implementation - #1976

Merged
axboe merged 4 commits into
axboe:masterfrom
tomas-winkler-sndk:sprandom-fixes
Sep 4, 2025
Merged

axboe merged 4 commits into
axboe:masterfrom
tomas-winkler-sndk:sprandom-fixes

Conversation

@tomas-winkler-sndk

Copy link
Copy Markdown
Contributor

Fix several issues found in the sprandom implementation, including a memory leak and incorrect eta() computation.

sprandom: drop validity_dist after use
sprandom: add pcb_free() function
sprandom: free invalid_pct buffer
sprandom: fix debug printout for offset
sprandom: setup SPRandom before total_io_size is computed

Move the sprandom_init() call to occur before total_io_size is computed,
in order to ensure correctly compute statitics.

Signed-off-by: Tomas Winkler <tomas.winkler@sandisk.com>
Fix a lefover bug, after code changes. Use 'offset' instead of  *b pointer.

Signed-off-by: Tomas Winkler <tomas.winkler@sandisk.com>
Free invalid_pct, fix a memory leak.

Signed-off-by: Tomas Winkler <tomas.winkler@sandisk.com>
Comment thread pcbuf.h Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's please not add a silly helper that does nothing but call free. The existing code is perfectly readable and you know what it does by looking at it. Conversely, after your change, I'd have to find the function to see exactly what it frees.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see your point about pcb_free() being just a wrapper around free(). My thinking was mainly about API symmetry and code readability. We already have pcb_alloc(), so a natural instinct is to search for a matching pcb_free().
If the consensus is to stick with direct free(cb), I’m fine with that as well.

The validity_dist buffer is only needed to compute the invalid_pct
array. Once that is done, we can free it instead of keeping it
around unnecessarily.

Signed-off-by: Tomas Winkler <tomas.winkler@sandisk.com>
@axboe
axboe merged commit d4b1dce into axboe:master Sep 4, 2025
@vincentkfu

Copy link
Copy Markdown
Collaborator

@tomas-winkler-sndk "sprandom: drop validity_dist after use" frees validity_dist too early because it's used a few lines below to calculate invalid_capacity.

Would you like to add some tests for sprandom to catch issues like these? These could take the form of simple job files like the ones in t/jobs or a Python script like t/*.py. Then the test cases can be added to t/run-fio-tests.py so that they will be run every time the repository is updated.

@tomas-winkler-sndk

Copy link
Copy Markdown
Contributor Author

I've tested and probably moved the lines after. My bad. Strangely -Wuse-after-free doesn't catch it.
Will add a test.

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

⌂ 换网址