[PATCH] xen/gnttab: Shrink struct gnttab_copy_buf

Andrew Cooper posted 1 patch 1 day, 17 hours ago
xen/common/grant_table.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
[PATCH] xen/gnttab: Shrink struct gnttab_copy_buf
Posted by Andrew Cooper 1 day, 17 hours ago
Move the booleans into earlier padding.  No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony.perard@vates.tech>
CC: Michal Orzel <michal.orzel@amd.com>
CC: Jan Beulich <jbeulich@suse.com>
CC: Julien Grall <julien@xen.org>
CC: Roger Pau Monné <roger@xenproject.org>
CC: Stefano Stabellini <sstabellini@kernel.org>

On 64bit, this shrinks from 64 bytes to 56 bytes.

On arm32, it's 40 bytes before and after.  Given that we can't reuse the
tail-padding from struct gnttab_copy_ptr, I'm not sure there's an obvious
improvement to be had:

  xen.git/xen$ pahole xen-syms-arm32-after -E -C gnttab_copy_buf
  struct gnttab_copy_buf {
        struct gnttab_copy_ptr {
                union {
                        /* typedef grant_ref_t -> uint32_t */ unsigned int ref;          /*     0     4 */
                        /* typedef xen_pfn_t -> uint64_t */ long long unsigned int gmfn; /*     0     8 */
                } u;                                                                     /*     0     8 */
                /* typedef domid_t -> uint16_t */ short unsigned int domid;              /*     8     2 */
                /* typedef uint16_t */ short unsigned int offset;                        /*    10     2 */
        }ptr; /*     0    16 */

        /* XXX last struct has 4 bytes of padding */

        /* typedef uint16_t */ short unsigned int         len;                           /*    16     2 */
        _Bool                      read_only;                                            /*    18     1 */
        _Bool                      have_grant;                                           /*    19     1 */
        _Bool                      have_type;                                            /*    20     1 */

        /* XXX 3 bytes hole, try to pack */

        struct domain *            domain;                                               /*    24     4 */
        /* typedef mfn_t */ struct {
                long unsigned int  mfn;                                                  /*    28     4 */
        } mfn; /*    28     4 */
        struct page_info *         page;                                                 /*    32     4 */
        void *                     virt;                                                 /*    36     4 */

        /* size: 40, cachelines: 1, members: 9 */
        /* sum members: 37, holes: 1, sum holes: 3 */
        /* paddings: 1, sum paddings: 4 */
        /* last cacheline: 40 bytes */
  };
---
 xen/common/grant_table.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 5e79c012b695..d2c3c73be900 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -2927,13 +2927,14 @@ struct gnttab_copy_buf {
     uint16_t len;
 
     /* Mapped etc. */
+    bool read_only;
+    bool have_grant;
+    bool have_type;
+
     struct domain *domain;
     mfn_t mfn;
     struct page_info *page;
     void *virt;
-    bool read_only;
-    bool have_grant;
-    bool have_type;
 };
 
 static int gnttab_copy_lock_domain(domid_t domid, struct gnttab_copy_buf *buf)

base-commit: 2043d22b7e926f508cc23391b4c75325fa7211e9
-- 
2.39.5


Re: [PATCH] xen/gnttab: Shrink struct gnttab_copy_buf
Posted by Jan Beulich 1 day, 17 hours ago
On 03.11.2026 14:01, Andrew Cooper wrote:
> Move the booleans into earlier padding.  No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

> On arm32, it's 40 bytes before and after.  Given that we can't reuse the
> tail-padding from struct gnttab_copy_ptr, I'm not sure there's an obvious
> improvement to be had:
> 
>   xen.git/xen$ pahole xen-syms-arm32-after -E -C gnttab_copy_buf
>   struct gnttab_copy_buf {
>         struct gnttab_copy_ptr {
>                 union {
>                         /* typedef grant_ref_t -> uint32_t */ unsigned int ref;          /*     0     4 */
>                         /* typedef xen_pfn_t -> uint64_t */ long long unsigned int gmfn; /*     0     8 */
>                 } u;                                                                     /*     0     8 */
>                 /* typedef domid_t -> uint16_t */ short unsigned int domid;              /*     8     2 */
>                 /* typedef uint16_t */ short unsigned int offset;                        /*    10     2 */
>         }ptr; /*     0    16 */
> 
>         /* XXX last struct has 4 bytes of padding */
> 
>         /* typedef uint16_t */ short unsigned int         len;                           /*    16     2 */
>         _Bool                      read_only;                                            /*    18     1 */
>         _Bool                      have_grant;                                           /*    19     1 */
>         _Bool                      have_type;                                            /*    20     1 */

Making these bitfields would help Arm32.

Jan

PS: Can we also get the other pending gnttab change sorted? As said,
feel free to post your patch, and I'll ack it. Alternatively an ack
on my variant would be nice.