From 55287c9f9a689c3c6e917b7e6b5c8774893a3f88 Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Wed, 23 Aug 2023 23:57:05 +0200 Subject: [PATCH] northd: Fix incorrect memory allocation for router group datapaths. We need to allocate memory for 'n_router_dps' pointers, but the current code allocates space for 'n_router_dps' datapaths, which is 762 byte structure. Having 5000 routers in the OpenStack setup, we allocate 762 * 5000 * 5000 ~= 17 GB of memory instead of 190 MB: 98.17% (19,962,746,247B) (heap allocation functions) ->90.67% (18,436,818,400B) xcalloc__ (util.c:124) ->90.67% (18,436,818,400B) xcalloc (util.c:161) ->90.67% (18,436,818,400B) build_lrouter_groups (northd.c:8707) ->90.67% (18,436,818,400B) ovnnb_db_run (northd.c:17611) ->90.67% (18,436,818,400B) en_northd_run (en-northd.c:137) ->90.67% (18,436,818,400B) engine_recompute (inc-proc-eng.c:415) ->90.67% (18,436,818,400B) engine_run_node (inc-proc-eng.c:477) ->90.67% (18,436,818,400B) engine_run (inc-proc-eng.c:528) ->90.67% (18,436,818,400B) inc_proc_northd_run (inc-proc-northd.c:316) ->90.67% (18,436,818,400B) main (ovn-northd.c:937) Also, even though this doesn't affect the allocation size, the order of arguments is incorrect. Fix that by using correct pointers and order. That saves a huge amount of memory as well as time on allocating and zeroing it out. In my testing northd node saved 10 seconds on these allocations. Fixes: b82d351976a1 ("ovn: Add generic HA chassis group") Signed-off-by: Ilya Maximets Acked-by: Mark Michelson Signed-off-by: Mark Michelson --- northd/northd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/northd/northd.c b/northd/northd.c index 66f14e9dd2..4d3646d106 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -7869,7 +7869,8 @@ build_lrouter_groups(struct hmap *ports, struct ovs_list *lr_list) od->lr_group = xzalloc(sizeof *od->lr_group); /* Each logical router group can have max * 'n_router_dps'. So allocate enough memory. */ - od->lr_group->router_dps = xcalloc(sizeof *od, n_router_dps); + od->lr_group->router_dps = + xcalloc(n_router_dps, sizeof *od->lr_group->router_dps); od->lr_group->router_dps[0] = od; od->lr_group->n_router_dps = 1; sset_init(&od->lr_group->ha_chassis_groups);