server: dent limit

This commit is contained in:
Thomas Schoebel-Theuer 2017-09-07 10:56:44 +02:00
parent c0dfbde8a8
commit 2d26b3d224
3 changed files with 29 additions and 0 deletions

View File

@ -52,6 +52,23 @@ EXPORT_SYMBOL_GPL(server_handler_count);
///////////////////////// own helper functions ////////////////////////
#define DENT_LIMIT 8
int dent_limit = DENT_LIMIT;
int dent_nr = DENT_LIMIT;
static struct semaphore dent_limit_sem = __SEMAPHORE_INITIALIZER(dent_limit_sem, DENT_LIMIT);
static
void change_sem(struct semaphore *sem, int *limit, int *nr)
{
if (unlikely(*nr < *limit)) {
up(sem);
(*nr)++;
} else if (unlikely(*nr > *limit)) {
if (!down_trylock(sem))
(*nr)--;
}
}
static
int cb_thread(void *data)
@ -446,8 +463,16 @@ int handler_thread(void *data)
if (unlikely(!cmd.cmd_str1))
break;
if (down_trylock(&dent_limit_sem)) {
MARS_DBG("#%d dent limit reached\n", sock->s_debug_nr);
status = -EUSERS;
break;
}
status = mars_dent_work(&handler_global, "/mars", sizeof(struct mars_dent), main_checker, dummy_worker, &handler_global, 3);
up(&dent_limit_sem);
down(&brick->socket_sem);
status = mars_send_dent_list(sock, &handler_global.dent_anchor);
up(&brick->socket_sem);
@ -790,6 +815,8 @@ static int _server_thread(void *data)
struct server_brick *brick = NULL;
struct mars_socket handler_socket = {};
change_sem(&dent_limit_sem, &dent_limit, &dent_nr);
server_global.global_version++;
mars_limit(&server_limiter, 0);

View File

@ -32,6 +32,7 @@
extern int server_show_statist;
extern struct mars_limiter server_limiter;
extern int dent_limit;
extern atomic_t server_handler_count;

View File

@ -344,6 +344,7 @@ struct ctl_table mars_table[] = {
INT_ENTRY("sync_want", global_sync_want, 0400),
INT_ENTRY("sync_nr", global_sync_nr, 0400),
INT_ENTRY("sync_limit", global_sync_limit, 0600),
INT_ENTRY("handler_dent_limit", dent_limit, 0600),
INT_ENTRY("mars_emergency_mode", mars_emergency_mode, 0600),
INT_ENTRY("mars_reset_emergency", mars_reset_emergency, 0600),
INT_ENTRY("mars_keep_msg_s", mars_keep_msg, 0600),