FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 03-13-2009, 10:08 AM
Joe Thornber
 
Default 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
");
> @@ -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
");
> 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
>

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 03-17-2009, 06:56 AM
Joe Thornber
 
Default set pthread stack size to at least PTHREAD_STACK_MIN

2009/3/16 Benjamin Marzinski <bmarzins@redhat.com>:
> I definitely see a problem if we use the default stacksize on ia64
> machines. *In RHEL5 at least, it's 10Mb per thread. *With one waiter
> thread per multipath device, you get a gigabyte of memory wasted on
> machines with over a hundred multipath devices.

You need to check whether this is 1G of physical memory, or just a 1G
chunk out of the address space.

Some threads need to have their stack reserved and locked into memory
before calls into the kernel. This avoids deadlocks where the stack
gets paged out, but he vm can't page it back in until the thread
completes ...

It sounds like you have many more threads running these days than when
I last looked at LVM, it's not clear to me how many of these are ones
that need their stacks mem-locking. Do you have an idea ?

If they don't need mem-locking then as long as you're not forcing the
stack to be physically allocated I wouldn't worry too much about
consuming address space.

Hope that ramble made sense,

- Joe

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 07:08 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org