From: "Daniel P. Berrangé" <berrange@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: input-keymap sizes
Date: Thu, 5 Nov 2026 09:06:43 +0000 [thread overview]
Message-ID: <auxF28W4dhEoqxWZ@redhat.com> (raw)
In-Reply-To: <CAFn=p-Z=RGEO-sTgRR549LkQbdfjR-zfnb8GASV8XnQf4TrwAw@mail.gmail.com>
On Wed, Nov 04, 2026 at 05:16:03PM -0500, John Snow wrote:
> Heya!
>
> I've been looking into producing minimal QEMU configurations for
> sandboxing, and as part of that, I've been auditing "what exactly
> takes up room in our QEMU binary?"
>
> One of the things that came up was that input-keymap.c burns over 250
> KiB of .rodata all by itself; all of the keymaps we generate for QEMU
> are included statically in one big blob and are linked with every last
> build.
>
> There's a few things we could do about this;
>
> (1) We can split out each keymap into its own object file, which
> allows us to link only the keymaps we need for the features we have
> enabled. Dan Berrange wrote a quite POC for this and the results look
> good at a glance. We need new linker flags to automatically prune
> unused keymaps from the build, or enhanced meson-fu to
> deterministically exclude them. Either way, it's likely a worthwhile
> pursuit. In a microvm-only build configuration I've been testing with,
> this immediately dropped us from 250KiB to 180KiB.
>
> (2) The x11 keymap used by ui/input-barrier.c and ui/gtk.c - all by
> itself - consumes 128KIB for its keymap. This is because although the
> x11_to_linux keymap has fewer than 512 total entries, it allocates
> this in a const array with 64K entries in it so it can span keycodes
> 0x00 to 0xff and 0xff00 to 0xffff.
>
> It's the second one I am concerned about.
But can the first one solve the second one ? In your sandbox use
case, presumably you don't need the GTK graphical frontend, and
so if GTK is dropped from the minimal build config there's no need
to link in the X11 keymap and thus (1) fixes the problem.
> At first I thought that I
> might be able to write a "condensed" table that uses 0 - 255 and then
> remaps 65,280 - 65,535 onto 256-511 and then take (index & 0x1ff) on
> lookup table input, but I realize that the entire unmodified table is
> passed off to gd_get_keymap() in ui/gtk.c where I can't inject those
> index transformations.
Bear in mind all these keymaps tables are auto-generated by a tool
that is used by many applications
> Does anyone have any suggestions on how to help shave the x11_to_linux
> keymap down to a more reasonable size? I doubt we need 128KB when 1KB
> could theoretically hold everything we need.
That's binary size, but presumably not all those pages are mapped.
We won't access every index in the table so many pages won't get
faulted in to RAM.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
prev parent reply other threads:[~2026-11-05 9:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 22:16 input-keymap sizes John Snow
2026-11-05 9:06 ` Daniel P. Berrangé [this message]
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=auxF28W4dhEoqxWZ@redhat.com \
--to=berrange@redhat.com \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.