From: Dermot McGahon <dmcgahon@waratek.com>
To: linux-mm@kvack.org
Subject: Fwd: CGroups and pthreads
Date: Wed, 29 Jan 2014 17:15:23 +0000 [thread overview]
Message-ID: <CALaYU_AA8fMLmp_Ng9Mhm0ztcXA0EHCxkU3p68tKs87G48NrOw@mail.gmail.com> (raw)
In-Reply-To: <CALaYU_BZ8iuHnAgkss1wO7BK3qULgotYSpmX4nqX=uC+aTnddA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1998 bytes --]
Forwarding a question that was first asked on cgroups mailing list.
Someone recommended asking here instead. We believe that we received
the correct answer, which is that cgroup memory subsystem charges
always to the leader of the Process Group rather than to the TID.
Could someone confirm that is definitely the case (testing does bear
that out). It does make sense to us, since who is to say which thread
should the process shared memory be accounted to. Unfortunately, in
our specific scenario, which is a JVM that generally allocated out of
the heap but occasionally loads native libraries that can allocate
using malloc() in known threads, we would have that information. But
we can see that in the general case it may not be that useful to
account per-thread.
Would appreciate any comments you may have.
-----------
Question originally posted to cgroups mailing list:
Is it possible to apply cgroup memory subsystem controls to threads
created with pthread_create() / clone or only tasks that have been
created using fork and exec?
In testing, we seem to be seeing that all allocations are accounted
for against the PPID / TGID and never the pthread_create()'d TID, even
though the TID is an LWP and can be seen using top (though RSS is
aggregate and global of course).
Attached is a simple test program used to print PID / TID and allocate
memory from a cloned TID. After setting breakpoints in child and
parent and setting up a cgroups hierarchy of 'parent' and 'child',
apply memory.limit_in_bytes and memory.memsw.limit_in_bytes to the
child cgroup only and adding the PID to the parent group and the TID
to the child group we see that behaviour.
Is that expected? I realise that the subsystems are all different but
what is confusing us slightly is that we have previously used the CPU
subsystem to set cpu_shares and adding LWP / TID's to individual
cgroups worked just fine for that
Am I misconfiguring somehow or is this a known difference between CPU
and MEMORY subsystems?
[-- Attachment #2: pthread_test.c --]
[-- Type: text/x-csrc, Size: 1094 bytes --]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/syscall.h>
void thread_func()
{
printf( "thread pid=%d, thread tid=%d\n", getpid(), syscall( SYS_gettid ) );
size_t one_hundred_mb = 100 * 1024 * 1024;
void * allocatedChunk = malloc ( one_hundred_mb );
memset( allocatedChunk, 0, one_hundred_mb );
if ( allocatedChunk == NULL )
{
printf("couldn't allocate\n");
}
else
{
int tid = syscall( SYS_gettid );
printf( "PID: %d, TID: %d - has allocated 100mb\n", getpid(), syscall( SYS_gettid ) );
}
sleep(1000);
}
void main()
{
printf( "main pid=%d, main tid=%d\n", getpid(), syscall( SYS_gettid ) );
pthread_t thread1;
pthread_create( &thread1, NULL, (void *)&thread_func, NULL);
/* pid_t childpid;
childpid = fork();
if ( childpid >= 0 )
{
if ( childpid == 0 )
{
thread_func(); // child
}
else
{
sleep(1000); // parent
}
}
else
{
perror("fork");
exit(0);
} */
sleep(1000);
}
next parent reply other threads:[~2014-01-29 17:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CALaYU_BZ8iuHnAgkss1wO7BK3qULgotYSpmX4nqX=uC+aTnddA@mail.gmail.com>
2014-01-29 17:15 ` Dermot McGahon [this message]
2014-01-31 20:24 ` James Bottomley
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=CALaYU_AA8fMLmp_Ng9Mhm0ztcXA0EHCxkU3p68tKs87G48NrOw@mail.gmail.com \
--to=dmcgahon@waratek.com \
--cc=linux-mm@kvack.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox