about summary refs log tree commit homepage
path: root/thrpool.c
diff options
context:
space:
mode:
Diffstat (limited to 'thrpool.c')
-rw-r--r--thrpool.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/thrpool.c b/thrpool.c
index 8030e19..3bff31e 100644
--- a/thrpool.c
+++ b/thrpool.c
@@ -4,6 +4,9 @@
  */
 #include "cmogstored.h"
 
+/* this is set and read without a lock, but harmless if racy */
+size_t mog_user_set_aio_threads;
+
 /*
  * we can lower this if we can test with lower values, NPTL minimum is 16K.
  * We also use syslog() and *printf() functions which take a lot of
@@ -132,6 +135,36 @@ out:
         CHECK(int, 0, pthread_mutex_unlock(&tp->lock));
 }
 
+/* this is only called by the main (notify) thread */
+void mog_thrpool_update(struct mog_queue *q, size_t ndev_old, size_t ndev_new)
+{
+        size_t size = ndev_new * 10;
+        struct mog_thrpool *tp = &q->thrpool;
+
+        if (mog_user_set_aio_threads) {
+                size_t n_threads;
+
+                CHECK(int, 0, pthread_mutex_lock(&tp->lock));
+                n_threads = tp->n_threads;
+                CHECK(int, 0, pthread_mutex_unlock(&tp->lock));
+
+                if (n_threads >= ndev_new)
+                        return;
+
+                syslog(LOG_WARNING,
+                        "server aio_threads=%zu is less than devcount=%zu",
+                        n_threads, ndev_new);
+
+                return;
+        }
+
+        if (ndev_old)
+                syslog(LOG_INFO,
+                       "devcount(%zu->%zu), updating server aio_threads=%zu",
+                       ndev_old, ndev_new, size);
+        thrpool_set_size(tp, size);
+}
+
 /*
  * fire and forget, we must run the actual thread count manipulation
  * in the main notify thread because we may end up terminating the
@@ -171,7 +204,7 @@ void mog_thrpool_process_queue(void)
                 if (arg == NULL)
                         return;
 
-                syslog(LOG_INFO, "server aio_threads=%u", (unsigned)arg->size);
+                syslog(LOG_INFO, "server aio_threads=%zu", arg->size);
                 thrpool_set_size(&arg->queue->thrpool, arg->size);
                 free(arg);
         }