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

Re: [PATCH] xen/mm: page_alloc fix duplicated order shift operation in the loop


  • To: Paran Lee <p4ranlee@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 25 Apr 2022 10:15:12 +0200
  • 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kgFXD2ZM0QepaS14l6MPX+1+SMvT6zHSjQoxlyY18es=; b=gcIShmr2ky5pKCCuoRdcoTwUavPkTWJN6b4eUPeViXYDKvQJsapGKEsEU+P4vHOeB9MAUzITttJ/nkDWSDJ+uxVtqCuWgIr4cxU9JmPWwbGQlKr16q2LjlMabSoLguFHjLs4MImzvNlN44MYcC6SEVUeoInwWWkJMdqIdYOeQEweyNFLaS+SdvjUfkXhULlRoqS+0moWwgPUbSCBzsZNunBCZQCRpO25iwzwS2pkmCf+CPoNvN+ObD1cOmYpxulTS+aHKw90qIdNx9ZXMYR2RGU0z9vt28hY1huYpfmMUrQeImPVBHnPYxj0Jk06juNNVFnwYSbyIYxSkNutSomaZA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lqauwyr+ADJto2FW1c2MeOEY3XGpanqMjKKzKsL9poy2m8kCSogU7En2cEL19q3k6AY/z3sfirsVrC3zkDdN9gFIY04LQ29DaVqKxsbH0HQ5Kjjtg/SqL1PYBaGwUQm+5sKzmh+5XREAKSAU5Rll9/9KWu1it3TVdpLQhJ59nXwf6wCdrHy6xUz8ecjQekd4BF5XL1e8zKnK3fqM2YcBFBFK/yGac5exDUSdgivkCGflwPGoS3aFwtTgBJc1E9/sPCzsXndC2kFts7fafwBRUWT5gXVPxyoied6PQeo/4rMMWh33VoKYWn0JPjLUFHLT7c/xbYzhHVemOZQQMDMs4Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Austin Kim <austindh.kim@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Mon, 25 Apr 2022 08:19:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 23.04.2022 21:35, Paran Lee wrote:
> It doesn't seem necessary to do that
> duplicate calculation of order shift 2^@order in the loop.

Once again I'm not convinced. As in the other patch the compiler could
do this transformation via its CSE pass if it sees fit.

Also (applicable as well to the other patch) I think "fix" in the
subject is misleading: There's nothing wrong with the original code.

> In addition, I fixed type of total_avail_pages from long
> to unsigned long. because when total_avail_pages static variable
> substitute in functions of page alloc local variable,
> type of local variables is unsigned long.

You've done more changes, some of which are questionable.

> @@ -922,8 +922,9 @@ static struct page_info *alloc_heap_pages(
>      struct domain *d)
>  {
>      nodeid_t node;
> -    unsigned int i, buddy_order, zone, first_dirty;
> -    unsigned long request = 1UL << order;
> +    unsigned int buddy_order, zone, first_dirty;
> +    unsigned int buddy_request;
> +    unsigned long i, request = 1UL << order;

E.g. it's not clear why these both need to be unsigned long when the
largest chunk which can be allocated in one go is 1GiB (MAX_ORDER).
At least on x86 operations on 32-bit quantities are generally
slightly more efficient than such on 64-bit values. If we wanted to
cater for architectures setting MAX_ORDER to 32 or higher, I think
the type used should become a typedef picking "unsigned int" at least
on x86.

> @@ -975,16 +976,17 @@ static struct page_info *alloc_heap_pages(
>      while ( buddy_order != order )
>      {
>          buddy_order--;
> +        buddy_request = 1U << buddy_order;

Such a local variable would better have narrowest possible scope.

> @@ -1490,7 +1493,7 @@ static void free_heap_pages(
>              /* Update predecessor's first_dirty if necessary. */
>              if ( predecessor->u.free.first_dirty == INVALID_DIRTY_IDX &&
>                   pg->u.free.first_dirty != INVALID_DIRTY_IDX )
> -                predecessor->u.free.first_dirty = (1U << order) +
> +                predecessor->u.free.first_dirty = mask +
>                                                    pg->u.free.first_dirty;
>  
>              pg = predecessor;
> @@ -1511,7 +1514,7 @@ static void free_heap_pages(
>              /* Update pg's first_dirty if necessary. */
>              if ( pg->u.free.first_dirty == INVALID_DIRTY_IDX &&
>                   successor->u.free.first_dirty != INVALID_DIRTY_IDX )
> -                pg->u.free.first_dirty = (1U << order) +
> +                pg->u.free.first_dirty = mask +
>                                           successor->u.free.first_dirty;

This re-use of an existing local variable looks reasonable to me.
It would be nice though if the variable's scope was shrunk and its
type was also adjusted to unsigned int.

Jan




 


Rackspace

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