|
|
404507 |
From a7cc1c068ba979a35bad3f4a21e1161379725c61 Mon Sep 17 00:00:00 2001
|
|
|
404507 |
Message-Id: <a7cc1c068ba979a35bad3f4a21e1161379725c61@dist-git>
|
|
|
404507 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
Date: Wed, 31 Jan 2018 16:32:42 +0100
|
|
|
404507 |
Subject: [PATCH] util: Don't overwrite mask in virResctrlAllocFindUnused
|
|
|
404507 |
|
|
|
404507 |
Due to confusing naming the pointer to the mask got copied which must not
|
|
|
404507 |
happen, so use UpdateMask instead of SetMask. That also means we can get
|
|
|
404507 |
completely rid of SetMask.
|
|
|
404507 |
|
|
|
404507 |
Also don't clear the free bits since it is not used again (leftover from
|
|
|
404507 |
previous versions).
|
|
|
404507 |
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
(cherry picked from commit 859186091cc6348e48cdad37c635fb3342e68189)
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
|
|
|
404507 |
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
---
|
|
|
404507 |
src/util/virresctrl.c | 41 ++++++++++++++---------------------------
|
|
|
404507 |
1 file changed, 14 insertions(+), 27 deletions(-)
|
|
|
404507 |
|
|
|
404507 |
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
|
|
|
404507 |
index a0ea274871..fdd1ded6f7 100644
|
|
|
404507 |
--- a/src/util/virresctrl.c
|
|
|
404507 |
+++ b/src/util/virresctrl.c
|
|
|
404507 |
@@ -1253,22 +1253,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl ATTRIBUTE_UNUSED)
|
|
|
404507 |
|
|
|
404507 |
#endif /* ! __linux__ */
|
|
|
404507 |
|
|
|
404507 |
-static int
|
|
|
404507 |
-virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type,
|
|
|
404507 |
- unsigned int cache,
|
|
|
404507 |
- virBitmapPtr mask)
|
|
|
404507 |
-{
|
|
|
404507 |
- if (a_type->nmasks <= cache &&
|
|
|
404507 |
- VIR_EXPAND_N(a_type->masks, a_type->nmasks,
|
|
|
404507 |
- cache - a_type->nmasks + 1) < 0)
|
|
|
404507 |
- return -1;
|
|
|
404507 |
-
|
|
|
404507 |
- virBitmapFree(a_type->masks[cache]);
|
|
|
404507 |
- a_type->masks[cache] = mask;
|
|
|
404507 |
-
|
|
|
404507 |
- return 0;
|
|
|
404507 |
-}
|
|
|
404507 |
-
|
|
|
404507 |
|
|
|
404507 |
/*
|
|
|
404507 |
* Given the information about requested allocation type `a_type`, the host
|
|
|
404507 |
@@ -1276,16 +1260,19 @@ virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type,
|
|
|
404507 |
* this function tries to find the smallest free space in which the allocation
|
|
|
404507 |
* for cache id `cache` would fit. We're looking for the smallest place in
|
|
|
404507 |
* order to minimize fragmentation and maximize the possibility of succeeding.
|
|
|
404507 |
+ *
|
|
|
404507 |
+ * Per-cache allocation for the @level, @type and @cache must already be
|
|
|
404507 |
+ * allocated for @alloc (does not have to exist though).
|
|
|
404507 |
*/
|
|
|
404507 |
static int
|
|
|
404507 |
-virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
|
|
|
404507 |
+virResctrlAllocFindUnused(virResctrlAllocPtr alloc,
|
|
|
404507 |
virResctrlInfoPerTypePtr i_type,
|
|
|
404507 |
virResctrlAllocPerTypePtr f_type,
|
|
|
404507 |
unsigned int level,
|
|
|
404507 |
unsigned int type,
|
|
|
404507 |
unsigned int cache)
|
|
|
404507 |
{
|
|
|
404507 |
- unsigned long long *size = a_type->sizes[cache];
|
|
|
404507 |
+ unsigned long long *size = alloc->levels[level]->types[type]->sizes[cache];
|
|
|
404507 |
virBitmapPtr a_mask = NULL;
|
|
|
404507 |
virBitmapPtr f_mask = NULL;
|
|
|
404507 |
unsigned long long need_bits;
|
|
|
404507 |
@@ -1293,6 +1280,7 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
|
|
|
404507 |
ssize_t pos = -1;
|
|
|
404507 |
ssize_t last_bits = 0;
|
|
|
404507 |
ssize_t last_pos = -1;
|
|
|
404507 |
+ int ret = -1;
|
|
|
404507 |
|
|
|
404507 |
if (!size)
|
|
|
404507 |
return 0;
|
|
|
404507 |
@@ -1384,17 +1372,16 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
|
|
|
404507 |
if (!a_mask)
|
|
|
404507 |
return -1;
|
|
|
404507 |
|
|
|
404507 |
- for (i = last_pos; i < last_pos + need_bits; i++) {
|
|
|
404507 |
+ for (i = last_pos; i < last_pos + need_bits; i++)
|
|
|
404507 |
ignore_value(virBitmapSetBit(a_mask, i));
|
|
|
404507 |
- ignore_value(virBitmapClearBit(f_mask, i));
|
|
|
404507 |
- }
|
|
|
404507 |
|
|
|
404507 |
- if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) {
|
|
|
404507 |
- virBitmapFree(a_mask);
|
|
|
404507 |
- return -1;
|
|
|
404507 |
- }
|
|
|
404507 |
+ if (virResctrlAllocUpdateMask(alloc, level, type, cache, a_mask) < 0)
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
|
|
|
404507 |
- return 0;
|
|
|
404507 |
+ ret = 0;
|
|
|
404507 |
+ cleanup:
|
|
|
404507 |
+ virBitmapFree(a_mask);
|
|
|
404507 |
+ return ret;
|
|
|
404507 |
}
|
|
|
404507 |
|
|
|
404507 |
|
|
|
404507 |
@@ -1500,7 +1487,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
|
|
|
404507 |
virResctrlInfoPerLevelPtr i_level = resctrl->levels[level];
|
|
|
404507 |
virResctrlInfoPerTypePtr i_type = i_level->types[type];
|
|
|
404507 |
|
|
|
404507 |
- if (virResctrlAllocFindUnused(a_type, i_type, f_type, level, type, cache) < 0)
|
|
|
404507 |
+ if (virResctrlAllocFindUnused(alloc, i_type, f_type, level, type, cache) < 0)
|
|
|
404507 |
goto cleanup;
|
|
|
404507 |
}
|
|
|
404507 |
}
|
|
|
404507 |
--
|
|
|
404507 |
2.16.1
|
|
|
404507 |
|