Page MenuHomeFreeBSD

D28147.diff
No OneTemporary

D28147.diff

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -763,6 +763,28 @@
return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG));
}
+void *
+malloc_domainset_aligned(size_t size, size_t align,
+ struct malloc_type *mtp, struct domainset *ds, int flags)
+{
+ void *res;
+
+ KASSERT(align != 0 && powerof2(align),
+ ("malloc_domainset_aligned: wrong align %#zx size %#zx",
+ align, size));
+ KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size,
+ ("malloc_domainset_aligned: align %#zx (size %#zx) too large",
+ align, size));
+
+ if (size < align)
+ size = align;
+ res = malloc_domainset(size, mtp, ds, flags);
+ KASSERT(res == NULL || ((uintptr_t)res & (align - 1)) == 0,
+ ("malloc_domainset_aligned: result not aligned %p size %#zx "
+ "align %#zx", res, size, align));
+ return (res);
+}
+
void *
mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags)
{
@@ -1146,8 +1168,12 @@
for (i = 0, indx = 0; kmemzones[indx].kz_size != 0; indx++) {
int size = kmemzones[indx].kz_size;
const char *name = kmemzones[indx].kz_name;
+ size_t align;
int subzone;
+ align = UMA_ALIGN_PTR;
+ if (powerof2(size) && size > sizeof(void *))
+ align = size - 1;
for (subzone = 0; subzone < numzones; subzone++) {
kmemzones[indx].kz_zone[subzone] =
uma_zcreate(name, size,
@@ -1156,7 +1182,7 @@
#else
NULL, NULL, NULL, NULL,
#endif
- UMA_ALIGN_PTR, UMA_ZONE_MALLOC);
+ align, UMA_ZONE_MALLOC);
}
for (;i <= size; i+= KMEM_ZBASE)
kmemsize[i >> KMEM_ZSHIFT] = indx;
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -261,6 +261,9 @@
__result_use_check __alloc_size(2);
void *reallocf(void *addr, size_t size, struct malloc_type *type, int flags)
__result_use_check __alloc_size(2);
+void *malloc_domainset_aligned(size_t size, size_t align,
+ struct malloc_type *mtp, struct domainset *ds, int flags)
+ __malloc_like __result_use_check __alloc_size(1);
struct malloc_type *malloc_desc2type(const char *desc);

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 16, 6:16 AM (19 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15821138
Default Alt Text
D28147.diff (2 KB)

Event Timeline