提交 361ff0a0 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 6862ad3c
......@@ -34,8 +34,10 @@
VIR_LOG_INIT("conf.virnetworkobj");
/* currently, /sbin/tc implementation allows up to 16 bits for minor class size */
#define CLASS_ID_BITMAP_SIZE (1<<16)
/* Currently, /sbin/tc implementation allows up to 16 bits for
* minor class size. But the initial bitmap doesn't have to be
* that big. */
#define INIT_CLASS_ID_BITMAP_SIZE (1<<4)
struct _virNetworkObj {
virObjectLockable parent;
......@@ -100,13 +102,14 @@ virNetworkObjNew(void)
if (!(obj = virObjectLockableNew(virNetworkObjClass)))
return NULL;
if (!(obj->classIdMap = virBitmapNew(CLASS_ID_BITMAP_SIZE)))
if (!(obj->classIdMap = virBitmapNew(INIT_CLASS_ID_BITMAP_SIZE)))
goto error;
/* The first three class IDs are already taken */
ignore_value(virBitmapSetBit(obj->classIdMap, 0));
ignore_value(virBitmapSetBit(obj->classIdMap, 1));
ignore_value(virBitmapSetBit(obj->classIdMap, 2));
if (virBitmapSetBitExpand(obj->classIdMap, 0) < 0 ||
virBitmapSetBitExpand(obj->classIdMap, 1) < 0 ||
virBitmapSetBitExpand(obj->classIdMap, 2) < 0)
goto error;
virObjectLock(obj);
......@@ -909,8 +912,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
ctxt->node = node;
if ((classIdStr = virXPathString("string(./class_id[1]/@bitmap)",
ctxt))) {
if (virBitmapParse(classIdStr, &classIdMap,
CLASS_ID_BITMAP_SIZE) < 0) {
if (!(classIdMap = virBitmapParseUnlimited(classIdStr))) {
VIR_FREE(classIdStr);
goto error;
}
......
......@@ -5395,9 +5395,10 @@ networkNextClassID(virNetworkObjPtr obj)
ssize_t ret = 0;
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 ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册