From: Theo Buehler Subject: Re: bgpd: resize communities with reallocarray To: tech@openbsd.org Date: Thu, 13 Nov 2025 16:02:33 +0100 On Thu, Nov 13, 2025 at 04:00:06PM +0100, Claudio Jeker wrote: > insert_community() is part of the hot path especially when people use > communities to tag internally for their filters. > Using recallocarray() there is a bit problematic since it has a much > higher overhead than any realloc verision. > Use reallocarray() and memset() instead. > > In one of my IXP test setups insert_community is called 224 million times > during initial sync. ouch. ok tb > -- > :wq Claudio > > Index: rde_community.c > =================================================================== > RCS file: /cvs/src/usr.sbin/bgpd/rde_community.c,v > diff -u -p -r1.18 rde_community.c > --- rde_community.c 4 Nov 2025 14:43:22 -0000 1.18 > +++ rde_community.c 13 Nov 2025 14:28:42 -0000 > @@ -227,9 +227,10 @@ insert_community(struct rde_community *c > struct community *new; > int newsize = comm->size + 8; > > - if ((new = recallocarray(comm->communities, comm->size, > - newsize, sizeof(struct community))) == NULL) > + if ((new = reallocarray(comm->communities, newsize, > + sizeof(struct community))) == NULL) > fatal(__func__); > + memset(&new[comm->size], 0, sizeof(struct community) * 8); > comm->communities = new; > comm->size = newsize; > } >