]> git.ipfire.org Git - people/ms/libloc.git/commit
ipset: Optimise hash table size
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Mar 2022 12:44:21 +0000 (12:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Mar 2022 12:44:21 +0000 (12:44 +0000)
commit47de14b01a0fae69994131e4fb9239738570ab38
tree7bf96cc6e65b9a57cb96de56aa2187a82452ff5f
parent181220aca39d86531f696369e90dd510915d197b
ipset: Optimise hash table size

ipset uses a hash table internally which can be dynamically sized to
chose whether more space efficiency or performance is required.

Previously to this patch, we always set the size of the hash table to
1024 buckets. Having large sets with almost half a million entries, this
is not performing well since we will spend a lot of time in searching
the linked list.

This will probably perform even slower on systems with smaller cache
sizes like the IPFire Mini Appliance.

Having more buckets that are sparesely filled, will result in less
memory fetches at the cost of more wastage. Throughout the whole IPv4
set, this ranges from about 50 MB for a factor of 4, to about 100 MB for
a factor of 0.75.

Since memory of this quantity is cheap and since we want to increase
throughput, I have chosen to set the fill factor to 0.75.

Logistically, it is a little bit complicated to know this in advance
when we have to write the header, so we will write the entire file
first, and then come back to write the header again. This is required to
keep memory consumption down during the export.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/export.py