Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

typical size of task_struct

1,318 views
Skip to first unread message

Jan Helgesen

unread,
Oct 7, 2009, 10:36:40 AM10/7/09
to

So we have put behind us lots of confusions in the last dicsussion, so I
will rephrase my question in the hopes of getting closer to an answer.

Does anybody know what the typical size of a task_struct, with
associated structure, is? Associated structures would be for example be
mm_struct, vm_area_struct etc

By typical I man with the kernel config used in for example Ubuntu
Server, Debian, RedHat and similar weel know and used installations?

From the definition i see in

http://lxr.linux.no/#linux+v2.6.31/include/linux/sched.h

It seems that the structure is not that small, and especially when alle
the associated structures are included.
I get the feeling that one must expect a task structure to be perhaps
1KB or more.


regards

Jan

Chris Friesen

unread,
Oct 7, 2009, 12:18:45 PM10/7/09
to
On 10/07/2009 08:36 AM, Jan Helgesen wrote:
>
>
> So we have put behind us lots of confusions in the last dicsussion, so I
> will rephrase my question in the hopes of getting closer to an answer.
>
> Does anybody know what the typical size of a task_struct, with
> associated structure, is? Associated structures would be for example be
> mm_struct, vm_area_struct etc

On my desktop (probably with various debug options enabled) the
task_struct alone is 3272 bytes. (Obtained from
/sys/kernel/slab/task_struct/object_size.)

The mm_struct (512 bytes on my desktop) is a per-process structure, so
needs to be counted separately. In a multithreaded process there is
only one mm_struct regardless of the number of threads.

However, there are additional overheads. There is also a per-task
kernel stack (usually 4K) and the userspace stack
(application-adjustable, but usually defaults to 2 or 4MB).

Chris

Jan Helgesen

unread,
Oct 9, 2009, 1:45:54 AM10/9/09
to

Chris Friesen wrote:
>
> On my desktop (probably with various debug options enabled) the
> task_struct alone is 3272 bytes. (Obtained from
> /sys/kernel/slab/task_struct/object_size.)

On mine it shows 3212 bytes, so its about the same,

> The mm_struct (512 bytes on my desktop) is a per-process structure, so
> needs to be counted separately. In a multithreaded process there is
> only one mm_struct regardless of the number of threads.
>
> However, there are additional overheads. There is also a per-task
> kernel stack (usually 4K) and the userspace stack
> (application-adjustable, but usually defaults to 2 or 4MB).

So if Erlang only has a thread kernel size of 350 bytes, Linux has a
threads size which is 10 times larger.

Now is it possible to shrink the size if the threads structure, I know
there are lots of ifdefs in the code, but a lot of them only apply for
special setups. Admitedly, in general distros like RedHat and Ubuntu, a
lot of it is enabled just in case someone needs it, so thats one way to
optimise it. But do you think there is stuff there that dont is not that
necessary to include or would a lot of that be shared structures any way?

regards

Jan

> Chris

Chris Friesen

unread,
Oct 9, 2009, 10:53:17 AM10/9/09
to
On 10/08/2009 11:45 PM, Jan Helgesen wrote:

> So if Erlang only has a thread kernel size of 350 bytes, Linux has a
> threads size which is 10 times larger.

This is incorrect. Erlang implements its own "processes" (different
than posix processes/threads). The per-"process" cost is about 300
words, or 1200 bytes on a 32-bit system. The per-"process" overhead in
erlang would be in userspace in the erlang runtime system, not in the
kernel.

> Now is it possible to shrink the size if the threads structure, I know
> there are lots of ifdefs in the code, but a lot of them only apply for
> special setups. Admitedly, in general distros like RedHat and Ubuntu, a
> lot of it is enabled just in case someone needs it, so thats one way to
> optimise it. But do you think there is stuff there that dont is not that
> necessary to include or would a lot of that be shared structures any way?

You can reduce the size of the task struct by adjusting the config
options, but certainly not by a factor of 10.

Chris

Jan Helgesen

unread,
Oct 10, 2009, 4:33:17 AM10/10/09
to

Chris Friesen wrote:
> On 10/08/2009 11:45 PM, Jan Helgesen wrote:
>
>> So if Erlang only has a thread kernel size of 350 bytes, Linux has a
>> threads size which is 10 times larger.
>
> This is incorrect. Erlang implements its own "processes" (different
> than posix processes/threads).

Well, with hardware support for that the kind of ultralightweight
threads that Erlang requires, it would be a different matter. I don't
know if there are any processors that do provide it, but hopefully one
of the future processors that support massive parallelism will support it.

> The per-"process" cost is about 300
> words,

Not quite, of those 300 words (more specifically 309 words), 233 is the
stack. so only 67 is the process structure. 67 words of 16 bits is 134
bytes. with 32 bits is 268 bytes. The task_struct on my Linux machine is
3200 bytes, and that does not include the 500 bytes for mm_struct.
Additionally the stack in erland is 233 words which is 466 bytes or 932
bytes.

That makes an erlang process take up, with a stack, 618 or 1236 bytes.
Compared to Linuxs approx 7700 bytes.

> or 1200 bytes on a 32-bit system.

Not necessarily. It depends on the architecture of the hardware and the
language used to program it. IA-32 defines a word as 16 bit, that is
because of compatibility with x86. Java, for example, defines it as 32
bits and so on.

> You can reduce the size of the task struct by adjusting the config
> options, but certainly not by a factor of 10.

Ok, thanks.

regards

Jan

0 new messages