Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144444198
D28219.id82645.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D28219.id82645.diff
View Options
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
@@ -768,20 +768,30 @@
struct malloc_type *mtp, struct domainset *ds, int flags)
{
void *res;
+ size_t asize;
KASSERT(align != 0 && powerof2(align),
("malloc_domainset_aligned: wrong align %#zx size %#zx",
align, size));
- KASSERT(align <= kmemzones[nitems(kmemzones) - 2].kz_size,
+ KASSERT(align <= PAGE_SIZE,
("malloc_domainset_aligned: align %#zx (size %#zx) too large",
align, size));
- if (size < align)
- size = align;
- res = malloc_domainset(size, mtp, ds, flags);
+ /*
+ * Round the allocation size up to the next power of 2,
+ * because we can only guarantee alignment at size for
+ * power-of-2-sized allocations. Increase allocation size to
+ * align if effective size is less than the align, since
+ * malloc zones provide align equal to size.
+ */
+ asize = size == 0 ? align : 1UL << flsl(size - 1);
+ if (asize < align)
+ asize = align;
+
+ res = malloc_domainset(asize, 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));
+ "allocsize %#zx align %#zx", res, size, asize, align));
return (res);
}
@@ -1173,7 +1183,7 @@
align = UMA_ALIGN_PTR;
if (powerof2(size) && size > sizeof(void *))
- align = size - 1;
+ align = MIN(size, PAGE_SIZE) - 1;
for (subzone = 0; subzone < numzones; subzone++) {
kmemzones[indx].kz_zone[subzone] =
uma_zcreate(name, size,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 9, 11:36 AM (1 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28574586
Default Alt Text
D28219.id82645.diff (1 KB)
Attached To
Mode
D28219: Restrict supported alignment for malloc_domainset_aligned(9) to PAGE_SIZE.
Attached
Detach File
Event Timeline
Log In to Comment