Changeset View
Standalone View
sys/kern/kern_malloc.c
Show First 20 Lines • Show All 762 Lines • ▼ Show 20 Lines | #endif | |||||||||
return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG)); | return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG)); | |||||||||
} | } | |||||||||
void * | void * | |||||||||
malloc_domainset_aligned(size_t size, size_t align, | malloc_domainset_aligned(size_t size, size_t align, | |||||||||
struct malloc_type *mtp, struct domainset *ds, int flags) | struct malloc_type *mtp, struct domainset *ds, int flags) | |||||||||
{ | { | |||||||||
void *res; | void *res; | |||||||||
size_t asize; | ||||||||||
KASSERT(align != 0 && powerof2(align), | KASSERT(align != 0 && powerof2(align), | |||||||||
("malloc_domainset_aligned: wrong align %#zx size %#zx", | ("malloc_domainset_aligned: wrong align %#zx size %#zx", | |||||||||
align, size)); | align, size)); | |||||||||
KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size, | KASSERT(align <= PAGE_SIZE, | |||||||||
("malloc_domainset_aligned: align %#zx (size %#zx) too large", | ("malloc_domainset_aligned: align %#zx (size %#zx) too large", | |||||||||
align, size)); | align, size)); | |||||||||
if (size < align) | if (size < align) | |||||||||
size = align; | asize = align; | |||||||||
markj: This also needs change to `size = roundup2(align)`, I think. | ||||||||||
res = malloc_domainset(size, mtp, ds, flags); | else if (!powerof2(size)) | |||||||||
asize = roundup2(size, align); | ||||||||||
Done Inline ActionsI think that this sentence would be clearer without "at size". alc: I think that this sentence would be clearer without "at size". | ||||||||||
else | ||||||||||
Done Inline Actions
alc: | ||||||||||
asize = size; | ||||||||||
Done Inline Actions
alc: | ||||||||||
res = malloc_domainset(asize, mtp, ds, flags); | ||||||||||
Done Inline ActionsIsn't this going to be slow on architectures without that instruction? What are the actual requirements here? This could at least do with a comment; flsl is a rather obscure function that's non-obvious unless you've seen it before. jrtc27: Isn't this going to be slow on architectures without that instruction? What are the actual… | ||||||||||
Done Inline ActionsA "count leading zeroes" instruction is available on every widely used architecture, including all of the architectures supported by FreeBSD. That said, the last time that I looked at the various cpufunc.h implementations, only 32-bit and 64-bit arm and x86 used the builtins that provide access to these instructions. The objective is to round up to the next power of 2, because we can only guarantee alignment for power-of-2-sized allocations. I agree that a comment to this effect would help. alc: A "count leading zeroes" instruction is available on every widely used architecture, including… | ||||||||||
Done Inline ActionsOk, which then confirms my suspicion that this is wrong: if size is a power of two it doubles the allocation size. https://godbolt.org/z/a6dhEq (using the arm64 implementation since it's a simple one in terms of the builtin). jrtc27: Ok, which then confirms my suspicion that this is wrong: if `size` is a power of two it doubles… | ||||||||||
Done Inline Actions(you want to subtract 1 before passing to flsl, and be careful about 0 - 1 if that's possible) jrtc27: (you want to subtract 1 before passing to `flsl`, and be careful about `0 - 1` if that's… | ||||||||||
Done Inline Actions
alc: | ||||||||||
Done Inline ActionsDrop the first "the" at the beginning of the line and add "their" at the end. alc: Drop the first "the" at the beginning of the line and add "their" at the end. | ||||||||||
KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0, | KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0, | |||||||||
("malloc_domainset_aligned: result not aligned %p size %#zx " | ("malloc_domainset_aligned: result not aligned %p size %#zx " | |||||||||
"align %#zx", res, size, align)); | "allocsize %#zx align %#zx", res, size, asize, align)); | |||||||||
return (res); | return (res); | |||||||||
} | } | |||||||||
Done Inline ActionsIsn't the following one line sufficient? asize = size < align ? align : 1UL << flsl(size - 1); alc: Isn't the following one line sufficient?
```
asize = size < align ? align : 1UL << flsl(size… | ||||||||||
void * | void * | |||||||||
mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags) | mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags) | |||||||||
{ | { | |||||||||
if (WOULD_OVERFLOW(nmemb, size)) | if (WOULD_OVERFLOW(nmemb, size)) | |||||||||
panic("mallocarray: %zu * %zu overflowed", nmemb, size); | panic("mallocarray: %zu * %zu overflowed", nmemb, size); | |||||||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | mallocinit(void *dummy) | |||||||||
for (i = 0, indx = 0; kmemzones[indx].kz_size != 0; indx++) { | for (i = 0, indx = 0; kmemzones[indx].kz_size != 0; indx++) { | |||||||||
int size = kmemzones[indx].kz_size; | int size = kmemzones[indx].kz_size; | |||||||||
const char *name = kmemzones[indx].kz_name; | const char *name = kmemzones[indx].kz_name; | |||||||||
size_t align; | size_t align; | |||||||||
int subzone; | int subzone; | |||||||||
align = UMA_ALIGN_PTR; | align = UMA_ALIGN_PTR; | |||||||||
if (powerof2(size) && size > sizeof(void *)) | if (powerof2(size) && size > sizeof(void *)) | |||||||||
align = size - 1; | align = (size <= PAGE_SIZE ? size : PAGE_SIZE) - 1; | |||||||||
Done Inline ActionsShouldn't we also formally request page alignment for zones with size > PAGE_SIZE? markj: Shouldn't we also formally request page alignment for zones with size > PAGE_SIZE? | ||||||||||
Done Inline ActionsI am not sure that this usage makes much sense, since at least busdma code wouldn't do it. Anyway, I changed it. kib: I am not sure that this usage makes much sense, since at least busdma code wouldn't do it. | ||||||||||
Done Inline ActionsMIN from param.h? jrtc27: `MIN` from param.h? | ||||||||||
Done Inline Actionsbde@ did not liked the macro AFAIR. kib: bde@ did not liked the macro AFAIR. | ||||||||||
Not Done Inline ActionsThat's also my recollection. He preferred the inline functions from libkern.h. alc: That's also my recollection. He preferred the inline functions from libkern.h. | ||||||||||
Done Inline ActionsI believe that an allocation request for 384 bytes with 128 byte alignment will still go to the malloc-384 zone, yes? But, we aren't requiring better than UMA_ALIGN_PTR alignment. alc: I believe that an allocation request for 384 bytes with 128 byte alignment will still go to the… | ||||||||||
for (subzone = 0; subzone < numzones; subzone++) { | for (subzone = 0; subzone < numzones; subzone++) { | |||||||||
kmemzones[indx].kz_zone[subzone] = | kmemzones[indx].kz_zone[subzone] = | |||||||||
uma_zcreate(name, size, | uma_zcreate(name, size, | |||||||||
#ifdef INVARIANTS | #ifdef INVARIANTS | |||||||||
mtrash_ctor, mtrash_dtor, mtrash_init, mtrash_fini, | mtrash_ctor, mtrash_dtor, mtrash_init, mtrash_fini, | |||||||||
#else | #else | |||||||||
NULL, NULL, NULL, NULL, | NULL, NULL, NULL, NULL, | |||||||||
#endif | #endif | |||||||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |
This also needs change to size = roundup2(align), I think.