MINOR: pattern: add pat_ref_purge_older() to purge old entries

This function will be usable to purge at most a specified number of old
entries from a reference. Entries are declared old if their generation
number is in the past compared to the one passed in argument. This will
ease removal of early entries when new ones have been appended.

We also call malloc_trim() when available, at the end of the series,
because this is one place where there is a lot of memory to save. Reloads
of 1M IP addresses used in an ACL made the process grow up to 1.7 GB RSS
after 10 reloads and roughly stabilize there without this call, versus
only 260 MB when the call is present. Sadly there is no direct equivalent
for jemalloc, which stabilizes around 800MB-1GB.
This commit is contained in:
Willy Tarreau
2020-10-28 18:23:49 +01:00
parent 1a6857b9c1
commit 94b9abe200
2 changed files with 65 additions and 0 deletions

View File

@@ -192,6 +192,7 @@ void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt);
int pat_ref_prune(struct pat_ref *ref);
int pat_ref_commit(struct pat_ref *ref, struct pat_ref_elt *elt, char **err);
int pat_ref_purge_older(struct pat_ref *ref, unsigned int oldest, int budget);
void pat_ref_reload(struct pat_ref *ref, struct pat_ref *replace);