qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>,
	qemu-trivial@nongnu.org, Jason Wang <jasowang@redhat.com>,
	Christian Schoenebeck <qemu_oss@crudebyte.com>,
	qemu-devel@nongnu.org, Greg Kurz <groug@kaod.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>
Subject: Re: [PATCH v2 0/9] hw, ui, virtfs-proxy-helper: Reduce QEMU .data/.rodata/.bss footprint
Date: Thu, 5 Mar 2020 08:32:20 -0600	[thread overview]
Message-ID: <5bcca2de-16bc-4026-23cc-1bf3f18cf9a2@redhat.com> (raw)
In-Reply-To: <20200305134229.GB2112347@redhat.com>

On 3/5/20 7:42 AM, Daniel P. Berrangé wrote:
> On Thu, Mar 05, 2020 at 01:45:16PM +0100, Philippe Mathieu-Daudé wrote:
>> Since v1:
>> - merged 2 series
>> - reworked hw/usb/quirks
>> - added R-b/A-b tags
>>
>> This series reduce the footprint of the QEMU binary:
>> .bss: 106KiB (moved to .heap)
> 
> Did this actually have an impact on the binary size, or just on the
> size the elf-dissector reports ?  I'm not very familiar with ELF,
> but Wikipedia's description of BSS makes me question it...
> 
>    "Typically only the length of the bss section, but no data,
>     is stored in the object file. The program loader allocates
>     memory for the bss section when it loads the program. On
>     some platforms, some or all of the bss section is initialized
>     to zeroes. Unix-like systems and Windows initialize the bss
>     section to zero"
> 
> This suggests .bss has no on-disk overhead, only runtime overhead,
> which is presumably going to be the same with heap allocations.

Or even LESS overhead.  Heap allocationhave unspecified contents 
requiring runtime effort (true, some implementations of malloc() handle 
large allocations specially as anonymous mmap initially backed by 
/dev/zero, so that those allocations start life 0-allocated, but you 
can't rely on that optimization), while .bss is required by the C 
language to be 0 initialized (and you CAN rely on the OS implementing 
that as efficiently as possible, generally by starting with COW mapping 
initially backed by the zero page).

In fact, on nbdkit, we hit an interesting case where using .bss instead 
of .rodata is actually beneficial:
https://www.redhat.com/archives/libguestfs/2019-July/msg00074.html
Marking a large array that will always consist only of zero bytes as 
const actually pessimized the image size and load time, because the 
addition of const moved the array from .bss into .rodata.

> 
>> .data: 1MiB
>> .rodata: 4.34MiB
> 
> These looks useful though in terms of disk footprint.

Yes. Smaller data structures allow for smaller binaries and faster loading.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  parent reply	other threads:[~2020-03-05 14:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05 12:45 [PATCH v2 0/9] hw, ui, virtfs-proxy-helper: Reduce QEMU .data/.rodata/.bss footprint Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 1/9] hw/audio/fmopl: Fix a typo twice Philippe Mathieu-Daudé
2020-03-05 13:38   ` Stefano Garzarella
2020-03-09 11:36   ` Laurent Vivier
2020-03-05 12:45 ` [PATCH v2 2/9] hw/audio/fmopl: Move ENV_CURVE to .heap to save 32KiB of .bss Philippe Mathieu-Daudé
2020-03-05 13:44   ` Stefano Garzarella
2020-03-05 13:48     ` Stefano Garzarella
2020-03-05 13:50       ` Philippe Mathieu-Daudé
2020-03-05 13:59         ` Stefano Garzarella
2020-03-05 13:49     ` Philippe Mathieu-Daudé
2020-03-05 13:54       ` Daniel P. Berrangé
2020-03-05 12:45 ` [PATCH v2 3/9] hw/audio/intel-hda: Use memory region alias to reduce .rodata by 4.34MB Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 4/9] hw/net/e1000: Add readops/writeops typedefs Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 5/9] hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 6/9] hw/usb/quirks: Use smaller types to reduce .rodata by 10KiB Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 7/9] ui/curses: Make control_characters[] array const Philippe Mathieu-Daudé
2020-03-05 13:46   ` Stefano Garzarella
2020-03-05 12:45 ` [PATCH v2 8/9] ui/curses: Move arrays to .heap to save 74KiB of .bss Philippe Mathieu-Daudé
2020-03-05 12:45 ` [PATCH v2 9/9] virtfs-proxy-helper: Make the helper_opts[] array const Philippe Mathieu-Daudé
2020-03-05 13:15 ` [PATCH v2 0/9] hw, ui, virtfs-proxy-helper: Reduce QEMU .data/.rodata/.bss footprint no-reply
2020-03-05 13:25 ` no-reply
2020-03-05 13:42 ` Daniel P. Berrangé
2020-03-05 13:56   ` Philippe Mathieu-Daudé
2020-03-05 14:34     ` Eric Blake
2020-03-05 14:32   ` Eric Blake [this message]
2020-03-05 13:48 ` no-reply
2020-03-05 14:21 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5bcca2de-16bc-4026-23cc-1bf3f18cf9a2@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=sgarzare@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).