network: Use self inflating bitmap for class IDs
Back in the day when I was implementing QoS for networks there were no self inflating virBitmaps. Only the static ones. Therefore, I had to allocate the whole 8KB of memory in order to keep track of used/unused class IDs. This is rather wasteful because nobody is ever gonna use that much classes (kernel overhead would drastically lower the bandwidth). Anyway, now that we have self inflating bitmaps we can start small and allocate more if there's need for it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
6862ad3cd7
commit
361ff0a088
@ -34,8 +34,10 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("conf.virnetworkobj");
|
VIR_LOG_INIT("conf.virnetworkobj");
|
||||||
|
|
||||||
/* currently, /sbin/tc implementation allows up to 16 bits for minor class size */
|
/* Currently, /sbin/tc implementation allows up to 16 bits for
|
||||||
#define CLASS_ID_BITMAP_SIZE (1<<16)
|
* minor class size. But the initial bitmap doesn't have to be
|
||||||
|
* that big. */
|
||||||
|
#define INIT_CLASS_ID_BITMAP_SIZE (1<<4)
|
||||||
|
|
||||||
struct _virNetworkObj {
|
struct _virNetworkObj {
|
||||||
virObjectLockable parent;
|
virObjectLockable parent;
|
||||||
@ -100,13 +102,14 @@ virNetworkObjNew(void)
|
|||||||
if (!(obj = virObjectLockableNew(virNetworkObjClass)))
|
if (!(obj = virObjectLockableNew(virNetworkObjClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(obj->classIdMap = virBitmapNew(CLASS_ID_BITMAP_SIZE)))
|
if (!(obj->classIdMap = virBitmapNew(INIT_CLASS_ID_BITMAP_SIZE)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* The first three class IDs are already taken */
|
/* The first three class IDs are already taken */
|
||||||
ignore_value(virBitmapSetBit(obj->classIdMap, 0));
|
if (virBitmapSetBitExpand(obj->classIdMap, 0) < 0 ||
|
||||||
ignore_value(virBitmapSetBit(obj->classIdMap, 1));
|
virBitmapSetBitExpand(obj->classIdMap, 1) < 0 ||
|
||||||
ignore_value(virBitmapSetBit(obj->classIdMap, 2));
|
virBitmapSetBitExpand(obj->classIdMap, 2) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
virObjectLock(obj);
|
virObjectLock(obj);
|
||||||
|
|
||||||
@ -909,8 +912,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
|
|||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
if ((classIdStr = virXPathString("string(./class_id[1]/@bitmap)",
|
if ((classIdStr = virXPathString("string(./class_id[1]/@bitmap)",
|
||||||
ctxt))) {
|
ctxt))) {
|
||||||
if (virBitmapParse(classIdStr, &classIdMap,
|
if (!(classIdMap = virBitmapParseUnlimited(classIdStr))) {
|
||||||
CLASS_ID_BITMAP_SIZE) < 0) {
|
|
||||||
VIR_FREE(classIdStr);
|
VIR_FREE(classIdStr);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -5395,9 +5395,10 @@ networkNextClassID(virNetworkObjPtr obj)
|
|||||||
ssize_t ret = 0;
|
ssize_t ret = 0;
|
||||||
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
||||||
|
|
||||||
ret = virBitmapNextClearBit(classIdMap, -1);
|
if ((ret = virBitmapNextClearBit(classIdMap, -1)) < 0)
|
||||||
|
ret = virBitmapSize(classIdMap);
|
||||||
|
|
||||||
if (ret < 0 || virBitmapSetBit(classIdMap, ret) < 0)
|
if (virBitmapSetBitExpand(classIdMap, ret) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user