From win-pv-devel-bounces@lists.xenproject.org Thu Aug 06 07:45:55 2026
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 06 Aug 2026 07:45:55 +0000
Received: from list by lists.xenproject.org with outflank-mailman.1384294.1627303 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wrsna-00011Q-3G; Thu, 06 Aug 2026 07:45:54 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 1384294.1627303; Thu, 06 Aug 2026 07:45:54 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wrsna-00011J-0f; Thu, 06 Aug 2026 07:45:54 +0000
Received: by outflank-mailman (input) for mailman id 1384294;
 Thu, 06 Aug 2026 07:45:52 +0000
Received: from mx.expurgate.net ([195.190.135.20])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <owen.smith@citrix.com>) id 1wrsnY-00011D-GL
 for win-pv-devel@lists.xenproject.org; Thu, 06 Aug 2026 07:45:52 +0000
Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp
 id 1wrsnX-00C3bg-AA
 for win-pv-devel@lists.xenproject.org; Thu, 06 Aug 2026 09:45:51 +0200
Received: from [10.42.69.2] (helo=localhost)
 by localhost with ESMTP (eXpurgate MTA 0.9.1)
 (envelope-from <owen.smith@citrix.com>)
 id 6a743ba4-2eae-0a2a0a5409dd-0a2a4502cf66-36
 for <win-pv-devel@lists.xenproject.org>; Thu, 06 Aug 2026 09:45:51 +0200
Received: from [160.101.131.8] (helo=na1pdmzitismtp01.tibco.com)
 by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1)
 (envelope-from <owen.smith@citrix.com>)
 id 6a743bae-6ca4-0a2a45020019-a0658308b736-3
 for <win-pv-devel@lists.xenproject.org>; Thu, 06 Aug 2026 09:45:51 +0200
Received: from mewpvdipd2033.citrite.net (unknown [10.113.48.64])
 by na1pdmzitismtp01.tibco.com (Postfix) with ESMTP id C4038449C9FC;
 Thu,  6 Aug 2026 03:44:11 -0400 (EDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
Authentication-Results: eu.smtp.expurgate.cloud; none
From: Owen Smith <owen.smith@citrix.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@citrix.com>
Subject: [PATCH 1/2] Remove redundant RtlZeroMemory on CacheCreateSlab
Date: Thu,  6 Aug 2026 08:45:44 +0100
Message-ID: <20260806074545.990-1-owen.smith@citrix.com>
X-Mailer: git-send-email 2.51.2.windows.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-purgate-ID: tlsNG-720697/1786002351-67ABD2AC-F4FE41BE/0/0
X-purgate-type: clean
X-purgate-size: 595

__CacheAllocate already returns zeroed memory, it is redundant to
call RtlZeroMemory after allocation.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
---
 src/xenbus/cache.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/xenbus/cache.c b/src/xenbus/cache.c
index eb7020d..81cd3eb 100644
--- a/src/xenbus/cache.c
+++ b/src/xenbus/cache.c
@@ -424,8 +424,6 @@ CacheCreateSlab(
     if (Slab == NULL)
         goto fail2;
 
-    RtlZeroMemory(Slab, NumberOfBytes);
-
     Slab->Magic = XENBUS_CACHE_SLAB_MAGIC;
     Slab->Cache = Cache;
 
-- 
2.51.2.windows.1



From win-pv-devel-bounces@lists.xenproject.org Thu Aug 06 07:45:56 2026
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Thu, 06 Aug 2026 07:45:56 +0000
Received: from list by lists.xenproject.org with outflank-mailman.1384295.1627307 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wrsnc-00012n-4P; Thu, 06 Aug 2026 07:45:56 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 1384295.1627307; Thu, 06 Aug 2026 07:45:56 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wrsnc-00012g-1q; Thu, 06 Aug 2026 07:45:56 +0000
Received: by outflank-mailman (input) for mailman id 1384295;
 Thu, 06 Aug 2026 07:45:54 +0000
Received: from mx.expurgate.net ([195.190.135.20])
 by lists.xenproject.org with esmtp (Exim 4.92)
 (envelope-from <owen.smith@citrix.com>) id 1wrsna-00012S-LT
 for win-pv-devel@lists.xenproject.org; Thu, 06 Aug 2026 07:45:54 +0000
Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp
 id 1wrsna-00C3bg-1d
 for win-pv-devel@lists.xenproject.org; Thu, 06 Aug 2026 09:45:54 +0200
Received: from [10.42.69.11] (helo=localhost)
 by localhost with ESMTP (eXpurgate MTA 0.9.1)
 (envelope-from <owen.smith@citrix.com>)
 id 6a743bb0-2eae-0a2a0a5409dd-0a2a450b9bc6-10
 for <win-pv-devel@lists.xenproject.org>; Thu, 06 Aug 2026 09:45:53 +0200
Received: from [160.101.131.8] (helo=na1pdmzitismtp01.tibco.com)
 by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1)
 (envelope-from <owen.smith@citrix.com>)
 id 6a743bb0-b7e8-0a2a450b0019-a06583088706-3
 for <win-pv-devel@lists.xenproject.org>; Thu, 06 Aug 2026 09:45:53 +0200
Received: from mewpvdipd2033.citrite.net (unknown [10.113.48.64])
 by na1pdmzitismtp01.tibco.com (Postfix) with ESMTP id 7780D449C9FC;
 Thu,  6 Aug 2026 03:44:14 -0400 (EDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
Authentication-Results: eu.smtp.expurgate.cloud; none
From: Owen Smith <owen.smith@citrix.com>
To: win-pv-devel@lists.xenproject.org
Cc: Owen Smith <owen.smith@citrix.com>
Subject: [PATCH 2/2] cache: Dont linearly scan magazine slots for objects
Date: Thu,  6 Aug 2026 08:45:45 +0100
Message-ID: <20260806074545.990-2-owen.smith@citrix.com>
X-Mailer: git-send-email 2.51.2.windows.1
In-Reply-To: <20260806074545.990-1-owen.smith@citrix.com>
References: <20260806074545.990-1-owen.smith@citrix.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-purgate-ID: tlsNG-42698a/1786002353-ABCD79EA-2C9EC072/0/0
X-purgate-type: clean
X-purgate-size: 2323

Add an occupancy count to the cache magazine, and use this as an index
into the magazine slots for the current get/put location.
This avoids a linear scan of magazine slots when looking for a valid
slot during CacheGetObjectFromMagazine or CachePutObjectToMagazine,
reducing the algorithm from O(n) to O(1).

Signed-off-by: Owen Smith <owen.smith@citrix.com>
---
 src/xenbus/cache.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/xenbus/cache.c b/src/xenbus/cache.c
index 81cd3eb..90aea08 100644
--- a/src/xenbus/cache.c
+++ b/src/xenbus/cache.c
@@ -50,6 +50,7 @@ RtlRandomEx (
 #define XENBUS_CACHE_MAGAZINE_SLOTS   6
 
 typedef struct _XENBUS_CACHE_MAGAZINE {
+    ULONG   Count;
     PVOID   Slot[XENBUS_CACHE_MAGAZINE_SLOTS];
 } XENBUS_CACHE_MAGAZINE, *PXENBUS_CACHE_MAGAZINE;
 
@@ -167,20 +168,16 @@ CacheGetObjectFromMagazine(
     _In_ PXENBUS_CACHE_MAGAZINE Magazine
     )
 {
-    ULONG                       Index;
-
-    for (Index = 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) {
-        PVOID   Object;
+    PVOID                       Object;
 
-        if (Magazine->Slot[Index] != NULL) {
-            Object = Magazine->Slot[Index];
-            Magazine->Slot[Index] = NULL;
+    if (Magazine->Count == 0)
+        return NULL;
 
-            return Object;
-        }
-    }
+    Object = Magazine->Slot[--Magazine->Count];
+    Magazine->Slot[Magazine->Count] = NULL;
 
-    return NULL;
+    ASSERT(Object != NULL);
+    return Object;
 }
 
 static NTSTATUS
@@ -189,16 +186,15 @@ CachePutObjectToMagazine(
     _In_ PVOID                  Object
     )
 {
-    ULONG                       Index;
+    ASSERT(Object != NULL);
 
-    for (Index = 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) {
-        if (Magazine->Slot[Index] == NULL) {
-            Magazine->Slot[Index] = Object;
-            return STATUS_SUCCESS;
-        }
-    }
+    if (Magazine->Count == XENBUS_CACHE_MAGAZINE_SLOTS)
+        return STATUS_UNSUCCESSFUL;
+
+    ASSERT(Magazine->Slot[Magazine->Count] == NULL);
+    Magazine->Slot[Magazine->Count++] = Object;
 
-    return STATUS_UNSUCCESSFUL;
+    return STATUS_SUCCESS;
 }
 
 static PXENBUS_CACHE_MASK
-- 
2.51.2.windows.1



From win-pv-devel-bounces@lists.xenproject.org Fri Aug 07 11:42:49 2026
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Aug 2026 11:42:49 +0000
Received: from list by lists.xenproject.org with outflank-mailman.1385962.1628232 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wsIyN-0002am-Tz; Fri, 07 Aug 2026 11:42:47 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 1385962.1628232; Fri, 07 Aug 2026 11:42:47 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wsIyN-0002ae-Qw; Fri, 07 Aug 2026 11:42:47 +0000
Received: by outflank-mailman (input) for mailman id 1385962;
 Fri, 07 Aug 2026 11:42:46 +0000
Received: from mx.expurgate.net ([195.190.135.20])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc0857d1000e099@swg.vates.tech>)
 id 1wsIyM-0002aY-7Q
 for win-pv-devel@lists.xenproject.org; Fri, 07 Aug 2026 11:42:46 +0000
Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp
 id 1wsIyK-006mde-UV
 for win-pv-devel@lists.xenproject.org; Fri, 07 Aug 2026 13:42:45 +0200
Received: from [10.42.69.2] (helo=localhost)
 by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc0857d1000e099@swg.vates.tech>)
 id 6a75c4b3-bab6-0a2a0a5309dd-0a2a4502d5c6-6
 for <win-pv-devel@lists.xenproject.org>; Fri, 07 Aug 2026 13:42:44 +0200
Received: from [185.255.28.35] (helo=prod-mta-13-02.swg-srv.net)
 by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1)
 (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc0857d1000e099@swg.vates.tech>)
 id 6a75c4b4-6ca4-0a2a45020019-b9ff1c239cc7-3
 for <win-pv-devel@lists.xenproject.org>; Fri, 07 Aug 2026 13:42:44 +0200
Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr)
 (Authenticated sender:
 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e)
 by prod-mta-13-02.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id
 19fdc0857d1000e099.002 for <win-pv-devel@lists.xenproject.org>
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Fri, 07 Aug 2026 11:42:42 +0000
Received: from [192.168.1.61] (155.223.66.37.rev.sfr.net [37.66.223.155])
 (Authenticated sender: ngoc-tu.dinh@vates.tech)
 by mail2.vates.fr (Postfix) with ESMTPSA id 470C482B2E;
 Fri,  7 Aug 2026 13:42:41 +0200 (CEST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech;
 q=dns/txt; s=selector1; bh=16guSo+WJuN0UQu6twWBIoctj5q8zzAK5BQTUzB/gcc=;
 h=from:subject:date:message-id:to:mime-version:content-type:in-reply-to:references:feedback-id;
 b=oE6KHFm/cNJrOhu06tZflhmZOTm+Ap0elhnRe3GXN1xN+WhLoOFiahhVKwktUdW0pLXNBvqGt
 rbdB2pPCnDVye38bO2Rl2IX+J1ChJRaIzvpZOsCWVRH8jC4NLZolW0XYWCMQZj4A/kwtvI2iRWY
 JSLSQMhNCZ8xayNlCaiLLqLwOHEsH1m8HfEAsjmqlFfkyVkGgyZL+zDfXsttvHTsdT05TZH8nZn
 b5oo6sJtpcvSMNCEbGEVKXB6oa31EnGHw4osJTaNAz3BLZeNZofof60s4NoAC9HAAz3k9hYQCLC
 HOvSMRTyc31PUV8nW+vJi6TdhT4kyoVJLKMOKQCQW4iQ==
X-Zone-Loop: 428fc0acce24871c0a6338334320a0230e542c79e904
x-campaign-type: default
x-transaction-id: 9a911d2b-04f6-4de4-9831-94e1d36aa0f8
x-swg-uid: 01-40abf1de-2eeb-453a-ae2f-448cbf62e7bf
X-Mailer: Sweego
Message-ID:
 <1786102962.8631fc262581453bbf619ec5b2062170.19fdc0857d1000e099@vates.tech>
x-swg-bid: 1786102962.8631fc262581453bbf619ec5b2062170.19fdc0857d1000e099
Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego
x-campaign-id: default
x-client-id: 8631fc262581453bbf619ec5b2062170
X-Originating-IP: [37.26.189.201]
Date: Fri, 7 Aug 2026 13:42:40 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PATCH 1/2] Remove redundant RtlZeroMemory on CacheCreateSlab
To: Owen Smith <owen.smith@citrix.com>, win-pv-devel@lists.xenproject.org
References: <20260806074545.990-1-owen.smith@citrix.com>
Content-Language: en-US
From: Tu Dinh <ngoc-tu.dinh@vates.tech>
In-Reply-To: <20260806074545.990-1-owen.smith@citrix.com>
X-BM-Disclaimer: Yes
Content-Type: multipart/alternative; boundary="-=Part.1ec3.8512d480895ce444.19fdc0854c5.7ff25471dfd26c09=-"
X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2
X-Bm-Transport-Timestamp: 1786102961350
X-purgate-ID: tlsNG-720697/1786102964-323D42AC-41C672EC/0/0
X-purgate-type: clean
X-purgate-size: 1094

---=Part.1ec3.8512d480895ce444.19fdc0854c5.7ff25471dfd26c09=-
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 06/08/2026 09:46, Owen Smith wrote:
> __CacheAllocate already returns zeroed memory, it is redundant to
> call RtlZeroMemory after allocation=2E
>=20
> Signed-off-by: Owen Smith <owen=2Esmith@citrix=2Ecom>

Reviewed-by: Tu Dinh <ngoc-tu=2Edinh@vates=2Etech>

> ---
>   src/xenbus/cache=2Ec | 2 --
>   1 file changed, 2 deletions(-)
>=20
> diff --git a/src/xenbus/cache=2Ec b/src/xenbus/cache=2Ec
> index eb7020d=2E=2E81cd3eb 100644
> --- a/src/xenbus/cache=2Ec
> +++ b/src/xenbus/cache=2Ec
> @@ -424,8 +424,6 @@ CacheCreateSlab(
>       if (Slab =3D=3D NULL)
>           goto fail2;
>  =20
> -    RtlZeroMemory(Slab, NumberOfBytes);
> -
>       Slab->Magic =3D XENBUS_CACHE_SLAB_MAGIC;
>       Slab->Cache =3D Cache;
>  =20



-- 
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates =
solutions

web: https://vates=2Etech
---=Part.1ec3.8512d480895ce444.19fdc0854c5.7ff25471dfd26c09=---


From win-pv-devel-bounces@lists.xenproject.org Fri Aug 07 11:43:01 2026
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 07 Aug 2026 11:43:01 +0000
Received: from list by lists.xenproject.org with outflank-mailman.1385963.1628236 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wsIya-0002d9-V5; Fri, 07 Aug 2026 11:43:00 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 1385963.1628236; Fri, 07 Aug 2026 11:43:00 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1wsIya-0002d2-Sa; Fri, 07 Aug 2026 11:43:00 +0000
Received: by outflank-mailman (input) for mailman id 1385963;
 Fri, 07 Aug 2026 11:43:00 +0000
Received: from mx.expurgate.net ([195.190.135.20])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc088618000e099@swg.vates.tech>)
 id 1wsIyZ-0002cs-Ss
 for win-pv-devel@lists.xenproject.org; Fri, 07 Aug 2026 11:42:59 +0000
Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp
 id 1wsIyZ-006mlf-9d
 for win-pv-devel@lists.xenproject.org; Fri, 07 Aug 2026 13:42:59 +0200
Received: from [10.42.69.1] (helo=localhost)
 by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc088618000e099@swg.vates.tech>)
 id 6a75c4a9-bab6-0a2a0a5309dd-0a2a4501bb2a-46
 for <win-pv-devel@lists.xenproject.org>; Fri, 07 Aug 2026 13:42:59 +0200
Received: from [185.255.28.34] (helo=prod-mta-13-01.swg-srv.net)
 by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1)
 (envelope-from
 <prod-mta-13.8631fc262581453bbf619ec5b2062170.19fdc088618000e099@swg.vates.tech>)
 id 6a75c4c2-5984-0a2a45010019-b9ff1c22963f-3
 for <win-pv-devel@lists.xenproject.org>; Fri, 07 Aug 2026 13:42:59 +0200
Received: from mail2.vates.fr ([37.26.189.201] mail2.vates.fr)
 (Authenticated sender:
 8631fc262581453bbf619ec5b2062170/smtp/7773de5a-2839-4720-82ee-e06722ae1d3e)
 by prod-mta-13-01.swg-srv.net (ZoneMTA - prod-mta-13) with ESMTPSA id
 19fdc088618000e099.002 for <win-pv-devel@lists.xenproject.org>
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Fri, 07 Aug 2026 11:42:53 +0000
Received: from [192.168.1.61] (155.223.66.37.rev.sfr.net [37.66.223.155])
 (Authenticated sender: ngoc-tu.dinh@vates.tech)
 by mail2.vates.fr (Postfix) with ESMTPSA id 57D0282B2E;
 Fri,  7 Aug 2026 13:42:53 +0200 (CEST)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:MIME-Version:Content-Type:In-Reply-To:References:Feedback-ID"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech;
 q=dns/txt; s=selector1; bh=4oNqW41O3vWqXQjSUHyNrstUx4aWL4sKydfoctQjWW0=;
 h=from:subject:date:message-id:to:mime-version:content-type:in-reply-to:references:feedback-id;
 b=N2C9u1Ta4JOE8kDiOinJhWuW8Unw9VK+M2SBzLjeUqppK9zvKVZaYGyXTblJq1vYAJiGKb0hX
 z6jsVieMNxjvx07oO7yROvehaDgTZD5uB10o4KtK2PIq3aVVqyaIA+KvpSfxrlq2F2sW9Q4WmNn
 zNYnBlFoLYQ6ymJuSN3cycd5FD4AaBuwYm04bYzCLMGLcUCs5uMv3ZKuNtZhHcVL3B6JgYVP8Ue
 B3u/bMGwgUiAXlIbcaUDoYs+3RJgis9/cIqIoDZUPuBlShB/IydPDEAhT1A3mQaO3hEw3oMAzcF
 af0kZU8W2VZHVtQufzJ4QTioQVvZ6fWX6mjs+ady11kw==
X-Zone-Loop: c3fd75bc93e65b013d818292aaf88e05f9b1e23014ad
x-campaign-type: default
x-transaction-id: bbbb7337-f874-4611-8d8a-4b945c457179
x-swg-uid: 01-db8de2c5-6325-4077-9c55-7339090d6845
X-Mailer: Sweego
Message-ID:
 <1786102974.8631fc262581453bbf619ec5b2062170.19fdc088618000e099@vates.tech>
x-swg-bid: 1786102974.8631fc262581453bbf619ec5b2062170.19fdc088618000e099
Feedback-ID: default:8631fc262581453bbf619ec5b2062170:Sweego
x-campaign-id: default
x-client-id: 8631fc262581453bbf619ec5b2062170
X-Originating-IP: [37.26.189.201]
Date: Fri, 7 Aug 2026 13:42:53 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PATCH 2/2] cache: Dont linearly scan magazine slots for objects
To: Owen Smith <owen.smith@citrix.com>, win-pv-devel@lists.xenproject.org
References: <20260806074545.990-1-owen.smith@citrix.com>
 <20260806074545.990-2-owen.smith@citrix.com>
Content-Language: en-US
From: Tu Dinh <ngoc-tu.dinh@vates.tech>
In-Reply-To: <20260806074545.990-2-owen.smith@citrix.com>
X-BM-Disclaimer: Yes
Content-Type: multipart/alternative; boundary="-=Part.1ec4.8e6f9ec076ee174a.19fdc0883dd.8fc0e836ba848f28=-"
X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2
X-Bm-Transport-Timestamp: 1786102973405
X-purgate-ID: tlsNG-d62444/1786102979-C5146757-12821EAF/0/0
X-purgate-type: clean
X-purgate-size: 2993

---=Part.1ec4.8e6f9ec076ee174a.19fdc0883dd.8fc0e836ba848f28=-
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On 06/08/2026 09:46, Owen Smith wrote:
> Add an occupancy count to the cache magazine, and use this as an index
> into the magazine slots for the current get/put location=2E
> This avoids a linear scan of magazine slots when looking for a valid
> slot during CacheGetObjectFromMagazine or CachePutObjectToMagazine,
> reducing the algorithm from O(n) to O(1)=2E
>=20
> Signed-off-by: Owen Smith <owen=2Esmith@citrix=2Ecom>

Reviewed-by: Tu Dinh <ngoc-tu=2Edinh@vates=2Etech>

> ---
>   src/xenbus/cache=2Ec | 34 +++++++++++++++-------------------
>   1 file changed, 15 insertions(+), 19 deletions(-)
>=20
> diff --git a/src/xenbus/cache=2Ec b/src/xenbus/cache=2Ec
> index 81cd3eb=2E=2E90aea08 100644
> --- a/src/xenbus/cache=2Ec
> +++ b/src/xenbus/cache=2Ec
> @@ -50,6 +50,7 @@ RtlRandomEx (
>   #define XENBUS_CACHE_MAGAZINE_SLOTS   6
>  =20
>   typedef struct _XENBUS_CACHE_MAGAZINE {
> +    ULONG   Count;
>       PVOID   Slot[XENBUS_CACHE_MAGAZINE_SLOTS];
>   } XENBUS_CACHE_MAGAZINE, *PXENBUS_CACHE_MAGAZINE;
>  =20
> @@ -167,20 +168,16 @@ CacheGetObjectFromMagazine(
>       _In_ PXENBUS_CACHE_MAGAZINE Magazine
>       )
>   {
> -    ULONG                       Index;
> -
> -    for (Index =3D 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) {
> -        PVOID   Object;
> +    PVOID                       Object;
>  =20
> -        if (Magazine->Slot[Index] !=3D NULL) {
> -            Object =3D Magazine->Slot[Index];
> -            Magazine->Slot[Index] =3D NULL;
> +    if (Magazine->Count =3D=3D 0)
> +        return NULL;
>  =20
> -            return Object;
> -        }
> -    }
> +    Object =3D Magazine->Slot[--Magazine->Count];
> +    Magazine->Slot[Magazine->Count] =3D NULL;
>  =20
> -    return NULL;
> +    ASSERT(Object !=3D NULL);
> +    return Object;
>   }
>  =20
>   static NTSTATUS
> @@ -189,16 +186,15 @@ CachePutObjectToMagazine(
>       _In_ PVOID                  Object
>       )
>   {
> -    ULONG                       Index;
> +    ASSERT(Object !=3D NULL);
>  =20
> -    for (Index =3D 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) {
> -        if (Magazine->Slot[Index] =3D=3D NULL) {
> -            Magazine->Slot[Index] =3D Object;
> -            return STATUS_SUCCESS;
> -        }
> -    }
> +    if (Magazine->Count =3D=3D XENBUS_CACHE_MAGAZINE_SLOTS)
> +        return STATUS_UNSUCCESSFUL;
> +
> +    ASSERT(Magazine->Slot[Magazine->Count] =3D=3D NULL);
> +    Magazine->Slot[Magazine->Count++] =3D Object;
>  =20
> -    return STATUS_UNSUCCESSFUL;
> +    return STATUS_SUCCESS;
>   }
>  =20
>   static PXENBUS_CACHE_MASK



-- 
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates =
solutions

web: https://vates=2Etech
---=Part.1ec4.8e6f9ec076ee174a.19fdc0883dd.8fc0e836ba848f28=---


