dnsmasq: backport latest patches
[openwrt/staging/lynxis.git] / package / network / services / dnsmasq / patches / 0035-lease-prune-lease-as-soon-as-expired.patch
1 From df6636bff61aa53ed7ad4b34d940805193c0bc74 Mon Sep 17 00:00:00 2001
2 From: Florent Fourcot <florent.fourcot@wifirst.fr>
3 Date: Mon, 11 Feb 2019 17:04:44 +0100
4 Subject: [PATCH 35/57] lease: prune lease as soon as expired
5
6 We detected a performance issue on a dnsmasq running many dhcp sessions
7 (more than 10 000). At the end of the day, the server was only releasing
8 old DHCP leases but was consuming a lot of CPU.
9
10 It looks like curent dhcp pruning:
11 1) it's pruning old sessions (iterate on all current leases). It's
12 important to note that it's only pruning session expired since more
13 than one second
14 2) it's looking for next lease to expire (iterate on all current leases
15 again)
16 3) it launchs an alarm to catch next expiration found in step 2). This
17 value can be zero for leases just expired (but not pruned).
18
19 So, for a second, dnsmasq could fall in a "prune loop" by doing:
20 * Not pruning anything, since difftime() is not > 0
21 * Run alarm again with zero as argument
22
23 On a server with very large number of leases and releasing often
24 sessions, that can waste a very big CPU time.
25
26 Signed-off-by: Florent Fourcot <florent.fourcot@wifirst.fr>
27 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
28 ---
29 src/lease.c | 2 +-
30 1 file changed, 1 insertion(+), 1 deletion(-)
31
32 --- a/src/lease.c
33 +++ b/src/lease.c
34 @@ -558,7 +558,7 @@ void lease_prune(struct dhcp_lease *targ
35 for (lease = leases, up = &leases; lease; lease = tmp)
36 {
37 tmp = lease->next;
38 - if ((lease->expires != 0 && difftime(now, lease->expires) > 0) || lease == target)
39 + if ((lease->expires != 0 && difftime(now, lease->expires) >= 0) || lease == target)
40 {
41 file_dirty = 1;
42 if (lease->hostname)