Message ID | 8f3d2e49270a2158717e15008e7ed7228196ba02.1676707807.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp279228wrn; Sat, 18 Feb 2023 00:35:22 -0800 (PST) X-Google-Smtp-Source: AK7set9Lj9LKA1zl9wWyx6Mvne+c7M9KYj/DTAkylrovZmn/C8m7k2Nw+fH6GV7oR6CmSG4kJ2JK X-Received: by 2002:a17:907:3e87:b0:8af:4969:1bb4 with SMTP id hs7-20020a1709073e8700b008af49691bb4mr2629395ejc.53.1676709322485; Sat, 18 Feb 2023 00:35:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676709322; cv=none; d=google.com; s=arc-20160816; b=jo1f+8F1MsZTX+N38W31123eJ9Tejd5k35ag6Rb8VoakGzgTFOFOBEkx39TaZ7wYCq 25KubpTobxzdPz3IxQiEwHDH0/FdFTBVXf1k0iXuUAavQuqBhjj2SqLU4e65rSK4EKCJ 7csnAYzOxDmrN6hc2IhwpXdHkxX0rDWWcWMgBLl57SJxGcV4c1pSrPIta/TSeB49fUtJ sqPdpncJHbWJ/SaX2VFafj7D8RYuUMFcY+42rPWjR3DV4FvtTp19GrbHJ0MN2V6sHM6X 9eLEtfS+R43FU2L8Kc7MMvQx28qQNAp7I88zHM8Er4mMMit4lXDwsyHKC30q3+IVaToN sjKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=83BUsRlyLMUmvJw4YZ75s+hGHW8Vdn/b8sK6pmOtpKU=; b=f0QyhrVo7Bqd+Gf4w7FDBIN3z28AdBSVvPdoAQ3HodBmU+7F99nzyYDXzm2tookNiM 0pHpds9pA/KaDp0M4E4bVw34ljNRereYRXaB4G6jc3Y3zXWWrDgBIFZR5oqVsFORmCtF iQJTlMvww2DMajeG1QqMD10ho9kYUYo6HSG3CmaEyZLZL9AKpBaKIFX4n8IU3mJO7GnK 55uM3oMAWD6JYKw5/KI7ao3z801kEBzXa8PfssPuaQjXzSjYpWR8W0x3rE5ce3N8Le3/ 3qjMLO1/v0g1ugR3cHgDFgw+f4Isu1Bko3sxgZxZ9JWm7bWSVYEA7lDCl2wXMdFSXS+d En+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fp36-20020a1709069e2400b008b13f5bb248si7494168ejc.309.2023.02.18.00.34.59; Sat, 18 Feb 2023 00:35:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbjBRIKl (ORCPT <rfc822;daweilics@gmail.com> + 99 others); Sat, 18 Feb 2023 03:10:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjBRIKk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 18 Feb 2023 03:10:40 -0500 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 362F42B2B2 for <linux-kernel@vger.kernel.org>; Sat, 18 Feb 2023 00:10:38 -0800 (PST) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id TIIkp7w6pOJaFTIIlpYfjR; Sat, 18 Feb 2023 09:10:36 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 18 Feb 2023 09:10:36 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, virtualization@lists.linux-foundation.org Subject: [PATCH] virtio: Reorder fields in 'struct virtqueue' Date: Sat, 18 Feb 2023 09:10:31 +0100 Message-Id: <8f3d2e49270a2158717e15008e7ed7228196ba02.1676707807.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758157154702862341?= X-GMAIL-MSGID: =?utf-8?q?1758157154702862341?= |
Series |
virtio: Reorder fields in 'struct virtqueue'
|
|
Commit Message
Christophe JAILLET
Feb. 18, 2023, 8:10 a.m. UTC
Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size of 'struct virtqueue'
from 72 to 68 bytes.
It saves a few bytes of memory.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole
Before:
======
struct virtqueue {
struct list_head list; /* 0 16 */
void (*callback)(struct virtqueue *); /* 16 8 */
const char * name; /* 24 8 */
struct virtio_device * vdev; /* 32 8 */
unsigned int index; /* 40 4 */
unsigned int num_free; /* 44 4 */
unsigned int num_max; /* 48 4 */
/* XXX 4 bytes hole, try to pack */
void * priv; /* 56 8 */
/* --- cacheline 1 boundary (64 bytes) --- */
bool reset; /* 64 1 */
/* size: 72, cachelines: 2, members: 9 */
/* sum members: 61, holes: 1, sum holes: 4 */
/* padding: 7 */
/* last cacheline: 8 bytes */
};
After:
=====
struct virtqueue {
struct list_head list; /* 0 16 */
void (*callback)(struct virtqueue *); /* 16 8 */
const char * name; /* 24 8 */
struct virtio_device * vdev; /* 32 8 */
unsigned int index; /* 40 4 */
unsigned int num_free; /* 44 4 */
unsigned int num_max; /* 48 4 */
bool reset; /* 52 1 */
/* XXX 3 bytes hole, try to pack */
void * priv; /* 56 8 */
/* size: 64, cachelines: 1, members: 9 */
/* sum members: 61, holes: 1, sum holes: 3 */
};
---
include/linux/virtio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Saturday, February 18th, 2023 at 03:10, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > > Group some variables based on their sizes to reduce hole and avoid padding. > On x86_64, this shrinks the size of 'struct virtqueue' > from 72 to 68 bytes. > > It saves a few bytes of memory. > > Signed-off-by: Christophe JAILLET christophe.jaillet@wanadoo.fr > > --- > Using pahole > > Before: > ====== > struct virtqueue { > struct list_head list; /* 0 16 */ > void (*callback)(struct virtqueue ); / 16 8 / > const char * name; / 24 8 / > struct virtio_device * vdev; / 32 8 / > unsigned int index; / 40 4 / > unsigned int num_free; / 44 4 / > unsigned int num_max; / 48 4 / > > / XXX 4 bytes hole, try to pack / > > void * priv; / 56 8 / > / --- cacheline 1 boundary (64 bytes) --- / > bool reset; / 64 1 / > > / size: 72, cachelines: 2, members: 9 / > / sum members: 61, holes: 1, sum holes: 4 / > / padding: 7 / > / last cacheline: 8 bytes / > }; > > After: > ===== > struct virtqueue { > struct list_head list; / 0 16 */ > void (*callback)(struct virtqueue ); / 16 8 / > const char * name; / 24 8 / > struct virtio_device * vdev; / 32 8 / > unsigned int index; / 40 4 / > unsigned int num_free; / 44 4 / > unsigned int num_max; / 48 4 / > bool reset; / 52 1 / > > / XXX 3 bytes hole, try to pack / > > void * priv; / 56 8 / > > / size: 64, cachelines: 1, members: 9 / > / sum members: 61, holes: 1, sum holes: 3 */ > }; > --- > include/linux/virtio.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 6ac2655500dc..9439ae898310 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -35,8 +35,8 @@ struct virtqueue { > unsigned int index; > unsigned int num_free; > unsigned int num_max; > - void *priv; > bool reset; > + void *priv; > }; > > int virtqueue_add_outbuf(struct virtqueue *vq, > -- > 2.34.1 This will shrink the struct size on 32 bit archs too. Acked-by: Peter Lafreniere <peter@n8pjl.ca> - Peter
On Sat, Feb 18, 2023 at 09:10:31AM +0100, Christophe JAILLET wrote: >Group some variables based on their sizes to reduce hole and avoid padding. >On x86_64, this shrinks the size of 'struct virtqueue' >from 72 to 68 bytes. > >It saves a few bytes of memory. > >Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> >--- LGTM! Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> >Using pahole > >Before: >====== >struct virtqueue { > struct list_head list; /* 0 16 */ > void (*callback)(struct virtqueue *); /* 16 8 */ > const char * name; /* 24 8 */ > struct virtio_device * vdev; /* 32 8 */ > unsigned int index; /* 40 4 */ > unsigned int num_free; /* 44 4 */ > unsigned int num_max; /* 48 4 */ > > /* XXX 4 bytes hole, try to pack */ > > void * priv; /* 56 8 */ > /* --- cacheline 1 boundary (64 bytes) --- */ > bool reset; /* 64 1 */ > > /* size: 72, cachelines: 2, members: 9 */ > /* sum members: 61, holes: 1, sum holes: 4 */ > /* padding: 7 */ > /* last cacheline: 8 bytes */ >}; > >After: >===== >struct virtqueue { > struct list_head list; /* 0 16 */ > void (*callback)(struct virtqueue *); /* 16 8 */ > const char * name; /* 24 8 */ > struct virtio_device * vdev; /* 32 8 */ > unsigned int index; /* 40 4 */ > unsigned int num_free; /* 44 4 */ > unsigned int num_max; /* 48 4 */ > bool reset; /* 52 1 */ > > /* XXX 3 bytes hole, try to pack */ > > void * priv; /* 56 8 */ > > /* size: 64, cachelines: 1, members: 9 */ > /* sum members: 61, holes: 1, sum holes: 3 */ >}; >--- > include/linux/virtio.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/include/linux/virtio.h b/include/linux/virtio.h >index 6ac2655500dc..9439ae898310 100644 >--- a/include/linux/virtio.h >+++ b/include/linux/virtio.h >@@ -35,8 +35,8 @@ struct virtqueue { > unsigned int index; > unsigned int num_free; > unsigned int num_max; >- void *priv; > bool reset; >+ void *priv; > }; > > int virtqueue_add_outbuf(struct virtqueue *vq, >-- >2.34.1 >
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 6ac2655500dc..9439ae898310 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -35,8 +35,8 @@ struct virtqueue { unsigned int index; unsigned int num_free; unsigned int num_max; - void *priv; bool reset; + void *priv; }; int virtqueue_add_outbuf(struct virtqueue *vq,