Re: Problem with mlockall() and Threads: memory usage

From: Terry Barnaby (terry1_at_beam.ltd.uk)
Date: 05/19/04

  • Next message: Jan Kasprzak: "sendfile -EOVERFLOW on AMD64"
    Date:	Wed, 19 May 2004 09:45:27 +0100
    To: davids@webmaster.com
    
    

    Hi David,

    We do want improved latency, but with reasonable memory usage. This is
    a soft real-time system. At the moment the memory usage is far too high in
    our application.

    With 20 threads runing the system will lock 160MBytes of memory just for stack
    space (8 MBytes each), although the application probably only needs 2MByte in
    total.
    We can reduce the maximum stack size per thread, but then if a thread
    increases its stack size beyond this the application will crash with a
    segment fault, not good ...

    For our use, mapping in physical memory as required for a growing stack would be
    a good compromise between latency and memory usage. Once the system has run the
    worker threads for a short time all of the needed stack memory will be locked in
    and latency will be controlled. If a thread needs more memory for stack in a particular
    instance, there will be a latency hit but this would be acceptable and
    much better than a crash.

    Terry

    David Schwartz wrote:
    >>Thanks for that.
    >>I have done some more investigating, and on my system (Standard RedHat 9)
    >>the stack ulimit is set to 8192 KBytes. So it appears that the thread
    >>library/kernel threads pre-allocates, and writes to, 8129 KBytes
    >>of stack per
    >>thread and so then mlockall() locks all of this in memory.
    >>
    >>Should'nt the Thread library grow the stack rather than
    >>preallocate it all even
    >>with mlockall() like malloc ?
    >
    >
    > I thought you wanted improved latency. Surely having to find a page for you
    > when your stack grows will add unpredictable latency. So, no, the thread
    > library should reserve the stack when 'mlockall(MCL_FUTURE)' is specified.
    >
    > I do agree that having an 'initial stack size' in additional to a 'maximum
    > stack size' would be a good idea. The former good for application that are
    > concerned about physical memory usage and the latter for applications
    > concerned about virtual memory usage.
    >
    > DS
    >
    >
    > -
    > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    > the body of a message to majordomo@vger.kernel.org
    > More majordomo info at http://vger.kernel.org/majordomo-info.html
    > Please read the FAQ at http://www.tux.org/lkml/
    >

    -- 
    Dr Terry Barnaby                     BEAM Ltd
    Phone: +44 1454 324512               Northavon Business Center, Dean Rd
    Fax:   +44 1454 313172               Yate, Bristol, BS37 5NH, UK
    Email: terry@beam.ltd.uk             Web: www.beam.ltd.uk
    BEAM for: Visually Impaired X-Terminals, Parallel Processing, Software
                           "Tandems are twice the fun !"
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Jan Kasprzak: "sendfile -EOVERFLOW on AMD64"

    Relevant Pages

    • Re: java.lang.StackOverflowError
      ... could i avoid the stackoverflow by resizing the ... stack, that eclipse should set really small by default value as some ... then you're memory usage is probably exponential ...
      (comp.lang.java.programmer)
    • Re: How to get process info from python
      ... '''Return process memory usage in bytes. ... '''Return process stack size in bytes. ... >> I've had to work with process data in the past, and you're right, a ... >> the module's functionality. ...
      (comp.lang.python)
    • Re: Problem with mlockall() and Threads: memory usage
      ... > We do want improved latency, but with reasonable memory usage. ... We can reduce the maximum stack size per ... > stack would be a good compromise between latency and memory usage. ...
      (Linux-Kernel)
    • Re: Sleep function in vb.net
      ... Swaps in the Next thread Y code, stack, memory usage from storage, ... instruction and stack pointers are swapped, along with other registers such as the stack pointer. ... We use this for all our internet hosting servers - SMTP, POP3, IMAP, FTP and other internal client/server protocol servers. ...
      (microsoft.public.dotnet.languages.vb)
    • Re: Sleep function in vb.net
      ... Swaps in the Next thread Y code, stack, memory usage from storage, ... Cmp EAX, B ' Compare EAX with B, and saves the result to CPU's flags ...
      (microsoft.public.dotnet.languages.vb)