diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-07-14 07:26:36 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-07-14 08:27:53 +0000 |
commit | 4edbdd6ba3686a60a8ddeed8f6f26e55abf0b207 (patch) | |
tree | 27a8221b0eaf3b3b08b9358cdf68974735c8fa03 /thrpool.c | |
parent | e46c221c47e3cd00edfcae199146cb2f50b9b63f (diff) | |
download | cmogstored-4edbdd6ba3686a60a8ddeed8f6f26e55abf0b207.tar.gz |
It's unlikely we'll even come close to see 2-4 billion devices in a MogileFS instance for a while. Meanwhile, it's also unlikely the kernel will ever run that many threads, either. So make it easier to pack and shrink data structures to save a few bytes and perhaps get better memory alignement. For reference, the POSIX semaphore API specifies initial values with unsigned (int) values, too. This leads to a minor size reduction (and we're not even packing): $ ~/linux/scripts/bloat-o-meter cmogstored.before cmogstored add/remove: 0/0 grow/shrink: 0/13 up/down: 0/-86 (-86) function old new delta mog_svc_dev_quit_prepare 13 12 -1 mog_mgmt_fn_aio_threads 147 146 -1 mog_dev_user_rescale_i 27 26 -1 mog_ioq_requeue_prepare 52 50 -2 mog_ioq_init 80 78 -2 mog_thrpool_start 101 96 -5 mog_svc_dev_user_rescale 143 137 -6 mog_svc_start_each 264 256 -8 mog_svc_aio_threads_handler 257 249 -8 mog_ioq_ready 263 255 -8 mog_ioq_next 303 295 -8 mog_svc_thrpool_rescale 206 197 -9 mog_thrpool_set_size 1028 1001 -27
Diffstat (limited to 'thrpool.c')
-rw-r--r-- | thrpool.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -93,7 +93,7 @@ static void poke(pthread_t thr, int sig) } static bool -thr_create_fail_retry(struct mog_thrpool *tp, size_t size, +thr_create_fail_retry(struct mog_thrpool *tp, unsigned size, unsigned long *nr_eagain, int err) { /* do not leave the pool w/o threads at all */ @@ -108,14 +108,14 @@ thr_create_fail_retry(struct mog_thrpool *tp, size_t size, } else { errno = err; syslog(LOG_ERR, - "pthread_create: %m, only running %lu of %lu threads", - (unsigned long)tp->n_threads, (unsigned long)size); + "pthread_create: %m, only running %u of %u threads", + tp->n_threads, size); return false; } } static bool -thrpool_add(struct mog_thrpool *tp, size_t size, unsigned long *nr_eagain) +thrpool_add(struct mog_thrpool *tp, unsigned size, unsigned long *nr_eagain) { struct mog_thr_start_arg arg = { .mtx = PTHREAD_MUTEX_INITIALIZER, @@ -158,7 +158,7 @@ thrpool_add(struct mog_thrpool *tp, size_t size, unsigned long *nr_eagain) return true; } -void mog_thrpool_set_size(struct mog_thrpool *tp, size_t size) +void mog_thrpool_set_size(struct mog_thrpool *tp, unsigned size) { unsigned long nr_eagain = 0; @@ -168,7 +168,7 @@ void mog_thrpool_set_size(struct mog_thrpool *tp, size_t size) /* nothing */; if (tp->n_threads > size) { - size_t i; + unsigned i; int err; /* set the do_quit flag for all threads we kill */ @@ -197,19 +197,19 @@ void mog_thrpool_set_size(struct mog_thrpool *tp, size_t size) } void -mog_thrpool_start(struct mog_thrpool *tp, size_t n, +mog_thrpool_start(struct mog_thrpool *tp, unsigned nthr, void *(*start_fn)(void *), void *arg) { /* we may be started on a new server before device dirs exist */ - if (n == 0) - n = 1; + if (nthr == 0) + nthr = 1; tp->threads = NULL; tp->n_threads = 0; tp->start_fn = start_fn; tp->start_arg = arg; CHECK(int, 0, pthread_mutex_init(&tp->lock, NULL)); - mog_thrpool_set_size(tp, n); + mog_thrpool_set_size(tp, nthr); } void mog_thrpool_quit(struct mog_thrpool *tp, struct mog_queue *q) |