[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH 3/3] lib/ukalloc: fix memory wastage in uk_posix_memalign_ifpages



On 06.02.20 18:22, Hugo Lefeuvre wrote:
If align == __PAGE_SIZE, we always allocate two pages more than the
requested size. This is not necessary, because we know that the pointer
returned to the user will always be intptr + page size.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@xxxxxxxxx>
---
  lib/ukalloc/alloc.c | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c
index 2d16057..3afd97f 100644
--- a/lib/ukalloc/alloc.c
+++ b/lib/ukalloc/alloc.c
@@ -252,14 +252,21 @@ int uk_posix_memalign_ifpages(struct uk_alloc *a,
         * preceding the memory block, but instead at the beginning of the page
         * preceding the memory returned by this function.
         *
-        * align < sizeof(*metadata) implies that metadata are too large to be
-        * stored preceding the first memory block at given alignment. In this
-        * case, set align to the next power of two >= sizeof(*metadata). Since
-        * it is a power of two, the returned pointer will still be aligned at
-        * the requested alignment.
+        * align < METADATA_IFPAGES_SIZE_POW2 implies that metadata are too
+        * large to be stored preceding the first memory block at given
+        * alignment. In this case, set align to METADATA_IFPAGES_SIZE_POW2,
+        * the next power of two >= sizeof(*metadata). Since it is a power of
+        * two, the returned pointer will still be aligned at the requested
+        * alignment.
         */
        if (align >= __PAGE_SIZE) {

In order to end up in the your new "else if" case, you should change this condition to (align > __PAGE_SIZE).

                padding = __PAGE_SIZE;
+       } else if (align == __PAGE_SIZE) {
+               /* No padding needed: in this case we already know that the next
+                * aligned pointer will be intptr (as handed to by palloc) +
+                * __PAGE_SIZE.
+                */
+               padding = 0;
        } else if (align < METADATA_IFPAGES_SIZE_POW2) {
                align = METADATA_IFPAGES_SIZE_POW2;
                padding = 0;


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.