Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1664689rwd; Tue, 16 May 2023 22:42:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OCw8l9+s5qcxb9SiOBLrYf9nymrKOyXklpRAhVFRqvWQkOAS28D9wHP7ApupYcmsnxuKY X-Received: by 2002:a17:903:1249:b0:1ab:220a:9068 with SMTP id u9-20020a170903124900b001ab220a9068mr52300423plh.42.1684302133659; Tue, 16 May 2023 22:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684302133; cv=none; d=google.com; s=arc-20160816; b=c+gcM4B0ttPe3Q2ir3KB3Z+dwVEtbKxh7i240QV+3SfxcLyPPnTBzHtygPZwOO/w8w tH0ZxO9oiREzH0jMgoeOx7zyT/tFD/JN40m6UYXuS10eJJIHdsfmetKhRNQsGUL33uhQ BSTxiiXrpD4lJgTkhCJWYtoke+b3lxdewvhQtAo13Ls2kLbeK9hEGBBogi31kPBQZTUV u+7y5U3qSh5aNM+vwKPqCNKntTykJOWrJL2xjZuHkWaYrzAGS1kSgxdXU2ZcSF1rNkvD H9+wGcvinHppuoLeIIjqqE/CYyySXvFq0b7QLK7L4wwB0BSPRdbPJgBG4ZPmwarnIfAg TYYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=t2TQmhlyr4qpfepuY+DlN4KamSzGRCNW1CGNN09KiW0=; b=MZ6XF1p7y3aRQjQbLwksekcIax+UZ1tqUt++m2upcZaRVr/06d8XmJKchHhElBJmbv /OtCG3ITuApvTlRjcLgjoLVWsmB26MawIDMZxyApTQey06YTcK7isRG/x+uTsiVSnWK3 X82FEQg4+/yYS30ChLl0UtQXOginSfOI7+z3FPZkcJgdmhRphrkvo9cEfOKsJlxtBFgQ 59mX8bcqhcgF5tPONSR5rlkx/ykJVjSYftbwKAjzFhRIRNUHj/ZFiUbOGuqgH56Tf9b+ tpMaX7dPwWJ7Xb9B66GlNE4mdWkKpsXga+Lp9y5P4zQzKxfhBKhzAIcykaY3tDW/NgWY RXkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=esCEDrkv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a17090341cb00b001ac36e5ec0esi11506049ple.299.2023.05.16.22.42.01; Tue, 16 May 2023 22:42:13 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=esCEDrkv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232231AbjEQFY5 (ORCPT + 99 others); Wed, 17 May 2023 01:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjEQFYz (ORCPT ); Wed, 17 May 2023 01:24:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3D613C25 for ; Tue, 16 May 2023 22:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684301045; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t2TQmhlyr4qpfepuY+DlN4KamSzGRCNW1CGNN09KiW0=; b=esCEDrkv6XDvIWCerh+ijARKvqfGWdYfLpnH0WaU6gGbzZpwyEO7FZb9ATj7JdObYGxqsX Bi8DVsbM6Fy9BdaTcfIlXbUXxvnqHpgXVxc7u5r0AY31t/SGz6Wb2i0SifTlBPbyWiXnIL KJNQD9JIZBpZruy2G4DtvmeH0ZCRCK0= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-388kzGULMry5tqUuDu0H7w-1; Wed, 17 May 2023 01:24:03 -0400 X-MC-Unique: 388kzGULMry5tqUuDu0H7w-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-4f3907d04dcso252479e87.2 for ; Tue, 16 May 2023 22:24:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684301042; x=1686893042; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t2TQmhlyr4qpfepuY+DlN4KamSzGRCNW1CGNN09KiW0=; b=eD6lqLy4TKjgOSbC5uQJK9q0PFYL6OBSc4wUHvuPN7f2nTHYSMFzH2kpq9+OIC6W8v ZJXe/F7yj+SsHu+wL1uZx/kvnIem7kyNN+QT0bJmkbTclmhDGOTbJZeidQoKCzylI+WC 6HzceVzEUgVvziIXbQt4sO5BA3S8+aqzbmE3RrqCe88TR/PSw8J0/HkONw5vEfBrvL3j qIZpi7fbWd8SN5s8XqPboFgmJD3ESvZia24cCLZSbQT83Cf5skwD2TAvNdhzTR3rGrhv M+VBz7+95Ux6niDKQezMI8PcPIDfYnvCtrfgxi4YjkWoUxH3DjPQ2O0msB5UyswAs+lg 2Z6w== X-Gm-Message-State: AC+VfDyORM65nFUd6qbi1an/hmqijWOLGK4SelCpCGlis1AQazikp3YM rhxE+wlcz8LVwoT2h1luD+BuXe2il1EGl6eeqc0u7Lj3mj5skIAMrTaXUmaVhEtcP6BFbCu+FWB uasA2N2IXj0x7CQXAW0yQUVuctAzNcLKy/iO/LYN/ X-Received: by 2002:ac2:598c:0:b0:4f3:83d6:f22c with SMTP id w12-20020ac2598c000000b004f383d6f22cmr2314502lfn.66.1684301042055; Tue, 16 May 2023 22:24:02 -0700 (PDT) X-Received: by 2002:ac2:598c:0:b0:4f3:83d6:f22c with SMTP id w12-20020ac2598c000000b004f383d6f22cmr2314490lfn.66.1684301041754; Tue, 16 May 2023 22:24:01 -0700 (PDT) MIME-Version: 1.0 References: <20230516135446.16266-1-feliu@nvidia.com> In-Reply-To: <20230516135446.16266-1-feliu@nvidia.com> From: Jason Wang Date: Wed, 17 May 2023 13:23:50 +0800 Message-ID: Subject: Re: [PATCH v1] virtio_pci: Optimize virtio_pci_device structure size To: Feng Liu Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Michael S . Tsirkin" , Xuan Zhuo , Bodong Wang , Jiri Pirko Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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, May 16, 2023 at 9:55=E2=80=AFPM 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 Acked-by: Jason Wang 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_p= ci_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) >