Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1483620rwd; Tue, 16 May 2023 18:40:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ595w9R/2vqYkD38HoXfBW4krwPmtqPRxZJhvxkA78QcbEv99TQwkUJceC55f3NcVhvLrVb X-Received: by 2002:a17:903:2092:b0:1ac:8e0b:282c with SMTP id d18-20020a170903209200b001ac8e0b282cmr27075340plc.1.1684287657286; Tue, 16 May 2023 18:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684287657; cv=none; d=google.com; s=arc-20160816; b=ywqjzRjPEQBwy3P80ZmYhe9gabkf9uRI3NOfLupY4++AZHvTJZ74jEwes/BaE70frv 9e0okRqMVrUFlqkd3ZI/pd4SUzgryhmFP0+VKopLptU1IWAnIayp3rpeEVlVfblGwfzV nJVyLzZ3o42OyM0nwnu4LsGws9txQ0fVpqdd95K8Vqcm+H2goeXxpw5oVx6Zj5QKqvLh cOpbdAHODZQBWeRXLDsoJQG20xaqW7atFjY9X5g3VXlLNZLMLXVDSecfurAP2wahjes+ t6SdBzXKNZWEqy6hRH/+5B6VPzDP15YUveCqZxu4Uir3PW6PQptIgbCXmlJjOnH7ZCYp Mchg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:cc:to:from:date:subject :message-id; bh=PubIh8c0X8lAx4O/Gu+Rs0wmoG0kbCSl7Cf5/0USumc=; b=cK3Gk6zC1wNFNjquXwesxp3hWpNgaHaU+NtaTWL0SBv6HvCf+V/0cgS0aGyLOPHPPT SOnSyxE/4gLbG8fzFLxx36IgoxURwcnGYA2RuyNpr4U0u4zgIO6HolXhl18rNESwH9tX rvVO5XVk8UweMvbEYbRlZWoTGVSGYX8AwgE3iiW46sjJnDmx6OA6DD+0jhF1Y1fDR0TU nPx8ooQu7GsbCLR+buV6oiVfLcOgJCGRDIbr2zFzIAKJY4u0rL1WhYUNaH1+WKFvaQ/s KY9Px6JYiJW1pxh8UmDV2/pjJ/FTcS7secQlRsa9S8CZf3fMlNbJ0elRMXCHNHr2Af/K oZIQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a170902900c00b001a94429df88si18666804plp.123.2023.05.16.18.40.45; Tue, 16 May 2023 18:40:57 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbjEQBcw (ORCPT + 99 others); Tue, 16 May 2023 21:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjEQBcv (ORCPT ); Tue, 16 May 2023 21:32:51 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89B0C3A80; Tue, 16 May 2023 18:32:50 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0ViqT6U4_1684287167; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0ViqT6U4_1684287167) by smtp.aliyun-inc.com; Wed, 17 May 2023 09:32:48 +0800 Message-ID: <1684287159.5055063-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size Date: Wed, 17 May 2023 09:32:39 +0800 From: Xuan Zhuo To: Feng Liu Cc: Jason Wang , "Michael S . Tsirkin" , Bodong Wang , Feng Liu , Jiri Pirko , , , References: <20230516135446.16266-1-feliu@nvidia.com> In-Reply-To: <20230516135446.16266-1-feliu@nvidia.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 May 2023 09:54:46 -0400, Feng Liu wrote: > Improve the size of the virtio_pci_device structure, which is commonly > used to represent a virtio PCI device. A given virtio PCI device can > either of legacy type or modern type, with the > struct virtio_pci_legacy_device occupying 32 bytes and the > struct virtio_pci_modern_device occupying 88 bytes. Make them a union, > thereby save 32 bytes of memory as shown by the pahole tool. This > improvement is particularly beneficial when dealing with numerous > devices, as it helps conserve memory resources. > > Before the modification, pahole tool reported the following: > struct virtio_pci_device { > [...] > struct virtio_pci_legacy_device ldev; /* 824 32 */ > /* --- cacheline 13 boundary (832 bytes) was 24 bytes ago --- */ > struct virtio_pci_modern_device mdev; /* 856 88 */ > > /* XXX last struct has 4 bytes of padding */ > [...] > /* size: 1056, cachelines: 17, members: 19 */ > [...] > }; > > After the modification, pahole tool reported the following: > struct virtio_pci_device { > [...] > union { > struct virtio_pci_legacy_device ldev; /* 824 32 */ > struct virtio_pci_modern_device mdev; /* 824 88 */ > }; /* 824 88 */ > [...] > /* size: 1024, cachelines: 16, members: 18 */ > [...] > }; > > Signed-off-by: Feng Liu > Reviewed-by: Jiri Pirko Reviewed-by: Xuan Zhuo Thanks. > --- > drivers/virtio/virtio_pci_common.h | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/virtio/virtio_pci_common.h b/drivers/virtio/virtio_pci_common.h > index 23112d84218f..4b773bd7c58c 100644 > --- a/drivers/virtio/virtio_pci_common.h > +++ b/drivers/virtio/virtio_pci_common.h > @@ -45,9 +45,10 @@ struct virtio_pci_vq_info { > struct virtio_pci_device { > struct virtio_device vdev; > struct pci_dev *pci_dev; > - struct virtio_pci_legacy_device ldev; > - struct virtio_pci_modern_device mdev; > - > + union { > + struct virtio_pci_legacy_device ldev; > + struct virtio_pci_modern_device mdev; > + }; > bool is_legacy; > > /* Where to read and clear interrupt */ > -- > 2.37.1 (Apple Git-137.1) >