Re: ten thousand small processes

From: Chuck Swiger (cswiger_at_mac.com)
Date: 06/26/03

  • Next message: D. J. Bernstein: "Re: The dangers of replacing malloc()"
    Date: Thu, 26 Jun 2003 15:04:41 -0400
    To: freebsd-performance@freebsd.org
    
    

    D. J. Bernstein wrote:
    >> Remember that VMM hardware requires page-alignment
    >
    > When I ask why the stack and data aren't put on the same page, and you
    > say ``They aren't on the same page,'' you aren't answering the question.

    True. If A implies B, yet A is false, what have you shown about B?

    I didn't write the words "They aren't on the same page". What I wrote was
    "stack and data have different VM protections and, since VMM hardware requires
    page alignment, the stack and data need to be put on different pages."

    If you don't think the latter paraphrase is a valid answer to the question you
    asked, fine, say so: quoting a single phrase from the three paragraphs I wrote,
    and then adapting it to the point where you can complain that what I didn't say
    didn't answer your question has more to do with rhetorical strawmen. Thanks.

    > (As for adding an x bit to data: This obviously won't break anything.)

    Using VMM protection to forbid code execution within the DATA, BSS, heap, and
    stack (if one can) mitigates against a common class of problems-- "buffer
    overflows"-- which have lead to a vast number of security vulnerabilities.

    Well-written programs do not require VMM hardware to protect them from such
    issues, but that doesn't mean that a general-purpose OS like FreeBSD should
    assume that all programs are well-written.

    [ ... ]
    >> It's easy to write a memory allocator that performs a specific case well;
    >> writing a general purpose malloc is significantly more complicated,
    >
    > I'm not talking about replacing malloc() with a special-purpose
    > allocator. I'm talking about adding a tiny bit of code to malloc() to
    > magically take advantage of space that is being ignored right now.
    >
    > The savings in this situation go beyond those dozens of megabytes of
    > magically reacquired RAM. There's a nasty spike in memory usage as soon
    > as malloc() starts extending the heap; when a program's allocations fit
    > into the magically reacquired RAM, the program also avoids the spike.

    Calling malloc(1) for the first time causes a 16K spike in memory usage under
    FreeBSD 4.8; that's a factor of four larger than the minimum possible allocation
    of one 4K page.

    [ It's not clear whether all four VM pages are actually allocated, or whether
    one is and three are waiting for a write-fault before the system allocates
    resources for them. It's also worth noting that malloc() has to return memory
    properly aligned to whatever the local hardware requires for arbitrary data
    types: malloc(1), malloc(4), and even malloc(16) might all reserve the same
    amount of space. ]

    With regard to your magic suggestion, frankly, what you are doing is solving a
    much easier problem domain than the general purpose malloc is expected to be
    capable of solving. Linear memory allocation and no provision to handle
    internal fragmentation (because you'll never release or reuse in this buffer of
    memory, yes?) are wonderful decisions for a memory allocator tuned for a very
    small program. So long as the program doesn't repeatedly allocate and free this
    memory, anyway.

    -- 
    -Chuck
    _______________________________________________
    freebsd-performance@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-performance
    To unsubscribe, send any mail to "freebsd-performance-unsubscribe@freebsd.org"
    

  • Next message: D. J. Bernstein: "Re: The dangers of replacing malloc()"

    Relevant Pages

    • Re: Error Raising and Memory in VB (general question)
      ... > object is terminated go out of scope, and the memory is also released. ... But why are you saying it uses stack? ... I think we are dealing with heap memory here. ... "COM's IMalloc allocator: ...
      (microsoft.public.vb.general.discussion)
    • Re: ten thousand small processes
      ... Stack needs to be executable for the current signal trampoline ... the use of malloc() that is causing your primary ... if there is any heap memory in use at all, no matter what you do, ... either directly, as a 4M page mapping (not used for user processes, ...
      (freebsd-performance)
    • Re: style question,itoa
      ... able to allocate buffers in some convenient location the callee ... dynamically allocate a block of memory and computing this size to use ... call might require allocating a page for the stack. ... " Checking every single malloc in a bigger application for possible ...
      (comp.unix.programmer)
    • Re: malloc options
      ... Malloc was significantly changed with 7.0 and reading through the malloc man page there are a number of flags that can be set with /etc/ malloc.conf. ... If you did recompile it and it is behaving differently then it is probably because your program contains bugs in how it manages memory that happened to be working by accident with the old memory allocator. ...
      (freebsd-questions)
    • Re: ten thousand small processes
      ... them roughly in the middle you take space away from heap and stack ... identical across two processes as is the case with large shared memory ... There is no special allocation for virtual address space that is ... the standard libc or at least not the standard malloc implementation. ...
      (freebsd-performance)

    Loading