Page MenuHomeFreeBSD

LinuxKPI: implement krealloc() for memory being contiguous
ClosedPublic

Authored by bz on Sat, Mar 29, 6:34 PM.
Tags
None
Referenced Files
F115728049: D49571.id152953.diff
Sun, Apr 27, 6:58 PM
Unknown Object (File)
Sat, Apr 26, 1:10 PM
Unknown Object (File)
Sat, Apr 26, 11:02 AM
Unknown Object (File)
Thu, Apr 17, 2:46 AM
Unknown Object (File)
Mon, Apr 14, 11:01 AM
Unknown Object (File)
Sat, Apr 12, 9:36 PM
Unknown Object (File)
Fri, Apr 11, 10:18 AM
Unknown Object (File)
Mon, Apr 7, 11:23 AM

Details

Summary

Extend malloc_usable_size() for contigmalloc; it seems the only
outside consumer is LinuxKPI ksize() which by itself has little to
no consumer either.

Implement krealloc_array() using krealloc(). Implement krealloc()
doing the various size checks ourselves and use realloc() or kmalloc()
depending on old and new allocation sizes.

This ensures that allocated memory stays physically contiguous.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Suggested by: jhb (see D46657)

Test Plan

Someone please double-check the DEBUG_MEMGUARD/DEBUG_REDZONE
invariants in malloc_usable_size() for contigmalloc!

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested review of this revision.Sat, Mar 29, 6:34 PM

The patch looks fine to me.

There is a typo in the descripton/commit message in "Implement kreallocc()`": the 'c' is duplicated in the function name.

sys/compat/linuxkpi/common/src/linux_slab.c
248 ↗(On Diff #152847)

Isn't it sufficient to check size <= PAGE_SIZE?

I think it'd be nice to add a comment explaining that realloc() doesn't handle contiguous allocations.

The patch looks fine to me.

There is a typo in the descripton/commit message in "Implement kreallocc()`": the 'c' is duplicated in the function name.

Fixed. Thanks.

Add the original ptr == NULL check and just call malloc in that case.
Add a comment about realloc and simplify the size check as suggested by @markj.

bz marked an inline comment as done.Tue, Apr 1, 11:44 AM

Argh, sorry. I'll re-upload the diff in a second.

Let's hope arc diff update Dxxx HEAD^1 works.

jhb added inline comments.
sys/compat/linuxkpi/common/src/linux_slab.c
254 ↗(On Diff #152957)
sys/kern/kern_malloc.c
1145

I would be tempted to commit this separately FWIW, but it's not a big deal. I think of it as more of a fixup to the original commit to merge contigmalloc() into the malloc() API so that free() can be used with both.

This revision is now accepted and ready to land.Tue, Apr 1, 5:30 PM
sys/kern/kern_malloc.c
1145

Yep sounds good to me too.

bz marked 3 inline comments as done.Tue, Apr 1, 9:45 PM
bz added inline comments.
sys/kern/kern_malloc.c
1145

Will do; still feels like ksize() [LinuxKPI] is the only consumer

markj added inline comments.
sys/compat/linuxkpi/common/src/linux_slab.c
256 ↗(On Diff #152957)
bz marked an inline comment as done.Wed, Apr 2, 3:55 PM