From b2e51b95d778c56362688403e2f96f4ad2583e09 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sun, 20 Mar 2022 19:01:19 +0100 Subject: [PATCH] mxqd: Avoid user sort when server is full Avoid sorting the user list when we are not going to start a job anyway. Also save a few source lines and remove a dead initalization. --- mxqd.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/mxqd.c b/mxqd.c index 78e57dac..4c95c3d9 100644 --- a/mxqd.c +++ b/mxqd.c @@ -1510,26 +1510,14 @@ static void move_user_to_end(struct mxq_server *server, struct mxq_user_list *us long start_user_with_least_running_global_slot_count(struct mxq_server *server) { - struct mxq_user_list *ulist; - unsigned long slots_started = 0; - unsigned long slots_free; - int waiting = 0; - unsigned long df_scratch; - - assert(server); - - if (!server->user_cnt) + unsigned long slots_free = server->slots - server->slots_running; + if (!server->user_cnt || !slots_free) return 0; - server_sort_users_by_running_global_slot_count(server); - slots_free = server->slots - server->slots_running; - - if (!slots_free) - return 0; - - df_scratch=mx_df(MXQ_JOB_TMPDIR_FS "/."); + unsigned long df_scratch=mx_df(MXQ_JOB_TMPDIR_FS "/."); + int waiting = 0; - for (ulist = server->users; ulist; ulist = ulist->next) { + for (struct mxq_user_list *ulist = server->users; ulist; ulist = ulist->next) { /* if a previous user is waiting for free resources, don't start jobs * for later users. */ if (waiting && can_start_job_for_user(ulist, df_scratch, server, slots_free)) @@ -1537,7 +1525,7 @@ long start_user_with_least_running_global_slot_count(struct mxq_server *server) * database to WAITING, which is just informational. */ return -1; - slots_started = start_user(ulist, slots_free, df_scratch); + unsigned long slots_started = start_user(ulist, slots_free, df_scratch); if (slots_started) { /* move user to end of list so that we get a round-robin with with * other users which sort to the same precedence. */