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

Re: [Xen-devel] [PATCH 1/3] xmalloc: stop using a magic '1' in alignment padding


  • To: Paul Durrant <paul.durrant@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Wed, 3 Jul 2019 09:38:34 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; test.office365.com 1;spf=none;dmarc=none;dkim=none;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=testarcselector01; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xIPrJAowB1UWBuKHvcrONveCxB4aSute50DGObSYoxY=; b=Bqmk+zn4wVxIhXb2sViYe/E7WinBZav+7i0PWWtlHl23574dlOaeM3tExzr7goAkT7DxM3XVfDbzasrQ3RXe3SoLrCihww+6ylLjloDCLY3snwL+LIRJAHFRSem822ic6CuO/+tlKrLhvSU1bc4Q8JmDlWfd3SodOVY5OABgWvs=
  • Arc-seal: i=1; a=rsa-sha256; s=testarcselector01; d=microsoft.com; cv=none; b=G0WG6YnyIfp4nWMrqeJcvUw3x30pREeYpqzRFPrCKUFLjltojKuFBR6erAaESBkY+nkWf0Dxov0Ry7VnmoWui19vYen4mF+sUEu+iIiWpActxlGimaC8DJMF6lwgxkfIxCy++0MgDKBunhL6r3vR7AIgnoRXISTxqgxdg+L7Y1E=
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: Stefano Stabellini <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>, TimDeegan <tim@xxxxxxx>, Julien Grall <julien.grall@xxxxxxx>
  • Delivery-date: Wed, 03 Jul 2019 09:40:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVMPSreQmX7EFeR0yZKSNJq3JVRaa4pDkA
  • Thread-topic: [PATCH 1/3] xmalloc: stop using a magic '1' in alignment padding

On 02.07.2019 18:38, Paul Durrant wrote:
> Alignment padding inserts a pseudo block header in front of the allocation,
> sets its size field to the pad size and then ORs in 1, which is equivalent
> to marking it as a free block, so that xfree() can distinguish it from a
> real block header.
> 
> This patch simply replaces the magic '1' with the defined 'FREE_BLOCK' to
> make it more obvious what's going on.

Hmm, that's still an abuse of some sort, I think. FREE_BLOCK
(together with USED_BLOCK, PREV_FREE, and PREV_USED) serve
block splitting and re-combination, which isn't strictly the
case here. But yes, I guess (ab)using the manifest constants is
still better than (ab)using the literal numbers.

> Also, whilst in the neighbourhood, it removes a stray space after a cast.

An option would have been to drop the cast altogether. The code
here appears to assume that void pointer arithmetic is not
allowed (as is indeed the case in plain C).

> Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
with one further adjustment:

> @@ -638,12 +638,12 @@ void xfree(void *p)
>       }
>   
>       /* Strip alignment padding. */
> -    b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
> -    if ( b->size & 1 )
> +    b = (struct bhdr *)((char *)p - BHDR_OVERHEAD);
> +    if ( b->size & FREE_BLOCK )
>       {
>           p = (char *)p - (b->size & ~1u);

This ~1u also wants to become ~FREE_BLOCK then. I guess the
change is easy enough to make while committing; I don't
expect the loss of the u suffix to actually cause any
problems. In fact its presence was not a problem only
because ->size can't get very large and is of u32 type.

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®.