[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 06/16] libs/call: cache up to 4 pages in hypercall bounce buffers


  • To: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • From: Frediano Ziglio <freddy77@xxxxxxxxx>
  • Date: Thu, 9 Jul 2026 08:13:51 +0100
  • Arc-authentication-results: i=1; mx.google.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=96R0aAbcwKSJcVhwn6esJttlYNo8225hH9gYOu8JEfo=; fh=/xIDEt21AoDgIoFrvXO7IQvdlvHF73QaNWBe25gcoZE=; b=cb/HicNx1Zi87X8ds+TAVTT4LZ8qAPnXoX9E+AW8aSNpO2mC+O/s3GgH1UhJKH/j9k WY4b2R6B6PMKdEt3IlPblr46p4TVeD60yf0qiVChDD3YaHEFDZAWIzXCaGuN6TDZpuZs OG/F2qWnc1oUMhBvxgEoK0vBA52hPfhRxreTQiEKHxm1uGa/xvEN6BAx38RZWvwDJSgR S9obYEZh0V8wqCQsybe+VRnNMmzZD78kzVp2Xbo91JZVJ7UGDt62NZKdh8e05wSISEzD ETtvalsx9wQIVzMj6yvWSxCPyo0EbBHfNgpbB/StTKFDTbje4AtY80hDqIQyEOrMTI2u a4Dg==; darn=lists.xenproject.org
  • Arc-seal: i=1; a=rsa-sha256; t=1783581244; cv=none; d=google.com; s=arc-20260327; b=oHXW4CS/Q30vIIlW9AUjWK+b0LfnEjGLh0FBJY1LEVyHf0Eto/womvNOqXQ+CvLEmo 4LULYKcNNr6eMrauLtwPlKzvuK1slUcKaNsHeYUYZIJXrdKb5h3ImIkuJ4CQOkuBXf1E Ungs1Xayd45897pixGZhRtynSxwDwToCL9V3ofFTVTLzCgIa0w8ogRqiM0Jnl4ysjLMB ZF4XklpOUeKJ/nPhAWPAdwBtqNImOlBfmZeHGdPXtB8WcMsZBoX2HgSyA19Rb3568D4w MqLppqgbw2wriotm3GSzFZ7wp1XElYGuLZpDpBhw9pqZa24DzA5oHaM8hXP5z4VWYzbi 7Sng==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:MIME-Version"
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Edwin Török <edwin.torok@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Frediano Ziglio <frediano.ziglio@xxxxxxxxxx>
  • Delivery-date: Thu, 09 Jul 2026 07:14:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, 8 Jul 2026 at 14:19, Anthony PERARD <anthony.perard@xxxxxxxxxx> wrote:
>
> On Tue, Jul 07, 2026 at 03:47:07PM +0100, Frediano Ziglio wrote:
> > On Tue, 7 Jul 2026 at 14:51, Anthony PERARD <anthony.perard@xxxxxxxxxx> 
> > wrote:
> > > On Fri, Jun 19, 2026 at 02:04:51PM +0100, Frediano Ziglio wrote:
> > > > diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c
> > > > index 155e4f9d43..2f0515c273 100644
> > > > --- a/tools/libs/call/buffer.c
> > > > +++ b/tools/libs/call/buffer.c
> > > > @@ -49,6 +49,9 @@ static void *cache_alloc(xencall_handle *xcall, 
> > > > size_t nr_pages)
> > > >  {
> > > >      void *p = NULL;
> > > >
> > > > +    if ( nr_pages == 0 )
> > > > +        return NULL;
> > >
> > > By doing that check here, we don't update the stat anymore. And it's
> > > getting out-of-sync with the updates done in cache_free().
> > >
> > > Before, we where returning a cache entry for that, and cache_hit++. I
> > > think it's ok to return cache_miss++ instead.
> > >
> >
> > Well... requesting 0 pages is weird by definition, even malloc(0) is
> > not well defined.
>
> malloc(0) isn't defined as weird, it is defined as
> "implementation-defined" ;-). But the pointer that the cache function
> handle isn't from malloc().
>
> > In theory in this case returning NULL would cause cache_free to not be
> > called as filtered by xencall_free_buffer_pages.
>
> Yes, for cases where the allocator returned NULL. But I can't find any
> guaranty of this. So I would prefer to have both cache_alloc() and
> cache_free() behave the same way when faced with nr_pages==0, without
> hindsight into the value of the pointer.
>
> >
> > I think the most symmetric think would be adding a similar test in
> > cache_free, like
> >
> > static int cache_free(xencall_handle *xcall, void *p, size_t nr_pages)
> > {
> >     int rc = 0;
> >
> >     if ( nr_pages == 0 )
> >         return 1;
> >
> >     cache_lock(xcall);
> >
> >
> > (the return 1 is needed to prevent the attempt to munmap the pointer
> > which does not make sense).
>
> If we have a pointer that is not NULL, we must free it. Even if you
> think it doesn't make sense. Also, there's no way to know, here, whether
> munmap() or an other function is going to be used. So, cache_free() must
> not say that it cached the pointer, and let the caller free it.
>

Changed to return 0, NULL pointer is handled by the caller anyway.

> Cheers,
>
>
> --
> Anthony Perard | Vates XCP-ng Developer
>
> XCP-ng & Xen Orchestra - Vates solutions
>
> web: https://vates.tech



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.