Skip to contentSkip to conversation

hw/net,virtfs-proxy-helper: Reduce .data footprint

PATCH Applied Philippe Mathieu-Daudé 6 participants 12 messages Mar 5, 2020 – Mar 9, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/net,virtfs-proxy-helper: Reduce .data footprint

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Philippe Mathieu-Daudé (3):
hw/net/e1000: Add readops/writeops typedefs hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data
virtfs-proxy-helper: Make the helper_opts[] array const

 fsdev/virtfs-proxy-helper.c | 2 +-
 hw/net/e1000.c              | 6 ++++--
 hw/net/e1000e_core.c        | 6 ++++--
 3 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/3 hw/net/e1000: Add readops/writeops typedefs

Express the macreg[] arrays using typedefs.
No logical changes introduced here.

---
 hw/net/e1000.c       | 6 ++++--
 hw/net/e1000e_core.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/net/e1000.c +4 -2
index 0b833d5a15..972d9b5083 100644
@@ -1150,7 +1150,8 @@ set_ims(E1000State *s, int index, uint32_t val)
 }
 
 #define getreg(x)    [x] = mac_readreg
-static uint32_t (*macreg_readops[])(E1000State *, int) = {
+typedef uint32_t (*readops)(E1000State *, int);
+static readops macreg_readops[] = {
     getreg(PBA),      getreg(RCTL),     getreg(TDH),      getreg(TXDCTL),
     getreg(WUFC),     getreg(TDT),      getreg(CTRL),     getreg(LEDCTL),
     getreg(MANC),     getreg(MDIC),     getreg(SWSM),     getreg(STATUS),
@@ -1205,7 +1206,8 @@ static uint32_t (*macreg_readops[])(E1000State *, int) = {
 enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
 
 #define putreg(x)    [x] = mac_writereg
-static void (*macreg_writeops[])(E1000State *, int, uint32_t) = {
+typedef void (*writeops)(E1000State *, int, uint32_t);
+static writeops macreg_writeops[] = {
     putreg(PBA),      putreg(EERD),     putreg(SWSM),     putreg(WUFC),
     putreg(TDBAL),    putreg(TDBAH),    putreg(TXDCTL),   putreg(RDBAH),
     putreg(RDBAL),    putreg(LEDCTL),   putreg(VET),      putreg(FCRUC),
hw/net/e1000e_core.c +4 -2
index 94ea34dca5..38bdb90114 100644
@@ -2855,7 +2855,8 @@ e1000e_set_gcr(E1000ECore *core, int index, uint32_t val)
 }
 
 #define e1000e_getreg(x)    [x] = e1000e_mac_readreg
-static uint32_t (*e1000e_macreg_readops[])(E1000ECore *, int) = {
+typedef uint32_t (*readops)(E1000ECore *, int);
+static readops e1000e_macreg_readops[] = {
     e1000e_getreg(PBA),
     e1000e_getreg(WUFC),
     e1000e_getreg(MANC),
@@ -3061,7 +3062,8 @@ static uint32_t (*e1000e_macreg_readops[])(E1000ECore *, int) = {
 enum { E1000E_NREADOPS = ARRAY_SIZE(e1000e_macreg_readops) };
 
 #define e1000e_putreg(x)    [x] = e1000e_mac_writereg
-static void (*e1000e_macreg_writeops[])(E1000ECore *, int, uint32_t) = {
+typedef void (*writeops)(E1000ECore *, int, uint32_t);
+static writeops e1000e_macreg_writeops[] = {
     e1000e_putreg(PBA),
     e1000e_putreg(SWSM),
     e1000e_putreg(WUFC),
Signature · 1 line
2.21.1
#3 lore raw

PATCH 2/3 hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data

In reply to Philippe Mathieu-Daudé

Each array consumes 256KiB of .data. As we do not reassign entries, we can move it to the .rodata section, and save a total of 1MiB of .data (size reported on x86_64 host).

---
 hw/net/e1000.c       | 4 ++--
 hw/net/e1000e_core.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/net/e1000.c +2 -2
index 972d9b5083..9233248c9a 100644
@@ -1151,7 +1151,7 @@ set_ims(E1000State *s, int index, uint32_t val)
 
 #define getreg(x)    [x] = mac_readreg
 typedef uint32_t (*readops)(E1000State *, int);
-static readops macreg_readops[] = {
+static const readops macreg_readops[] = {
     getreg(PBA),      getreg(RCTL),     getreg(TDH),      getreg(TXDCTL),
     getreg(WUFC),     getreg(TDT),      getreg(CTRL),     getreg(LEDCTL),
     getreg(MANC),     getreg(MDIC),     getreg(SWSM),     getreg(STATUS),
@@ -1207,7 +1207,7 @@ enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
 
 #define putreg(x)    [x] = mac_writereg
 typedef void (*writeops)(E1000State *, int, uint32_t);
-static writeops macreg_writeops[] = {
+static const writeops macreg_writeops[] = {
     putreg(PBA),      putreg(EERD),     putreg(SWSM),     putreg(WUFC),
     putreg(TDBAL),    putreg(TDBAH),    putreg(TXDCTL),   putreg(RDBAH),
     putreg(RDBAL),    putreg(LEDCTL),   putreg(VET),      putreg(FCRUC),
hw/net/e1000e_core.c +2 -2
index 38bdb90114..df957e0c1a 100644
@@ -2856,7 +2856,7 @@ e1000e_set_gcr(E1000ECore *core, int index, uint32_t val)
 
 #define e1000e_getreg(x)    [x] = e1000e_mac_readreg
 typedef uint32_t (*readops)(E1000ECore *, int);
-static readops e1000e_macreg_readops[] = {
+static const readops e1000e_macreg_readops[] = {
     e1000e_getreg(PBA),
     e1000e_getreg(WUFC),
     e1000e_getreg(MANC),
@@ -3063,7 +3063,7 @@ enum { E1000E_NREADOPS = ARRAY_SIZE(e1000e_macreg_readops) };
 
 #define e1000e_putreg(x)    [x] = e1000e_mac_writereg
 typedef void (*writeops)(E1000ECore *, int, uint32_t);
-static writeops e1000e_macreg_writeops[] = {
+static const writeops e1000e_macreg_writeops[] = {
     e1000e_putreg(PBA),
     e1000e_putreg(SWSM),
     e1000e_putreg(WUFC),
Signature · 1 line
2.21.1
#5 lore raw

PATCH 3/3 virtfs-proxy-helper: Make the helper_opts[] array const

In reply to Philippe Mathieu-Daudé

Reduce a bit the memory footprint by making the helper_opts[] array const.

---
 fsdev/virtfs-proxy-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsdev/virtfs-proxy-helper.c +1 -1
index aa1ab2590d..de061a8a0e 100644
@@ -43,7 +43,7 @@
 #define BTRFS_SUPER_MAGIC 0x9123683E
 #endif
 
-static struct option helper_opts[] = {
+static const struct option helper_opts[] = {
     {"fd", required_argument, NULL, 'f'},
     {"path", required_argument, NULL, 'p'},
     {"nodaemon", no_argument, NULL, 'n'},
Signature · 1 line
2.21.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Each array consumes 256KiB of .data. As we do not reassign entries, we can move it to the .rodata section, and save a total of 1MiB of .data (size reported on x86_64 host).

Quoted 52 lines

---
hw/net/e1000.c | 4 ++--
hw/net/e1000e_core.c | 4 ++--

2 files changed, 4 insertions(+), 4 deletions(-)
hw/net/e1000.c +2 -2
index 972d9b5083..9233248c9a 100644
@@ -1151,7 +1151,7 @@ set_ims(E1000State *s, int index, uint32_t val)
 
 #define getreg(x)    [x] = mac_readreg
 typedef uint32_t (*readops)(E1000State *, int);
-static readops macreg_readops[] = {
+static const readops macreg_readops[] = {
    getreg(PBA),      getreg(RCTL),     getreg(TDH),      getreg(TXDCTL),
    getreg(WUFC),     getreg(TDT),      getreg(CTRL),     getreg(LEDCTL),
    getreg(MANC),     getreg(MDIC),     getreg(SWSM),     getreg(STATUS),
@@ -1207,7 +1207,7 @@ enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
 
 #define putreg(x)    [x] = mac_writereg
 typedef void (*writeops)(E1000State *, int, uint32_t);
-static writeops macreg_writeops[] = {
+static const writeops macreg_writeops[] = {
    putreg(PBA),      putreg(EERD),     putreg(SWSM),     putreg(WUFC),
    putreg(TDBAL),    putreg(TDBAH),    putreg(TXDCTL),   putreg(RDBAH),
    putreg(RDBAL),    putreg(LEDCTL),   putreg(VET),      putreg(FCRUC),
hw/net/e1000e_core.c +2 -2
index 38bdb90114..df957e0c1a 100644
@@ -2856,7 +2856,7 @@ e1000e_set_gcr(E1000ECore *core, int index, uint32_t val)
 
 #define e1000e_getreg(x)    [x] = e1000e_mac_readreg
 typedef uint32_t (*readops)(E1000ECore *, int);
-static readops e1000e_macreg_readops[] = {
+static const readops e1000e_macreg_readops[] = {
    e1000e_getreg(PBA),
    e1000e_getreg(WUFC),
    e1000e_getreg(MANC),
@@ -3063,7 +3063,7 @@ enum { E1000E_NREADOPS = ARRAY_SIZE(e1000e_macreg_readops) };
 
 #define e1000e_putreg(x)    [x] = e1000e_mac_writereg
 typedef void (*writeops)(E1000ECore *, int, uint32_t);
-static writeops e1000e_macreg_writeops[] = {
+static const writeops e1000e_macreg_writeops[] = {
    e1000e_putreg(PBA),
    e1000e_putreg(SWSM),
    e1000e_putreg(WUFC),
Signature · 1 line
2.21.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] hw/net/e1000: Add readops/writeops typedefs

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Express the macreg[] arrays using typedefs.
No logical changes introduced here.

Quoted 56 lines

---
hw/net/e1000.c | 6 ++++--
hw/net/e1000e_core.c | 6 ++++--

2 files changed, 8 insertions(+), 4 deletions(-)
hw/net/e1000.c +4 -2
index 0b833d5a15..972d9b5083 100644
@@ -1150,7 +1150,8 @@ set_ims(E1000State *s, int index, uint32_t val)
 }
 
 #define getreg(x)    [x] = mac_readreg
-static uint32_t (*macreg_readops[])(E1000State *, int) = {
+typedef uint32_t (*readops)(E1000State *, int);
+static readops macreg_readops[] = {
    getreg(PBA),      getreg(RCTL),     getreg(TDH),      getreg(TXDCTL),
    getreg(WUFC),     getreg(TDT),      getreg(CTRL),     getreg(LEDCTL),
    getreg(MANC),     getreg(MDIC),     getreg(SWSM),     getreg(STATUS),
@@ -1205,7 +1206,8 @@ static uint32_t (*macreg_readops[])(E1000State *, int) = {
 enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
 
 #define putreg(x)    [x] = mac_writereg
-static void (*macreg_writeops[])(E1000State *, int, uint32_t) = {
+typedef void (*writeops)(E1000State *, int, uint32_t);
+static writeops macreg_writeops[] = {
    putreg(PBA),      putreg(EERD),     putreg(SWSM),     putreg(WUFC),
    putreg(TDBAL),    putreg(TDBAH),    putreg(TXDCTL),   putreg(RDBAH),
    putreg(RDBAL),    putreg(LEDCTL),   putreg(VET),      putreg(FCRUC),
hw/net/e1000e_core.c +4 -2
index 94ea34dca5..38bdb90114 100644
@@ -2855,7 +2855,8 @@ e1000e_set_gcr(E1000ECore *core, int index, uint32_t val)
 }
 
 #define e1000e_getreg(x)    [x] = e1000e_mac_readreg
-static uint32_t (*e1000e_macreg_readops[])(E1000ECore *, int) = {
+typedef uint32_t (*readops)(E1000ECore *, int);
+static readops e1000e_macreg_readops[] = {
    e1000e_getreg(PBA),
    e1000e_getreg(WUFC),
    e1000e_getreg(MANC),
@@ -3061,7 +3062,8 @@ static uint32_t (*e1000e_macreg_readops[])(E1000ECore *, int) = {
 enum { E1000E_NREADOPS = ARRAY_SIZE(e1000e_macreg_readops) };
 
 #define e1000e_putreg(x)    [x] = e1000e_mac_writereg
-static void (*e1000e_macreg_writeops[])(E1000ECore *, int, uint32_t) = {
+typedef void (*writeops)(E1000ECore *, int, uint32_t);
+static writeops e1000e_macreg_writeops[] = {
    e1000e_putreg(PBA),
    e1000e_putreg(SWSM),
    e1000e_putreg(WUFC),
Signature · 1 line
2.21.1
Reviewed-by on the v1 series
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Thanks to share these links!

Quoted 10 lines

Philippe Mathieu-Daudé (3):
hw/net/e1000: Add readops/writeops typedefs hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data
virtfs-proxy-helper: Make the helper_opts[] array const

 fsdev/virtfs-proxy-helper.c | 2 +-
 hw/net/e1000.c              | 6 ++++--
 hw/net/e1000e_core.c        | 6 ++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

Cool and clear changes!

Thanks,
Stefano

Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] virtfs-proxy-helper: Make the helper_opts[] array const

In reply to Philippe Mathieu-Daudé
Quoted 3 lines · On Thu, 5 Mar 2020 02:04:46 +0100 Philippe Mathieu-Daudé <[email protected]>…

Reduce a bit the memory footprint by making the helper_opts[] array const.

... and, maybe most importantly, make it clear helper_opts[] is not supposed to be modified at runtime.

Quoted 2 lines

---

Assuming this goes to the trivial tree:

Quoted 16 lines
 fsdev/virtfs-proxy-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsdev/virtfs-proxy-helper.c +1 -1
index aa1ab2590d..de061a8a0e 100644
@@ -43,7 +43,7 @@
 #define BTRFS_SUPER_MAGIC 0x9123683E
 #endif
 
-static struct option helper_opts[] = {
+static const struct option helper_opts[] = {
     {"fd", required_argument, NULL, 'f'},
     {"path", required_argument, NULL, 'p'},
     {"nodaemon", no_argument, NULL, 'n'},
#8 lore raw
In reply to Stefano Garzarella
Quoted 11 lines · Stefano Garzarella
Quoted 8 lines · Philippe Mathieu-Daudé

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Thanks to share these links!

FYI the heap equivalent (besides that more powerful) is:
https://github.com/KDE/heaptrack

Quoted 19 lines
Quoted 11 lines

Philippe Mathieu-Daudé (3):

   hw/net/e1000: Add readops/writeops typedefs
   hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data
   virtfs-proxy-helper: Make the helper_opts[] array const
  fsdev/virtfs-proxy-helper.c | 2 +-
  hw/net/e1000.c              | 6 ++++--
  hw/net/e1000e_core.c        | 6 ++++--
  3 files changed, 9 insertions(+), 5 deletions(-)

Cool and clear changes!

Thanks,
Stefano

#9 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Stefano Garzarella
Quoted 5 lines · Philippe Mathieu-Daudé

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Thanks to share these links!

FYI the heap equivalent (besides that more powerful) is:
https://github.com/KDE/heaptrack

Cool, thanks!

Previously I used valgrind's massif tool to track the heap, but I'll try heaptrack.

Cheers,
Stefano

Acked-by on the v1 series
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Philippe Mathieu-Daudé (3):
hw/net/e1000: Add readops/writeops typedefs hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data
virtfs-proxy-helper: Make the helper_opts[] array const

Quoted 5 lines
 fsdev/virtfs-proxy-helper.c | 2 +-
 hw/net/e1000.c              | 6 ++++--
 hw/net/e1000e_core.c        | 6 ++++--
 3 files changed, 9 insertions(+), 5 deletions(-)

These can certainly go through qemu-trivial.

Paolo

#11 lore raw

Le 06/03/2020 à 10:25, Paolo Bonzini a écrit :

Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 13 lines

More memory footprint reduction, similar to:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00984.html

The elf-dissector tool [1] [2] helped to notice the big array.

[1] https://phabricator.kde.org/source/elf-dissector/
[2] https://www.volkerkrause.eu/2019/06/22/elf-dissector-aarch64-support.html

Philippe Mathieu-Daudé (3):
hw/net/e1000: Add readops/writeops typedefs hw/net/e1000: Move macreg[] arrays to .rodata to save 1MiB of .data
virtfs-proxy-helper: Make the helper_opts[] array const

Quoted 5 lines
 fsdev/virtfs-proxy-helper.c | 2 +-
 hw/net/e1000.c              | 6 ++++--
 hw/net/e1000e_core.c        | 6 ++++--
 3 files changed, 9 insertions(+), 5 deletions(-)
Quoted 3 lines

These can certainly go through qemu-trivial.

Applied to my trivial-patches branch.

Thanks,
Laurent