Too much on the stack?

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Re: Too much on the stack?

    Michael B Allen wrote:
    > On Sat, 21 Jun 2003 13:05:15 -0400, Paul Pluzhnikov wrote:
    >
    >>> Why doesn't the following program overrun the stack?
    >>
    >> Why should it? Your 'ulimit' is apparently set higher than 6.5M ... The
    >> only reason for this program to run out of stack is if it exceeds stack
    >> ulimit, or comes close to where shared libraries are mapped. The 'ulimit
    >> -s' is quite often unlimited, and shared libraries on Linux are usually
    >> mapped up from 0x40000000.
    >
    > Interesting! I didn't know this. Ulimit is indeed set to 'unlimited'.
    >
    >> If you do not have gazillion of very large shared libraries, their
    >> mappings are quite likely to stay below 0x50000000, which gives your
    >> program quite a few more megabytes to grow.
    >>
    >>> How much is too much on the stack?
    >>
    >> That depends on your OS, and whether you ever plan to use your code in
    >> multi-threaded environment, where stack sizes are significantly more
    >> limited (Linux default is 8MB IIRC).
    >
    > The code is actually using pthreads. A thread will be calling this
    > function.
    >
    The pthreads I've used (RH 7.3, glibc 2.2.5) allocated a separate 2MB stack
    space for each thread. If you set your ulimit stack space to unlimited you
    might have threads stepping on each other's stack.

    --
    Al Dunstan, Software Engineer
    OptiMetrics, Inc.
    3115 Professional Drive
    Ann Arbor, MI 48104-5131

    "To educate a man in mind and not in morals is to
    educate a menace to society."
    - Theodore Roosevelt

    A. W. Dunstan Guest

  2. Similar Questions and Discussions

    1. Stack Overflow Error - Need Help!
      We have a server on which we are running CF MX 7 Enterprise. It is a Windows 2000 Server (service pack 4). It is talking to a SQL Server 2000...
    2. get the Java stack trace
      hi, is there a way to get the full java stack trace when an exception is occured? May be a cfcatch or cferror variable that contains this stack? Do...
    3. Out of stack space
      Hello, I'm using iis 5 on windows 2000 Pro. I have a recursive function. If the recursion is too big, I get a "Out of stack space" error. On a...
    4. GC and the stack
      Hello, As far as I understand the ruby gc will not collect objects that are referenced from the stack, ie the "C/native" stack in a ruby...
    5. Ruby GC eating my VALUE on the stack
      I thought I had read everything I needed about the Ruby GC, but something just popped up that took me by surprise. I am allocating a structure...
  3. #2

    Default Re: Too much on the stack?

    "A. W. Dunstan" <readHere@post.here> writes:
    > The pthreads I've used (RH 7.3, glibc 2.2.5) allocated a separate 2MB stack
    > space for each thread.
    You are correct on this point.
    > If you set your ulimit stack space to unlimited you
    > might have threads stepping on each other's stack.
    But quite mistaken on that one, for 2 reasons:

    - 'ulimit -s' has *absolutely nothing* to with sizes of thread
    stacks, and

    - the thread manager puts a guard page (mprotect()ed with no access)
    at the end of each 2MB stack region, so before a thread can
    "step on other's stack", it will crash accessing the guard page.

    That's not to say that a thread can't trash other thread's stack
    due to a bad pointer ... But 'ulimit -s' has nothing to do with this.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Paul Pluzhnikov Guest

  4. #3

    Default Re: Too much on the stack?

    In article <uhe6ej0za.fsfYB8X@earthlink.net>
    Paul Pluzhnikov <ppluzhnikov@earthlink.net> writes:
    >- the thread manager puts a guard page (mprotect()ed with no access)
    > at the end of each 2MB stack region, so before a thread can
    > "step on other's stack", it will crash accessing the guard page.
    Unless, of course, you skip right over the guard page.

    If the page size is 4096 bytes and you allocate at least 8192
    bytes (via "sub $8192,sp" or equivalent), you have a good chance
    of doing just that.
    --
    In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it [url]http://67.40.109.61/torek/index.html[/url] (for the moment)
    Reading email is like searching for food in the garbage, thanks to spammers.
    Chris Torek Guest

  5. #4

    Default Search for stream program

    Hi All,

    I'm a green hand on stream programming.

    Does someone give me some good links or easy example on this?

    Thanks in advance!

    Cliff



    Cliff Fu Xuan Chen Guest

  6. #5

    Default Search for stream program

    Hi All,

    I'm a green hand on stream programming.

    Does someone give me some good links or easy example on this?

    Thanks in advance!

    Cliff



    Cliff Fu Xuan Chen Guest

  7. #6

    Default Re: Search for stream program

    In article <3F02AC70.8F1145B9@lucent.com>,
    Cliff Fu Xuan Chen <fchen7@lucent.com> writes:
    >
    > Hi All,
    >
    > I'm a green hand on stream programming.
    >
    > Does someone give me some good links or easy example on this?
    You don't say which UNIX, but if it's Solaris, then look at Sun's
    STREAMS Programming Manual, [url]http://docs.sun.com/db/doc/806-6546[/url]
    Much of this will be relevant to non-Solaris UNIXs with STREAMS
    too, but the module loading and multi-threaded kernel parts will
    be Solaris-specific.

    PS, please turn off the HTML posting.

    --
    Andrew Gabriel
    Consultant Software Engineer
    Andrew Gabriel Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139