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

Re: [Xen-devel] [PATCH V2 3/6] [RFC] xen/common: Introduce _xrealloc function


  • To: Oleksandr Tyshchenko <olekstysh@xxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Mon, 5 Aug 2019 10:02:43 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q3EeKVeFPKGVxGVDEQfu2zW8mbIy6TW+fp2IDQrbz2M=; b=SVEzandYhPPH0kkCXPq0MVAW/T76CPNhyblbI+RUukXgWiQjzYV3FAko5OCOiLGSoE8Drp8jd0D24i8+vIz9cQtezumRK7H3fmi1Mx07rifhHUO/VPLtUFliPOSzGodJd5uDfkx+82SaxSFE/xls0RxJRsjWZYAAYeCQI1U4r4iyLZjBHcbKJ4s3XTmgay1RyJGBtvRNPANmP5b4V6YHzDj2GEOGxJ3S/lwcF3dFwI5rxjOxbszVPEk+8cyFeFpHSCLhMD8BEMSTCR1l+aAcVSN1QWx5KZgW01IDkNHGYjlUub0pOa8dyyupKi6dSt3vmVi17t2OPbiTHNzZTRTReA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LjEmHA606z06QzpC1umkF2H8UJ3swggVDTAfeeWddi5oEvdPLxYeKf5Eef24asGCsKPQFlTR4mVClLzXHDshzQDBeAAf1eOD8scJAX+7GO5xyAv1sqRj5Wud6gO+AFDUFVyyv+8qXgxT4KgsC8v/KIRqelH6mR7xwaVyT9c1sU15xcVutgEQTXt8UiiVKffGZTClPmFyNxAwbHgbo72xFqPkzrs5i/6qFfG+T2W09SeRcodIXL59kxN8TczQ/s/tSmhkbKie29AD6FJkeJrV8L30Y7Nx7KQstGgK+G3JaRMzzNk+wpIB6y3YfBQhNs/l3J3s7gE9pWVD6u+tF/fYtA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, "julien.grall@xxxxxxx" <julien.grall@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 05 Aug 2019 10:07:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVSVD5wUnbw+V8Qku+SBIMTDh+a6bsVzSA
  • Thread-topic: [PATCH V2 3/6] [RFC] xen/common: Introduce _xrealloc function

On 02.08.2019 18:39, Oleksandr Tyshchenko wrote:
> --- a/xen/common/xmalloc_tlsf.c
> +++ b/xen/common/xmalloc_tlsf.c
> @@ -610,6 +610,27 @@ void *_xzalloc(unsigned long size, unsigned long align)
>       return p ? memset(p, 0, size) : p;
>   }
>   
> +void *_xrealloc(void *p, unsigned long new_size, unsigned long align)
> +{
> +    void *new_p;
> +
> +    if ( !new_size )
> +    {
> +        xfree(p);
> +        return NULL;
> +    }
> +
> +    new_p = _xmalloc(new_size, align);
> +
> +    if ( new_p && p )
> +    {
> +        memcpy(new_p, p, new_size);
> +        xfree(p);
> +    }
> +
> +    return new_p;
> +}

While I can see why having a re-allocation function may be handy,
explicit / direct use of _xmalloc() and _xzalloc() are discouraged,
in favor of the more type-safe underscore-less variants. I can't
see though how a type-safe "realloc" could look like, except for
arrays. If resizing arrays is all you're after, I'd like to
recommend to go that route rather then the suggested one here. If
resizing arbitrary objects is the goal, then what you suggest may
be the only route, but I'd still be not overly happy to see such
added.

Furthermore you don't even use internals of the allocator: It is
common practice to avoid re-allocation if the requested size fits
within the already allocated block. That's not the least helpful
because in such a case you can't possibly suffer any -ENOMEM
condition.

And finally - please note _xmalloc()'s and _xfree()'s use /
special casing of ZERO_BLOCK_PTR: You absolutely would need to
mirror this here.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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