diff --git a/src/mworker.c b/src/mworker.c index 261b7578c..d1513f3ac 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -223,7 +223,20 @@ int mworker_env_to_proc_list() } } if (child->pid > 0) { - LIST_APPEND(&proc_list, &child->list); + struct list *insert_pt = &proc_list; + struct mworker_proc *pos; + + /* insert at the right position in ASC reload order; + * search from the tail since items are sorted most of + * the time + */ + list_for_each_entry_rev(pos, &proc_list, list) { + if (pos->reloads <= child->reloads) { + insert_pt = &pos->list; + break; + } + } + LIST_INSERT(insert_pt, &child->list); } else { mworker_free_child(child); }