[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [dm-devel] [PATCH 2/3] set pthread stack size to at least PTHREAD_STACK_MIN



At least pull this logic out into a seperate function rather than
repeating it three times.  Also you may find min() useful.

- Joe

2009/3/12 Benjamin Marzinski <bmarzins redhat com>:
> Attempting to set the stacksize of a pthread to below
> PTHREAD_STACK_MIN causes pthread_attr_setstacksize() to fail, which
> means that the thread will use the default stack size.  This fix
> makes sure that multipathd never requests a stack size less than
> PTHREAD_STACK_MIN.
>
> Signed-off-by: Benjamin Marzinski <bmarzins redhat com>
> ---
>  libmultipath/log_pthread.c |    6 +++++-
>  libmultipath/waiter.c      |    5 ++++-
>  multipathd/main.c          |    5 ++++-
>  3 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
> index a1d4a10..5d2fe76 100644
> --- a/libmultipath/log_pthread.c
> +++ b/libmultipath/log_pthread.c
> @@ -6,6 +6,7 @@
>  #include <stdarg.h>
>  #include <pthread.h>
>  #include <sys/mman.h>
> +#include <limits.h>
>
>  #include <memory.h>
>
> @@ -52,6 +53,7 @@ static void * log_thread (void * et)
>
>  void log_thread_start (void)
>  {
> +       size_t stacksize = 64 * 1024;
>        pthread_attr_t attr;
>
>        logdbg(stderr,"enter log_thread_start\n");
> @@ -65,7 +67,9 @@ void log_thread_start (void)
>        pthread_cond_init(logev_cond, NULL);
>
>        pthread_attr_init(&attr);
> -       pthread_attr_setstacksize(&attr, 64 * 1024);
> +       if (stacksize < PTHREAD_STACK_MIN)
> +               stacksize = PTHREAD_STACK_MIN;
> +       pthread_attr_setstacksize(&attr, stacksize);
>
>        if (log_init("multipathd", 0)) {
>                fprintf(stderr,"can't initialize log buffer\n");
> diff --git a/libmultipath/waiter.c b/libmultipath/waiter.c
> index 54cd19f..4d449e1 100644
> --- a/libmultipath/waiter.c
> +++ b/libmultipath/waiter.c
> @@ -194,6 +194,7 @@ void *waitevent (void *et)
>
>  int start_waiter_thread (struct multipath *mpp, struct vectors *vecs)
>  {
> +       size_t stacksize = 32 * 1024;
>        pthread_attr_t attr;
>        struct event_thread *wp;
>
> @@ -203,7 +204,9 @@ int start_waiter_thread (struct multipath *mpp, struct vectors *vecs)
>        if (pthread_attr_init(&attr))
>                goto out;
>
> -       pthread_attr_setstacksize(&attr, 32 * 1024);
> +       if (stacksize < PTHREAD_STACK_MIN)
> +               stacksize = PTHREAD_STACK_MIN;
> +       pthread_attr_setstacksize(&attr, stacksize);
>        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
>
>        wp = alloc_waiter();
> diff --git a/multipathd/main.c b/multipathd/main.c
> index 98153df..dae9152 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -1267,6 +1267,7 @@ set_oom_adj (int val)
>  static int
>  child (void * param)
>  {
> +       size_t stacksize = 64 * 1024;
>        pthread_t check_thr, uevent_thr, uxlsnr_thr;
>        pthread_attr_t attr;
>        struct vectors * vecs;
> @@ -1347,7 +1348,9 @@ child (void * param)
>         * start threads
>         */
>        pthread_attr_init(&attr);
> -       pthread_attr_setstacksize(&attr, 64 * 1024);
> +       if (stacksize < PTHREAD_STACK_MIN)
> +               stacksize = PTHREAD_STACK_MIN;
> +       pthread_attr_setstacksize(&attr, stacksize);
>        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
>
>        pthread_create(&check_thr, &attr, checkerloop, vecs);
> --
> 1.5.3.3
>
> --
> dm-devel mailing list
> dm-devel redhat com
> https://www.redhat.com/mailman/listinfo/dm-devel
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]