All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: device-mapper development <dm-devel@redhat.com>
Subject: Re: [PATCH 2/3] set pthread stack size to at least	PTHREAD_STACK_MIN
Date: Fri, 13 Mar 2009 11:51:59 +0100	[thread overview]
Message-ID: <49BA3ACF.1010101@suse.de> (raw)
In-Reply-To: <1236883093-2989-3-git-send-email-bmarzins@redhat.com>

Benjamin Marzinski wrote:
> 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");
[ .. ]
Hmm. I don't quite agree. I run into the same problem, but having
discovered that we're not checking any return values at all here
we should rather do the prudent thing and check them once and for all.

I've chosen this approach:

diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
index 9e9aebe..c33480e 100644
--- a/libmultipath/log_pthread.c
+++ b/libmultipath/log_pthread.c
@@ -53,9 +53,30 @@ static void * log_thread (void * et)
 void log_thread_start (void)
 {
        pthread_attr_t attr;
+       size_t stacksize;
 
        logdbg(stderr,"enter log_thread_start\n");
 
+       if (pthread_attr_init(&attr)) {
+               fprintf(stderr,"can't initialize log thread\n");
+               exit(1);
+       }
+
+       if (pthread_attr_getstacksize(&attr, &stacksize) != 0)
+               stacksize = PTHREAD_STACK_MIN:
+
+       /* Check if the stacksize is large enough */
+       if (stacksize < (64 * 1024))
+               stacksize = 64 * 1024;
+
+       /* Set stacksize and try to reinitialize attr if failed */
+       if (stacksize > PTHREAD_STACK_MIN &&
+           pthread_attr_setstacksize(&attr, stacksize) != 0 &&
+           pthread_attr_init(&attr)) {
+               fprintf(stderr,"can't set log thread stack size\n");
+               exit(1);
+       }
+
        logq_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
        logev_lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
        logev_cond = (pthread_cond_t *) malloc(sizeof(pthread_cond_t));
@@ -64,9 +85,6 @@ void log_thread_start (void)
        pthread_mutex_init(logev_lock, NULL);
        pthread_cond_init(logev_cond, NULL);
 
-       pthread_attr_init(&attr);
-       pthread_attr_setstacksize(&attr, 64 * 1024);
-
        if (log_init("multipathd", 0)) {
                fprintf(stderr,"can't initialize log buffer\n");
                exit(1);


This way we'll at least be notified if something goes wrong in
the future. We shouldn't make the same mistake again and
ignore error codes which don't happen to trigger now.

If agreed I'll post the full patch here.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)

  reply	other threads:[~2009-03-13 10:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12 18:38 [PATCH 0/3] Some miscellaneous dm-multipath patches Benjamin Marzinski
2009-03-12 18:38 ` [PATCH 1/3] remove deleted path from pathvec Benjamin Marzinski
2009-03-12 18:38 ` [PATCH 2/3] set pthread stack size to at least PTHREAD_STACK_MIN Benjamin Marzinski
2009-03-13 10:51   ` Hannes Reinecke [this message]
2009-03-13 20:55     ` Benjamin Marzinski
2009-03-16 16:12       ` Hannes Reinecke
2009-03-16 23:08         ` Benjamin Marzinski
2009-03-17  7:56           ` Joe Thornber
2009-03-30 23:30             ` Benjamin Marzinski
2009-03-13 11:08   ` Joe Thornber
2009-03-12 18:38 ` [PATCH 3/3] Add options to multipathd to turn off queueing Benjamin Marzinski
2017-04-25 13:38   ` Xose Vazquez Perez
2017-04-25 18:03     ` Benjamin Marzinski
2009-04-03 22:40 ` [PATCH 0/3] Some miscellaneous dm-multipath patches Christophe Varoqui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49BA3ACF.1010101@suse.de \
    --to=hare@suse.de \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.