Page MenuHomeFreeBSD

malloc: add a routine to find out usable size without allocating
ClosedPublic

Authored by mjg on Nov 5 2020, 4:14 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 22 2024, 6:45 PM
Unknown Object (File)
Jan 10 2024, 3:36 AM
Unknown Object (File)
Dec 3 2023, 3:40 PM
Unknown Object (File)
Aug 20 2023, 8:21 PM
Unknown Object (File)
Jul 2 2023, 7:01 AM
Unknown Object (File)
May 9 2023, 12:36 AM
Subscribers

Details

Summary

ZFS creates several zones, some of which unnecessarily duplicate zones provided by malloc.

The suggested routine can be used to avoid the problem. Sample user would be abd_chunk cache which defaults to 4096 but can be tuned in loader.conf

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mjg requested review of this revision.Nov 5 2020, 4:14 AM
sys/kern/kern_malloc.c
1037 ↗(On Diff #79195)

To me the name suggests that the return type should be uma_zone_t.

1042 ↗(On Diff #79195)

The return type is (unsigned) size_t.

sys/kern/kern_malloc.c
1037 ↗(On Diff #79195)

I don't care for the name, just suggest another one and I'll use it.

1042 ↗(On Diff #79195)

Callers can check for -1 regardless. Alternatively, I can return errnos here and the actual size in a different argument, like so: error = func(size, &malloc_size);

sys/kern/kern_malloc.c
1034 ↗(On Diff #79195)

"returns the number of bytes allocated for a request of the specified size"

1037 ↗(On Diff #79195)

malloc_size() is my suggestion.

1042 ↗(On Diff #79195)

Code analysis tools will raise warnings. Why not just return 0?

mjg marked 5 inline comments as done.
markj added inline comments.
sys/kern/kern_malloc.c
1044 ↗(On Diff #79219)

No need for braces, or at least make it consistent with the if statement immediately following.

This revision is now accepted and ready to land.Nov 5 2020, 3:30 PM