]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: On memory region based allocations, skip small regions
authorSergiu Moga <sergiu@unikraft.io>
Wed, 5 Jun 2024 14:18:40 +0000 (17:18 +0300)
committerUnikraft Bot <monkey@unikraft.io>
Wed, 5 Jun 2024 21:49:12 +0000 (21:49 +0000)
If a free memory region is too small for the current requested
allocation, skip to the next region directly.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Marco Schlumpp <marco@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1449

plat/common/memory.c

index 73f259a7d73243d64a85bf6d128edbd3f55f0ab1..dffbdfd79a69318b8b89a62b78a46b427631907b 100644 (file)
@@ -81,15 +81,17 @@ void *ukplat_memregion_alloc(__sz size, int type, __u16 flags)
                UK_ASSERT_VALID_FREE_MRD(mrd);
                UK_ASSERT(mrd->pbase <= __U64_MAX - size);
 
-               pstart = ALIGN_UP(mrd->pbase, __PAGE_SIZE);
-               pend = pstart + size;
-
                if ((mrd->flags & UKPLAT_MEMRF_PERMS) !=
                            (UKPLAT_MEMRF_READ | UKPLAT_MEMRF_WRITE))
                        return NULL;
 
-               ostart = mrd->pbase;
                olen = mrd->len;
+               if (olen < size)
+                       continue;
+
+               ostart = mrd->pbase;
+               pstart = ALIGN_UP(mrd->pbase, __PAGE_SIZE);
+               pend = pstart + size;
 
                /* If fragmenting this memory region leaves it with length 0,
                 * then simply overwrite and return it instead.