* [Xenomai-help] pthread_create memory size
@ 2009-07-07 14:06 Yigal Goldberger
2009-07-07 14:11 ` Gilles Chanteperdrix
0 siblings, 1 reply; 7+ messages in thread
From: Yigal Goldberger @ 2009-07-07 14:06 UTC (permalink / raw)
To: xenomai
Hi all,
I'm using xenomai on kernel 2.6.29 on a powerpc based board.
I see that when I call :
cat proc/meminfo
before pthread_create and after it there is a difference of 2MB in free memory , indicating that the thread is being allocated 2MB of ram (?) .
before :
MemTotal: 256868 kB
MemFree: 227624 kB
After :
MemTotal: 256868 kB
MemFree: 225632 kB
I am calling pthread_attr_setstacksize(&attr,8192)
before calling pthread_create so it shouldn't be the stack size .
Is this the expected memory consuption per thread ?
if not, how can I reduce this ?
Thanks ,
Yigal Goldberger.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Xenomai-help] pthread_create memory size
2009-07-07 14:06 [Xenomai-help] pthread_create memory size Yigal Goldberger
@ 2009-07-07 14:11 ` Gilles Chanteperdrix
2009-07-07 14:13 ` Gilles Chanteperdrix
0 siblings, 1 reply; 7+ messages in thread
From: Gilles Chanteperdrix @ 2009-07-07 14:11 UTC (permalink / raw)
To: Yigal Goldberger; +Cc: xenomai
Yigal Goldberger wrote:
> Hi all,
> I'm using xenomai on kernel 2.6.29 on a powerpc based board.
> I see that when I call :
> cat proc/meminfo
> before pthread_create and after it there is a difference of 2MB in free memory , indicating that the thread is being allocated 2MB of ram (?) .
>
> before :
> MemTotal: 256868 kB
> MemFree: 227624 kB
>
> After :
> MemTotal: 256868 kB
> MemFree: 225632 kB
>
> I am calling pthread_attr_setstacksize(&attr,8192)
> before calling pthread_create so it shouldn't be the stack size .
> Is this the expected memory consuption per thread ?
> if not, how can I reduce this ?
That is explained in the TROUBLESHOOTING guide, use ulimit -s. In fact,
I suspect the behaviour depends on the version of the glibc you use. A
better indicator of your process memory map is /proc/pid/maps.
Note that a stacksize of 8K is a bit low, such simple functions as
printf will cause stack overflows with this stack size.
--
Gilles
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Xenomai-help] pthread_create memory size
2009-07-07 14:11 ` Gilles Chanteperdrix
@ 2009-07-07 14:13 ` Gilles Chanteperdrix
0 siblings, 0 replies; 7+ messages in thread
From: Gilles Chanteperdrix @ 2009-07-07 14:13 UTC (permalink / raw)
To: Yigal Goldberger; +Cc: xenomai
Gilles Chanteperdrix wrote:
> Yigal Goldberger wrote:
>> Hi all,
>> I'm using xenomai on kernel 2.6.29 on a powerpc based board.
>> I see that when I call :
>> cat proc/meminfo
>> before pthread_create and after it there is a difference of 2MB in free memory , indicating that the thread is being allocated 2MB of ram (?) .
>>
>> before :
>> MemTotal: 256868 kB
>> MemFree: 227624 kB
>>
>> After :
>> MemTotal: 256868 kB
>> MemFree: 225632 kB
>>
>> I am calling pthread_attr_setstacksize(&attr,8192)
>> before calling pthread_create so it shouldn't be the stack size .
>> Is this the expected memory consuption per thread ?
>> if not, how can I reduce this ?
>
> That is explained in the TROUBLESHOOTING guide, use ulimit -s. In fact,
> I suspect the behaviour depends on the version of the glibc you use.
In particular, if using an old glibc with linuxthreads (that is a really
old glibc), the glibc creates an additional thread when creating the
first thread. The 2MB you see maybe the stack of this additional thread.
--
Gilles
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <206278.72023.qm@domain.hid>]
* Re: [Xenomai-help] pthread_create memory size
[not found] <206278.72023.qm@domain.hid>
@ 2009-07-07 17:41 ` Gilles Chanteperdrix
0 siblings, 0 replies; 7+ messages in thread
From: Gilles Chanteperdrix @ 2009-07-07 17:41 UTC (permalink / raw)
To: Yigal Goldberger; +Cc: Xenomai help
Yigal Goldberger wrote:
> Hi Gilles,
> Thanks for your quick reply.
> I'd like to give some more details based on some expirements I've made .
> I tried an older version of linux and xenomai (linux 2.6.14.7 ) and when I enlarged the requested stack size to 32KB instead of 8KB I saw a **dramatic** reduction in memory consumption per thread (~30MB less!!!).
> I saw that there is some minimum stack size that if trying to create a thread with a smaller value will end up with the default (2MB ?) .
> This improved to some extent the memory usage of my application also in the new version (linux 2.6.29 + new xenoami - recently ported to mpc8272ads by DENX ) , but I am getting the following :
>
> 2.6.14.7 :
> application usage : ~31MB
>
>
> 2.6.29.4
> application usage : ~180MB
>
> The application is the same in both versions , so I can't think of where ~150MB are comming from ?
As I told you in the previous mail, see /proc/pid/maps to see how the
memory is spent.
--
Gilles.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <852117.36446.qm@domain.hid>]
* Re: [Xenomai-help] pthread_create memory size
[not found] <852117.36446.qm@domain.hid>
@ 2009-07-08 8:26 ` Gilles Chanteperdrix
0 siblings, 0 replies; 7+ messages in thread
From: Gilles Chanteperdrix @ 2009-07-08 8:26 UTC (permalink / raw)
To: Yigal Goldberger; +Cc: Xenomai help
Yigal Goldberger wrote:
> Hi again,
> I've performed the cat proc/pid/maps
Ok, could you try /proc/pid/smaps? It gives you the sizes. Anyway:
>
> I see a lot of libraries that were loaded .
> Can you assist me in understanding this output :
>
>
>
> -bash-3.2# cat proc/1203/maps
> uart_ioctl, cmd is 802c7415
> in set_termios
> in change_termios
> 00100000-00103000 r-xp 00100000 00:00 0 [vdso]
> 0fa60000-0fb9c000 r-xp 00000000 00:0b 3577533 /lib/libc-2.6.so
> 0fb9c000-0fbdb000 ---p 0013c000 00:0b 3577533 /lib/libc-2.6.so
> 0fbdb000-0fbdd000 r--p 0013b000 00:0b 3577533 /lib/libc-2.6.so
> 0fbdd000-0fbe0000 rwxp 0013d000 00:0b 3577533 /lib/libc-2.6.so
> 0fbe0000-0fbe3000 rwxp 0fbe0000 00:00 0
> 0fbf3000-0fc06000 r-xp 00000000 00:0b 3577554 /lib/libgcc_s.so.1
> 0fc06000-0fc45000 ---p 00013000 00:0b 3577554 /lib/libgcc_s.so.1
> 0fc45000-0fc46000 rwxp 00012000 00:0b 3577554 /lib/libgcc_s.so.1
> 0fc56000-0fcf6000 r-xp 00000000 00:0b 3577583 /lib/libm-2.6.so
> 0fcf6000-0fd35000 ---p 000a0000 00:0b 3577583 /lib/libm-2.6.so
> 0fd35000-0fd36000 r--p 0009f000 00:0b 3577583 /lib/libm-2.6.so
> 0fd36000-0fd39000 rwxp 000a0000 00:0b 3577583 /lib/libm-2.6.so
> 0fd49000-0fd4c000 r-xp 00000000 00:0b 3508708 /usr/xenomai/lib/librtdm.so.1.0
> .0
> 0fd4c000-0fd8b000 ---p 00003000 00:0b 3508708 /usr/xenomai/lib/librtdm.so.1.0
> .0
> 0fd8b000-0fd8c000 rwxp 00002000 00:0b 3508708 /usr/xenomai/lib/librtdm.so.1.0
> .0
> 0fd9c000-0fe8a000 r-xp 00000000 00:0b 3577648 /lib/libstdc++.so.6.0.9
> 0fe8a000-0fec9000 ---p 000ee000 00:0b 3577648 /lib/libstdc++.so.6.0.9
> 0fec9000-0fecd000 r--p 000ed000 00:0b 3577648 /lib/libstdc++.so.6.0.9
> 0fecd000-0fece000 rwxp 000f1000 00:0b 3577648 /lib/libstdc++.so.6.0.9
> 0fece000-0fed5000 rwxp 0fece000 00:00 0
> 0fee5000-0feec000 r-xp 00000000 00:0b 3577633 /lib/librt-2.6.so
> 0feec000-0ff2b000 ---p 00007000 00:0b 3577633 /lib/librt-2.6.so
> 0ff2b000-0ff2c000 r--p 00006000 00:0b 3577633 /lib/librt-2.6.so
> 0ff2c000-0ff2d000 rwxp 00007000 00:0b 3577633 /lib/librt-2.6.so
> 0ff3d000-0ff51000 r-xp 00000000 00:0b 3577623 /lib/libpthread-2.6.so
> 0ff51000-0ff91000 ---p 00014000 00:0b 3577623 /lib/libpthread-2.6.so
> 0ff91000-0ff92000 r--p 00014000 00:0b 3577623 /lib/libpthread-2.6.so
> 0ff92000-0ff93000 rwxp 00015000 00:0b 3577623 /lib/libpthread-2.6.so
> 0ff93000-0ff95000 rwxp 0ff93000 00:00 0
> 0ffa5000-0ffb0000 r-xp 00000000 00:0b 3509109 /usr/xenomai/lib/libpthread_rt.
> so.1.0.0
> 0ffb0000-0ffef000 ---p 0000b000 00:0b 3509109 /usr/xenomai/lib/libpthread_rt.
> so.1.0.0
> 0ffef000-0fff0000 rwxp 0000a000 00:0b 3509109 /usr/xenomai/lib/libpthread_rt.
> so.1.0.0
> 10000000-1003e000 r-xp 00000000 00:0b 3509108 /802Rdr
> 1007e000-1007f000 rwxp 0003e000 00:0b 3509108 /802Rdr
> 1007f000-10081000 rwxp 1007f000 00:00 0
> 10081000-100eb000 rwxp 10081000 00:00 0 [heap]
> 48000000-4801d000 r-xp 00000000 00:0b 3577520 /lib/ld-2.6.so
> 4801d000-4801e000 rw-p 4801d000 00:00 0
> 4801e000-4801f000 rw-p 4801e000 00:00 0
> 4801f000-48020000 rw-s 10000000 00:0b 3506904 /dev/mem
> 48020000-48021000 rw-s 00010000 00:0b 3506904 /dev/mem
> 48023000-48026000 rw-p 48023000 00:00 0
> 48026000-4802e000 rw-s 10010000 00:0b 3506904 /dev/mem
> 4805c000-4805d000 r--p 0001c000 00:0b 3577520 /lib/ld-2.6.so
> 4805d000-4805e000 rwxp 0001d000 00:0b 3577520 /lib/ld-2.6.so
> 4805e000-4805f000 ---p 4805e000 00:00 0
> 4805f000-4885e000 rw-p 4805f000 00:00 0
This is typically a thread stack: the page with only the 'p' flag is the
"guard page", which will cause a segmentation fault in case of stack
overflow. The other area is the stack, its size is 8 MB.
> 4885e000-4885f000 ---p 4885e000 00:00 0
> 4885f000-4905e000 rw-p 4885f000 00:00 0
8 MB
etc...
> 4d85e000-4d85fuart_ioctl, cmd is 402c7413
These uart_ioctl are printks in one of your drivers probably
> bfe75000-bfe8a000 rw-p bffeb000 00:00 0 [stack]
The main thread stack, strangely, is only 86K large (I believe it is
allocated on demand).
Did you try to check pthread_attr_setstacksize return value when calling it?
Please do not forget to cc the mailing list.
--
Gilles
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Xenomai-help] pthread_create memory size
@ 2009-07-08 10:52 Yigal Goldberger
2009-07-08 11:12 ` Gilles Chanteperdrix
0 siblings, 1 reply; 7+ messages in thread
From: Yigal Goldberger @ 2009-07-08 10:52 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
Hi Gilles,
I enlarged the stack size during thread creation to 256KB and reduced the memory usage by ~140MB , this is roughly explained by an 8MB stack per thread .So there is no memory problem .
Your quick and helpful responses are much appreciated.
Yigal Goldberger.
--- On Wed, 7/8/09, Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org> wrote:
> From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
> Subject: Re: [Xenomai-help] pthread_create memory size
> To: "Yigal Goldberger" <yigal_gold@domain.hid>
> Cc: "Xenomai help" <xenomai@xenomai.org>
> Date: Wednesday, July 8, 2009, 11:26 AM
> Yigal Goldberger wrote:
> > Hi again,
> > I've performed the cat proc/pid/maps
>
> Ok, could you try /proc/pid/smaps? It gives you the sizes.
> Anyway:
>
> >
> > I see a lot of libraries that were loaded .
> > Can you assist me in understanding this output :
> >
> >
> >
> > -bash-3.2# cat proc/1203/maps
> > uart_ioctl, cmd is 802c7415
> > in set_termios
> > in change_termios
> > 00100000-00103000 r-xp 00100000 00:00 0
> [vdso]
> > 0fa60000-0fb9c000 r-xp 00000000 00:0b 3577533
> /lib/libc-2.6.so
> > 0fb9c000-0fbdb000 ---p 0013c000 00:0b 3577533
> /lib/libc-2.6.so
> > 0fbdb000-0fbdd000 r--p 0013b000 00:0b 3577533
> /lib/libc-2.6.so
> > 0fbdd000-0fbe0000 rwxp 0013d000 00:0b 3577533
> /lib/libc-2.6.so
> > 0fbe0000-0fbe3000 rwxp 0fbe0000 00:00 0
> > 0fbf3000-0fc06000 r-xp 00000000 00:0b 3577554
> /lib/libgcc_s.so.1
> > 0fc06000-0fc45000 ---p 00013000 00:0b 3577554
> /lib/libgcc_s.so.1
> > 0fc45000-0fc46000 rwxp 00012000 00:0b 3577554
> /lib/libgcc_s.so.1
> > 0fc56000-0fcf6000 r-xp 00000000 00:0b 3577583
> /lib/libm-2.6.so
> > 0fcf6000-0fd35000 ---p 000a0000 00:0b 3577583
> /lib/libm-2.6.so
> > 0fd35000-0fd36000 r--p 0009f000 00:0b 3577583
> /lib/libm-2.6.so
> > 0fd36000-0fd39000 rwxp 000a0000 00:0b 3577583
> /lib/libm-2.6.so
> > 0fd49000-0fd4c000 r-xp 00000000 00:0b 3508708
> /usr/xenomai/lib/librtdm.so.1.0
> > .0
> > 0fd4c000-0fd8b000 ---p 00003000 00:0b 3508708
> /usr/xenomai/lib/librtdm.so.1.0
> > .0
> > 0fd8b000-0fd8c000 rwxp 00002000 00:0b 3508708
> /usr/xenomai/lib/librtdm.so.1.0
> > .0
> > 0fd9c000-0fe8a000 r-xp 00000000 00:0b 3577648
> /lib/libstdc++.so.6.0.9
> > 0fe8a000-0fec9000 ---p 000ee000 00:0b 3577648
> /lib/libstdc++.so.6.0.9
> > 0fec9000-0fecd000 r--p 000ed000 00:0b 3577648
> /lib/libstdc++.so.6.0.9
> > 0fecd000-0fece000 rwxp 000f1000 00:0b 3577648
> /lib/libstdc++.so.6.0.9
> > 0fece000-0fed5000 rwxp 0fece000 00:00 0
> > 0fee5000-0feec000 r-xp 00000000 00:0b 3577633
> /lib/librt-2.6.so
> > 0feec000-0ff2b000 ---p 00007000 00:0b 3577633
> /lib/librt-2.6.so
> > 0ff2b000-0ff2c000 r--p 00006000 00:0b 3577633
> /lib/librt-2.6.so
> > 0ff2c000-0ff2d000 rwxp 00007000 00:0b 3577633
> /lib/librt-2.6.so
> > 0ff3d000-0ff51000 r-xp 00000000 00:0b 3577623
> /lib/libpthread-2.6.so
> > 0ff51000-0ff91000 ---p 00014000 00:0b 3577623
> /lib/libpthread-2.6.so
> > 0ff91000-0ff92000 r--p 00014000 00:0b 3577623
> /lib/libpthread-2.6.so
> > 0ff92000-0ff93000 rwxp 00015000 00:0b 3577623
> /lib/libpthread-2.6.so
> > 0ff93000-0ff95000 rwxp 0ff93000 00:00 0
> > 0ffa5000-0ffb0000 r-xp 00000000 00:0b 3509109
> /usr/xenomai/lib/libpthread_rt.
> > so.1.0.0
> > 0ffb0000-0ffef000 ---p 0000b000 00:0b 3509109
> /usr/xenomai/lib/libpthread_rt.
> > so.1.0.0
> > 0ffef000-0fff0000 rwxp 0000a000 00:0b 3509109
> /usr/xenomai/lib/libpthread_rt.
> > so.1.0.0
> > 10000000-1003e000 r-xp 00000000 00:0b 3509108
> /802Rdr
> > 1007e000-1007f000 rwxp 0003e000 00:0b 3509108
> /802Rdr
> > 1007f000-10081000 rwxp 1007f000 00:00 0
> > 10081000-100eb000 rwxp 10081000 00:00 0
> [heap]
> > 48000000-4801d000 r-xp 00000000 00:0b 3577520
> /lib/ld-2.6.so
> > 4801d000-4801e000 rw-p 4801d000 00:00 0
> > 4801e000-4801f000 rw-p 4801e000 00:00 0
> > 4801f000-48020000 rw-s 10000000 00:0b 3506904
> /dev/mem
> > 48020000-48021000 rw-s 00010000 00:0b 3506904
> /dev/mem
> > 48023000-48026000 rw-p 48023000 00:00 0
> > 48026000-4802e000 rw-s 10010000 00:0b 3506904
> /dev/mem
> > 4805c000-4805d000 r--p 0001c000 00:0b 3577520
> /lib/ld-2.6.so
> > 4805d000-4805e000 rwxp 0001d000 00:0b 3577520
> /lib/ld-2.6.so
> > 4805e000-4805f000 ---p 4805e000 00:00 0
> > 4805f000-4885e000 rw-p 4805f000 00:00 0
>
> This is typically a thread stack: the page with only the
> 'p' flag is the
> "guard page", which will cause a segmentation fault in case
> of stack
> overflow. The other area is the stack, its size is 8 MB.
>
> > 4885e000-4885f000 ---p 4885e000 00:00 0
> > 4885f000-4905e000 rw-p 4885f000 00:00 0
>
> 8 MB
>
> etc...
>
>
> > 4d85e000-4d85fuart_ioctl, cmd is 402c7413
>
> These uart_ioctl are printks in one of your drivers
> probably
>
> > bfe75000-bfe8a000 rw-p bffeb000 00:00 0
> [stack]
>
> The main thread stack, strangely, is only 86K large (I
> believe it is
> allocated on demand).
>
> Did you try to check pthread_attr_setstacksize return value
> when calling it?
>
> Please do not forget to cc the mailing list.
>
> --
>
>
> Gilles
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Xenomai-help] pthread_create memory size
2009-07-08 10:52 Yigal Goldberger
@ 2009-07-08 11:12 ` Gilles Chanteperdrix
0 siblings, 0 replies; 7+ messages in thread
From: Gilles Chanteperdrix @ 2009-07-08 11:12 UTC (permalink / raw)
To: Yigal Goldberger; +Cc: xenomai
Yigal Goldberger wrote:
> Hi Gilles,
>
> I enlarged the stack size during thread creation to 256KB and reduced
> the memory usage by ~140MB , this is roughly explained by an 8MB
> stack per thread .So there is no memory problem . Your quick and
> helpful responses are much appreciated.
Ok. But to avoid doing this tuning blindly, you can use
PTHREAD_STACK_MIN, and I believe checking pthread_attr_setstacksize
return value should tell you if the stack size you try is accepted.
--
Gilles.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-07-08 11:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-07 14:06 [Xenomai-help] pthread_create memory size Yigal Goldberger
2009-07-07 14:11 ` Gilles Chanteperdrix
2009-07-07 14:13 ` Gilles Chanteperdrix
[not found] <206278.72023.qm@domain.hid>
2009-07-07 17:41 ` Gilles Chanteperdrix
[not found] <852117.36446.qm@domain.hid>
2009-07-08 8:26 ` Gilles Chanteperdrix
-- strict thread matches above, loose matches on Subject: below --
2009-07-08 10:52 Yigal Goldberger
2009-07-08 11:12 ` Gilles Chanteperdrix
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.