Page MenuHomeFreeBSD

LinuxKPI: Add ksize() implementation
ClosedPublic

Authored by wulf on Aug 27 2020, 8:47 PM.

Details

Summary

ksize() gets the actual amount of memory allocated for a given object and is used once in drm-kmod (drivers/dma-buf/reservation.c) to align C99 flexible array size with UMA zone item size.
This patch is borrowed from kern_malloc.c and allows to strip "#ifdef _ _FreeBSD_ _" from aforementioned drm-kmod's file. Quick test shows no positive effect from better array size alignment at least in my setup.

Test Plan

Test allocation sizes with GENERIC kernel config and with DEBUG_MEMGUARD and DEBUG_REDZONE options enabled.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wulf requested review of this revision.Aug 27 2020, 8:47 PM

Looks good to me. Let Konstantin have a say too before it goes in.

This revision is now accepted and ready to land.Aug 27 2020, 9:01 PM

Make sure you have the word LinuxKPI in the commit message.

I suppose this was extracted from realloc(9) ?

I dislike the addition of code that knows so much about internals of malloc(9), into linuxkpi. I suggest to move this function to kern_malloc.c as is and name it e.g. malloc_usable_size(), since this is the usermode name for the same functionality. Then linuxkpi is just a renaming macro.

sys/compat/linuxkpi/common/include/linux/slab.h
188 ↗(On Diff #76294)

Can we drop all that extern from function declarations in linuxkpi ?

wulf retitled this revision from LKPI: Add ksize() implementation to LinuxKPI: Add ksize() implementation.

Move main routine in to kern_malloc.c
Add pair of lines to malloc(9) manpage

This revision now requires review to proceed.Aug 28 2020, 7:14 PM
In D26215#582535, @kib wrote:

I suppose this was extracted from realloc(9) ?

Yes. it was extracted from realloc(9) and free(9)

This revision is now accepted and ready to land.Aug 28 2020, 7:18 PM
kib added inline comments.
sys/sys/malloc.h
251 ↗(On Diff #76319)

Move this line right after malloc_uninit() to keep declarations sorted by name.

sys/vm/memguard.h
49 ↗(On Diff #76319)

Similarly move to after memguard_free, but this is too unordered already.

This revision was automatically updated to reflect the committed changes.