diff --git a/mxq_group.c b/mxq_group.c index 65f7757..2887411 100644 --- a/mxq_group.c +++ b/mxq_group.c @@ -292,39 +292,6 @@ int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **m return res; } -int mxq_load_active_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) -{ - int res; - struct mxq_group *groups = NULL; - struct mxq_group g = {0}; - struct mx_mysql_bind result = {0}; - - assert(mysql); - assert(mxq_groups); - - *mxq_groups = NULL; - - char *query = - "SELECT" - GROUP_FIELDS - " FROM mxq_group" - " WHERE (group_jobs_inq > 0 OR group_jobs_running > 0)" - " ORDER BY user_name, group_mtime" - " LIMIT 1000"; - - res = bind_result_group_fields(&result, &g); - assert(res == 0); - - res = mx_mysql_do_statement_retry_on_fail(mysql, query, NULL, &result, &g, (void **)&groups, sizeof(*groups)); - if (res < 0) { - mx_log_err("mx_mysql_do_statement_retry_on_fail(): %m"); - return res; - } - - *mxq_groups = groups; - return res; -} - int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups) { int res; diff --git a/mxq_group.h b/mxq_group.h index e678cb3..46a352b 100644 --- a/mxq_group.h +++ b/mxq_group.h @@ -68,7 +68,6 @@ inline uint64_t mxq_group_jobs_inq(struct mxq_group *g); int mxq_load_group(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t group_id); int mxq_load_all_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); -int mxq_load_active_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); int mxq_load_all_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t user_uid); int mxq_load_active_groups_for_user(struct mx_mysql *mysql, struct mxq_group **mxq_groups, uint64_t user_uid); int mxq_load_running_groups(struct mx_mysql *mysql, struct mxq_group **mxq_groups); diff --git a/mxqd.c b/mxqd.c index 047b6ed..3a7fa6a 100644 --- a/mxqd.c +++ b/mxqd.c @@ -277,9 +277,9 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) char arg_recoveronly = 0; char *str_bootid; int opt; - unsigned long threads_total = 0; - unsigned long memory_total = 2048; - unsigned long memory_max = 0; + unsigned long arg_threads_total = 0; + unsigned long arg_memory_total = 2048; + unsigned long arg_memory_max = 0; int i; struct proc_pid_stat pps = {0}; @@ -361,35 +361,35 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) exit(EX_USAGE); case 'j': - if (mx_strtoul(optctl.optarg, &threads_total) < 0) { + if (mx_strtoul(optctl.optarg, &arg_threads_total) < 0) { mx_log_err("Invalid argument supplied for option --slots '%s': %m", optctl.optarg); exit(1); } break; case 'm': - if (mx_strtoul(optctl.optarg, &memory_total) < 0) { + if (mx_strtoul(optctl.optarg, &arg_memory_total) < 0) { unsigned long long int bytes; if(mx_strtobytes(optctl.optarg, &bytes) < 0) { mx_log_err("Invalid argument supplied for option --memory '%s': %m", optctl.optarg); exit(1); } - memory_total = bytes/1024/1024; + arg_memory_total = bytes/1024/1024; } - if (!memory_total) - memory_total = 2048; + if (!arg_memory_total) + arg_memory_total = 2048; break; case 'x': - if (mx_strtoul(optctl.optarg, &memory_max) < 0) { + if (mx_strtoul(optctl.optarg, &arg_memory_max) < 0) { unsigned long long int bytes; if(mx_strtobytes(optctl.optarg, &bytes) < 0) { mx_log_err("Invalid argument supplied for option --max-memory-per-slot '%s': %m", optctl.optarg); exit(1); } - memory_max = bytes/1024/1024; + arg_memory_max = bytes/1024/1024; } break; @@ -508,14 +508,19 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) mx_asprintf_forever(&server->host_id, "%s-%llx-%x", server->boot_id, server->starttime, getpid()); - server->slots = threads_total; + server->slots = arg_threads_total; res = cpuset_init(server); if (res < 0) { mx_log_err("MAIN: cpuset_init() failed. exiting."); exit(1); } - server->memory_total = memory_total; - server->memory_max_per_slot = memory_max; + server->memory_total = arg_memory_total; + server->memory_max_per_slot = arg_memory_max; + + /* if run as non-root use full memory by default for every job */ + if (!arg_memory_max && getuid() != 0) + server->memory_max_per_slot = arg_memory_total; + server->memory_avg_per_slot = (long double)server->memory_total / (long double)server->slots; if (server->memory_max_per_slot < server->memory_avg_per_slot) @@ -524,7 +529,6 @@ int server_init(struct mxq_server *server, int argc, char *argv[]) if (server->memory_max_per_slot > server->memory_total) server->memory_max_per_slot = server->memory_total; - return 1; } @@ -1720,13 +1724,16 @@ int catchall(struct mxq_server *server) { } int load_groups(struct mxq_server *server) { - struct mxq_group *mxqgroups; + struct mxq_group *mxqgroups = NULL; struct mxq_group_list *group; int group_cnt; int total; int i; - group_cnt = mxq_load_active_groups(server->mysql, &mxqgroups); + if (getuid() == 0) + group_cnt = mxq_load_running_groups(server->mysql, &mxqgroups); + else + group_cnt = mxq_load_running_groups_for_user(server->mysql, &mxqgroups, getuid()); for (i=0, total=0; i