All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Jeremy Friesner <jaf@domain.hid>
Cc: xenomai@xenomai.org, Jeff Koftinoff <jeffk@domain.hid>
Subject: Re: [Xenomai-help] Xenomai 2.5.3 process doubles its memory footprint when spawning a subprocess?
Date: Fri, 26 Aug 2011 23:04:33 +0200	[thread overview]
Message-ID: <4E580A61.8020107@domain.hid> (raw)
In-Reply-To: <2BB74055-EB0C-4474-BA76-BE4227C56B50@domain.hid>

On 08/26/2011 10:54 PM, Jeremy Friesner wrote:
> I suspect that is has something to do with mlockall() and/or some
> other aspect of Xenomai partially or fully defeating the fork()
> call's Copy-On-Write feature, meaning that when the sub-process is
> spawned, most or all of the RAM pages allocated by the parent process
> are being duplicated, even though they are all going to be thrown
> away again immediately because I'm going to call exec() right
> afterwards.

The "copy-on-write" feature causes faults both in the parent and child
process, which causes threads to exit primary mode. So, in order to
avoid it, we duplicate the memory space when forking.

> 
> My question is, is there some recommended way to launch a sub-process
> from a large Xenomai process that will avoid massive amounts of
> overhead?  I suppose I could launch a separate, persistent,
> non-Xenomai process that would act as a "non-Xenomai process server",
> and connect to it via TCP and ask it to spawn processes on my
> behalf.... but that seems like an awful lot of extra work.  Is there
> an easier way around this problem?

If what you intend is to execute another thread, you do not need to use
fork(), you can use vfork() which will avoid the issue you are
mentioning. Normally, if you are using a recent libc, system() already
uses vfork().

It is also worth mentioning that the reason why your process consumes so
much memory in the first place may be because of the space allocated for
the threads stacks (2MB by default), because of mlockall. So, if you are
using the posix API, think about setting the stacks sizes to a more
reasonable size with pthread_attr_setstacksize.

-- 
                                                                Gilles.


  reply	other threads:[~2011-08-26 21:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26 20:54 [Xenomai-help] Xenomai 2.5.3 process doubles its memory footprint when spawning a subprocess? Jeremy Friesner
2011-08-26 21:04 ` Gilles Chanteperdrix [this message]
2011-08-26 22:37   ` Jeremy Friesner

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=4E580A61.8020107@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=jaf@domain.hid \
    --cc=jeffk@domain.hid \
    --cc=xenomai@xenomai.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 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.