From 2c1c567ee1a59fa7bf09be0ed0554d2dc01cd0b9 Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Mon, 13 Jul 2015 21:42:57 +0300 Subject: [PATCH] winbindd: shorten client list scan Counting on the client list being sorted by last access time, the list scan for removing timed-out clients is shortened - once the list is scanned oldest to newest, and once a non-timed-out client is found, the scan can stop. Also, finding the oldest idle client for removing an idle client is simplified - oldest idle client is last idle client. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11397 Signed-off-by: Uri Simchoni Reviewed-by: Jeremy Allison Reviewed-by: Volker Lendecke Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Jul 16 01:45:20 CEST 2015 on sn-devel-104 --- source3/winbindd/winbindd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 620fd3fb8b6..c878ce2e220 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -1086,16 +1086,13 @@ static bool client_is_idle(struct winbindd_cli_state *state) { static bool remove_idle_client(void) { struct winbindd_cli_state *state, *remove_state = NULL; - time_t last_access = 0; int nidle = 0; for (state = winbindd_client_list(); state; state = state->next) { if (client_is_idle(state)) { nidle++; - if (!last_access || state->last_access < last_access) { - last_access = state->last_access; - remove_state = state; - } + /* list is sorted by access time */ + remove_state = state; } } @@ -1117,14 +1114,14 @@ static bool remove_idle_client(void) static void remove_timed_out_clients(void) { - struct winbindd_cli_state *state, *next = NULL; + struct winbindd_cli_state *state, *prev = NULL; time_t curr_time = time(NULL); int timeout_val = lp_winbind_request_timeout(); - for (state = winbindd_client_list(); state; state = next) { + for (state = winbindd_client_list_tail(); state; state = prev) { time_t expiry_time; - next = state->next; + prev = winbindd_client_list_prev(state); expiry_time = state->last_access + timeout_val; if (curr_time > expiry_time) { @@ -1140,6 +1137,10 @@ static void remove_timed_out_clients(void) (unsigned int)state->pid)); } remove_client(state); + } else { + /* list is sorted, previous clients in + list are newer */ + break; } } } -- 2.11.4.GIT