Commit graph

61 commits

Author SHA1 Message Date
Donald Sharp d97c535c1e *: Create termtable specific temp memory
When trying to track down a MTYPE_TMP memory leak
it's harder to search for it when you happen to
have some usage of ttable_dump.  Let's just give
it it's own memory type so that we can avoid
confusion in the future.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-09-01 13:07:46 -04:00
Donald Sharp d8bc11a592 *: Add a hash_clean_and_free() function
Add a hash_clean_and_free() function as well as convert
the code to use it.  This function also takes a double
pointer to the hash to set it NULL.  Also it cleanly
does nothing if the pointer is NULL( as a bunch of
code tested for ).

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21 08:54:21 -04:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
Donald Sharp cb1991af8c *: frr_with_mutex change to follow our standard
convert:
	frr_with_mutex(..)

to:
	frr_with_mutex (..)

To make all our code agree with what clang-format is going to produce

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-20 15:50:32 -04:00
David Lamparter bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
Back when I put this together in 2015, ISO C11 was still reasonably new
and we couldn't require it just yet.  Without ISO C11, there is no
"good" way (only bad hacks) to require a semicolon after a macro that
ends with a function definition.  And if you added one anyway, you'd get
"spurious semicolon" warnings on some compilers...

With C11, `_Static_assert()` at the end of a macro will make it so that
the semicolon is properly required, consumed, and not warned about.

Consistently requiring semicolons after "file-level" macros matches
Linux kernel coding style and helps some editors against mis-syntax'ing
these macros.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:17 +01:00
Igor Ryzhov 1ac88792c0 *: fix all backets
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-02-02 19:11:25 +03:00
Quentin Young c7bb4f006b lib, bgpd: convert lttng tracepoints to frrtrace()
- tracepoint() -> frrtrace()
- tracelog() -> frrtracelog()
- tracepoint_enabled() -> frrtrace_enabled()

Also removes copypasta'd #ifdefs for those LTTng macros, those are
handled in lib/trace.h

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Quentin Young 912d45a161 lib: move trace.h -> libfrr_trace.h
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Quentin Young 67a485d18f lib: add tracepoint for hash insertion
hash_get is used for both lookup and insert; add a tracepoint for when
we insert something into the hash

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Quentin Young abf96a87f3 lib: add tracepoints for hash ops, thread events
Define some initial tracepoints for hash table operations, thread
schedules, and thread cancels

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-10-23 15:13:51 -04:00
Quentin Young e6464fdc18 lib: remove overflow arithmetic from hash stats
Signed values get converted to unsigned for addition, so when the value
to adjust a stats variable for hash tables was negative this resulted in
overflow arithmetic, which we generally don't want.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-09-02 16:54:41 -04:00
David Lamparter 00dffa8cde lib: add frr_with_mutex() block-wrapper
frr_with_mutex(...) { ... } locks and automatically unlocks the listed
mutex(es) when the block is exited.  This adds a bit of safety against
forgetting the unlock in error paths & co. and makes the code a slight
bit more readable.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-09-03 17:15:17 +02:00
David Lamparter eaf58ba906 lib: use MTYPE_STATIC
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-06-21 08:54:25 +02:00
Quentin Young d8b87afe7c lib: hashing functions should take const arguments
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.

BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-05-14 21:23:08 +00:00
Quentin Young c17faa4b10 lib: reduce exported var symbols
Don't need these in our DSO tables

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-04-03 20:34:18 +00:00
Quentin Young 0a22ddfbb1 *: remove null check before XFREE
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:46 +00:00
Quentin Young 76f0146890 *: do not check XMALLOC / XCALLOC for null ret
They never return NULL

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-02-25 23:00:44 +00:00
Tim Bray e3b78da875 *: Rename backet to bucket
Presume typo from original author

Signed-off-by: Tim Bray <tim@kooky.org>
2019-02-25 16:22:36 +00:00
Ruben Kerkhof 4d762f2607 Treewide: use ANSI function definitions
Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
2019-01-24 11:21:59 +01:00
Donald Sharp 74df8d6d9d *: Replace hash_cmp function return value to a bool
The ->hash_cmp and linked list ->cmp functions were sometimes
being used interchangeably and this really is not a good
thing.  So let's modify the hash_cmp function pointer to return
a boolean and convert everything to use the new syntax.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-10-19 13:14:45 -04:00
David Lamparter 6a154c8812 *: list_delete_and_null() -> list_delete()
Signed-off-by: David Lamparter <equinox@diac24.net>
2018-10-02 11:40:52 +02:00
Donald Sharp df66eb2eeb Revert "lib: A small optimization for the hash iterate and walk functions"
This reverts commit fc61644e440c875eefa222ab34d726c6281ca806.
2018-07-06 10:18:11 -04:00
Donald Sharp 626e8d0a9b lib: A small optimization for the hash iterate and walk functions
When we are iterating through the hash, keep count of how many
we've called and if we have finished calling the hash->size
iterator times, then short-circuit and stop looping over
the entire array.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-06-16 20:09:45 -04:00
Quentin Young 6fd8c487e1 lib: add proper doc comments for hash & linklist
* Remove references to ospf source files from linklist.[ch]
* Remove documentation comments from hash.c and linklist.c
* Add comprehensive documentation comments to linklist.h and hash.h

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-05-25 16:29:54 +00:00
Quentin Young 91f1037064 lib: add hash_to_list()
Convenience function to convert hash table to an unsorted linked list.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-05-25 16:16:22 +00:00
Renato Westphal 44f12f209f *: fix coverity warnings - resource leaks
These are mostly trivial fixes for leaks in the error path of some functions.

The changes in bgpd/bgp_mpath.c deserves a bit of explanation though. In
the bgp_info_mpath_aggregate_update() function, we were allocating memory
for the lcomm variable but doing nothing with it. Since the code for
communities, extended communities and large communities is pretty much
the same in this function, it's clear that this was a copy and paste
error where most of the ext. community code was copied but not all of
it as it should have been.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2017-10-24 19:30:30 -02:00
Donald Sharp efb149d95b lib: Allow hash_get to sidestep expensive hash key generation in some cases
There is no need to generate a hash key *if* the hash_alloc_function
is NULL and the hash is empty.

This changed showed a measurable increase in performance for
table hash lookup for tables that were meant to be empty in
bgp( the distance commands ).

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-16 13:56:01 -04:00
Donald Sharp affe9e9983 *: Convert list_delete(struct list *) to ** to allow nulling
Convert the list_delete(struct list *) function to use
struct list **.  This is to allow the list pointer to be nulled.

I keep running into uses of this list_delete function where we
forget to set the returned pointer to NULL and attempt to use
it and then experience a crash, usually after the developer
has long since left the building.

Let's make the api explicit in it setting the list pointer
to null.

Cynical Prediction:  This code will expose a attempt
to use the NULL'ed list pointer in some obscure bit
of code.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-10-05 10:53:13 -04:00
David Lamparter 40818cec85 lib: move hashstats under debug, show per-daemon
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-08-21 14:41:02 +02:00
Quentin Young bed7ad8387
lib: use load factor as hash expansion trigger
Previous strategy was to resize the hash table when the length of any
one bucket exceeded a certain size, with some logic for intelligently
stopping resizes when the gains from doing so weren't sufficient. While
this was a good idea that attempted to optimize both space and lookup
time, unfortunately under transient degenerate conditions this led to
some issues with the tables not resizing when they should have,
harming performance. The resizing restriction was lifted, but this had
the result of exacerbating degenerate behavior and caused out of memory
conditions.

This patch changes the hash expansion criterion to be based on the
number of elements in the table. Once the # of elements in the table
exceeds the number of buckets, the table size is doubled. While the
space efficiency of this method decreases relative to the perfectness of
the hash function, at least this strategy puts the table performance
squarely in the hands of the hash function.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-09 13:53:11 -04:00
Quentin Young 61b9e9d6b3
lib: remove last powl()
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-08-04 10:58:00 -04:00
Christian Franke c7d3895eb1 lib: Reformat comment so my eyes don't fall out while reading it
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2017-08-03 14:30:01 +02:00
Daniel Walton 40520c3649 bgpd: peer hash expands until we are out of memory
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>

swpX peers all start out with the same sockunion so initially they all
go into the same hash bucket. Once IPv6 ND has worked its magic they
will have different sockunions and will go in different buckets...life
is good.

Until then though, we are in a phase where all swpX peers have the same
socknunion. Once we have HASH_THRESHOLD (10) swpX peers and call
hash_get for a new swpX peer the hash code calls hash_expand(). This
happens because there are more than HASH_THRESHOLD entries in a single
bucket so the logic is "expand the hash to spread things out"...in our
case expanding doesn't spread out the swpX peers because all of their
sockunions are the same.

I looked at having peer_hash_make and peer_hash_same consider the ifname
of the swpX peer but that is a large change that we don't want to make
at the moment. So the fix is to put a cap on how large we are
willing to let the hash table get. By default there is no limit but if
max_size is set we will not allow the hash to expand above that.
2017-07-31 21:22:23 +00:00
Donald Sharp 8b2a6222e8 lib: Remove expansion of hash table
The hash code has the idea of stopping expanding
the hash table when certain criteria are set.
With the recent addition of `show hashtable`
we can now see that when we have a full internet
feed we've stopped expanding the table at 1k
buckets.  This results in some serious performance
issues at scale.

Since we now have the ability to see the statistics
on a hash table, let's allow it to expand.  Doing
so on a full feed showed this:

before:
   Hash table          |  Buckets   Entries   Empty   LF        SD      FLF       SD
 ----------------------+----------------------------------------------------------------
   route table hash    |  1024      1187579   0%      1159.75   34.06   1159.75   35.08
   route table hash    |  32768     76208     10%     2.33      2.80    2.58      4.03
   route table hash    |  1024      1187572   0%      1159.74   34.06   1159.74   35.08
   route table hash    |  2048      76205     0%      37.21     6.13    37.21     7.29

Showing hash table statistics for BGP
-------------------------------------

   Hash table         |  Buckets   Entries   Empty   LF       SD      FLF      SD
 ---------------------+--------------------------------------------------------------
   BGP Attributes     |  131072    251229    15%     1.92     2.48    2.25     3.33
   route table hash   |  4096      1187572   0%      289.93   17.03   289.93   17.87
   route table hash   |  32768     76205     10%     2.33     2.90    2.58     4.21

After:

   Hash table          |  Buckets   Entries   Empty   LF     SD     FLF    SD
 ----------------------+--------------------------------------------------------
   route table hash    |  1048576   1187349   32%     1.13   2.57   1.67   3.16
   route table hash    |  32768     76195     10%     2.33   2.81   2.58   4.03
   route table hash    |  1048576   1187342   32%     1.13   2.58   1.67   3.16
   route table hash    |  32768     76192     10%     2.33   2.68   2.58   3.81

Showing hash table statistics for BGP
-------------------------------------

   Hash table         |  Buckets   Entries   Empty   LF     SD     FLF    SD
 ---------------------+--------------------------------------------------------
   BGP Attributes     |  131072    251222    15%     1.92   2.64   2.25   3.58
   route table hash   |  1048576   1187342   32%     1.13   2.52   1.67   3.07
   route table hash   |  32768     76192     10%     2.33   2.86   2.58   4.12

We should see some significant performance improvements across the board
for full feeds.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-07-27 11:08:40 -04:00
whitespace / reindent d62a17aede *: reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17 14:04:07 +02:00
David Lamparter 50790e72fb *: remove vty_outln again
(PRs merged to master added another few vty_outln() calls)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 13:09:47 +02:00
David Lamparter 2d8270596a Merge remote-tracking branch 'frr/master' into newline-redux
Lots of conflicts from CMD_WARNING_CONFIG_FAILED...

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 13:07:30 +02:00
David Lamparter 625e016d14 *: remove VTYNL, part 6 of 6
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 10:20:03 +02:00
David Lamparter 55f70b671f *: remove VTYNL, part 4 of 6
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-14 10:20:03 +02:00
David Lamparter 5c7571d43f *: ditch vty_outln(), part 1 of 2
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-13 20:29:22 +02:00
David Lamparter f4b0619dc6 Merge pull request #796 from qlyoung/fix-hash-stats
lib: use 32-bit atomics, s/pow/mul
2017-07-13 14:57:44 +02:00
Quentin Young 62c3d0260c
lib: use 32-bit atomics, s/pow/mul
Some platforms don't support 64-bit atomics, missed converting a
floating point pow() to an integral mul when changing SD algo.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-11 14:43:50 -04:00
David Lamparter 07181496b7 lib: hash: don't double-init hash list
hash_cmd_init will overwrite _hashes with a new list, while _hashes
already has been initialised from cmd_init(), thread_master_create(), or
any other function that may have created a hash.

Found while valgrind'ing ospf6d/test_lsdb.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-11 14:58:44 +02:00
Quentin Young e703a0f3af
lib, vtysh: rebase hashstats
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-01 19:18:39 -04:00
Quentin Young b3db0a22b7
lib: use doubles instead of long doubles
NetBSD can't take the square root of a long double
and we should be fine just using a double here anyway

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-01 19:18:38 -04:00
Quentin Young 6f6f00107e
lib, vtysh: hashtable statistics
Adds the ability to name hash tables, and a new cli command that will
show various summary statistics for named hash tables.

Statistics computed are
  - load factor
  - full load factor (see comments)
  - stddev of full load factor

Standard deviation is computed by storing the sum of squares of bucket
lengths. This is somewhat susceptible to overflow. On platforms where a
double is 32 bits, placing 65535 or more elements into a hash table
opens up the potential for overflow, depending on how they are arranged
in buckets (which depends on the hash function). For example, placing
65535 elements into one hash bucket would cause ssq overflow, but
distributing 40000000 elements evenly among 400000 buckets (100 elements
per bucket) would not.

These cases are extremely degenerate, so the vague possibility of
overflow in an informational command is deemed an acceptable tradeoff
for constant time calculation of variance without locks or compromising
efficiency of actual table operations.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-01 19:18:35 -04:00
Quentin Young 4db0cff16a
lib: add statistics for hash tables
Adds a function that calculates various statistics on our implementation
of a hash table. These are useful for evaluating performance.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2017-07-01 19:18:06 -04:00
David Lamparter 896014f4bc *: make consistent & update GPLv2 file headers
The FSF's address changed, and we had a mixture of comment styles for
the GPL file header.  (The style with * at the beginning won out with
580 to 141 in existing files.)

Note: I've intentionally left intact other "variations" of the copyright
header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15 16:37:41 +02:00
David Lamparter 4a1ab8e405 *: split & distribute memtypes and stop (re|ab)using lib/ MTYPEs
This is a rather large mechanical commit that splits up the memory types
defined in lib/memtypes.c and distributes them into *_memory.[ch] files
in the individual daemons.

The zebra change is slightly annoying because there is no nice place to
put the #include "zebra_memory.h" statement.

bgpd, ospf6d, isisd and some tests were reusing MTYPEs defined in the
library for its own use.  This is bad practice and would break when the
memtype are made static.

Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
[CF: rebased for cmaster-next]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-09-19 16:31:04 -04:00
Donald Sharp 24873f0c06 lib: lib-warnings.patch
Remove compile warnings for the lib directory
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by:
2015-05-19 18:04:26 -07:00