From nobody Mon May 6 13:09:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502955178836741.2896403997679; Thu, 17 Aug 2017 00:32:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1964C01DDAC; Thu, 17 Aug 2017 07:32:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E091E5D75A; Thu, 17 Aug 2017 07:32:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 780BD3FC71; Thu, 17 Aug 2017 07:32:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7H7W6Db009926 for ; Thu, 17 Aug 2017 03:32:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id A96146EC8D; Thu, 17 Aug 2017 07:32:06 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 312EE619F4 for ; Thu, 17 Aug 2017 07:32:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1964C01DDAC Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 17 Aug 2017 09:32:01 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] network: Use self inflating bitmap for class IDs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Aug 2017 07:32:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: John Ferlan --- src/conf/virnetworkobj.c | 18 ++++++++++-------- src/network/bridge_driver.c | 5 +++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 918ef44ea..455b604bb 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -34,8 +34,10 @@ =20 VIR_LOG_INIT("conf.virnetworkobj"); =20 -/* 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) =20 struct _virNetworkObj { virObjectLockable parent; @@ -100,13 +102,14 @@ virNetworkObjNew(void) if (!(obj =3D virObjectLockableNew(virNetworkObjClass))) return NULL; =20 - if (!(obj->classIdMap =3D virBitmapNew(CLASS_ID_BITMAP_SIZE))) + if (!(obj->classIdMap =3D virBitmapNew(INIT_CLASS_ID_BITMAP_SIZE))) goto error; =20 /* 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; =20 virObjectLock(obj); =20 @@ -909,8 +912,7 @@ virNetworkLoadState(virNetworkObjListPtr nets, ctxt->node =3D node; if ((classIdStr =3D virXPathString("string(./class_id[1]/@bitmap)", ctxt))) { - if (virBitmapParse(classIdStr, &classIdMap, - CLASS_ID_BITMAP_SIZE) < 0) { + if (!(classIdMap =3D virBitmapParseUnlimited(classIdStr))) { VIR_FREE(classIdStr); goto error; } diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 74ce92e43..e8d093a31 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5395,9 +5395,10 @@ networkNextClassID(virNetworkObjPtr obj) ssize_t ret =3D 0; virBitmapPtr classIdMap =3D virNetworkObjGetClassIdMap(obj); =20 - ret =3D virBitmapNextClearBit(classIdMap, -1); + if ((ret =3D virBitmapNextClearBit(classIdMap, -1)) < 0) + ret =3D virBitmapSize(classIdMap); =20 - if (ret < 0 || virBitmapSetBit(classIdMap, ret) < 0) + if (virBitmapSetBitExpand(classIdMap, ret) < 0) return -1; =20 return ret; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list