Skip to contentSkip to conversation

xl: move freemem()'s "credit expired" loop exit

PATCH In review Jan Beulich 2 participants 2 messages Jul 12, 2022 – Jul 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: move freemem()'s "credit expired" loop exit

Move the "credit expired" loop exit to the middle of the loop, immediately after "return true". This way having reached the goal on the last iteration would be reported as success to the caller, rather than as "timed out".

tools/xl/xl_vmcontrol.c +5 -4
@@ -332,7 +332,7 @@ static bool freemem(uint32_t domid, libx
     if (rc < 0)
         return false;
 
-    do {
+    for (;;) {
         time_t start;
 
         rc = libxl_get_free_memory(ctx, &free_memkb);
@@ -342,6 +342,9 @@ static bool freemem(uint32_t domid, libx
         if (free_memkb >= need_memkb)
             return true;
 
+        if (credit <= 0)
+            return false;
+
         rc = libxl_set_memory_target(ctx, 0, free_memkb - need_memkb, 1, 0);
         if (rc < 0)
             return false;
@@ -354,9 +357,7 @@ static bool freemem(uint32_t domid, libx
             return false;
 
         credit -= difftime(time(NULL), start);
-    } while (credit > 0);
-
-    return false;
+    }
 }
 
 static void reload_domain_config(uint32_t domid,
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jan Beulich

Move the "credit expired" loop exit to the middle of the loop, immediately after "return true". This way having reached the goal on the last iteration would be reported as success to the caller, rather than as "timed out".

Thanks,

Signature · 1 line
Anthony PERARD