Page MenuHomeFreeBSD

LinuxKPI: Add ksize() implementation
ClosedPublic

Authored by wulf on Aug 27 2020, 8:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 7 2024, 6:04 AM
Unknown Object (File)
Feb 15 2024, 6:55 PM
Unknown Object (File)
Feb 14 2024, 11:31 PM
Unknown Object (File)
Jan 31 2024, 5:36 AM
Unknown Object (File)
Jan 28 2024, 8:21 PM
Unknown Object (File)
Jan 10 2024, 12:11 PM
Unknown Object (File)
Dec 22 2023, 10:24 PM
Unknown Object (File)
Dec 21 2023, 3:25 PM
Subscribers

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 - subversion
Lint
Lint Skipped
Unit
Tests Skipped

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
193

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

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

sys/vm/memguard.h
49

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

This revision was automatically updated to reflect the committed changes.