Re: page sizes



On Sat, 12 Apr 2008 23:01:23 +0200, copx wrote:

"Phlip" <phlip2005@xxxxxxxxx> schrieb im Newsbeitrag
news:4800038f$0$25921$4c368faf@xxxxxxxxxxxxxxxxx
copx wrote:

Do memory managers usually use page sizes which are a power of two or
not?

Yes. This optimizes the variables and hardware registers used to manage
the pages. None of their bits are wasted. User-level code doesn't need
these optimizations, so they pick array sizes with different
conveniences.



Usually 4096 bytes.

X86 has an optional bigger pagesize (1MB or 4MB, can't remember), which
is hardly ever used. NB: DEC-alpha has 8K pages which makes it a great
platform for testing portability.


I am trying to squeeze a few more nanoseconds out of a programming
language interpreter. The documentation of malloc() on one of the
platforms I am targetting explicitly gives the advice to allocate powers
of 2 to improve performance. However, that is only true if the allocated
blocks are <= pagesize. Larger blocks allocate fastest if they are
multiples of the page size.

For performance, think in terms of cache lines (16 bytes on x86) or pages
(4K on x86) Spanning a cache line or page boundary results in (approx)
twice the number of cache misses/ page faults. Malloc *may* avoid this
overhead by always putting chunks on cacheline boundaries (and wasting
some space).

Also; IMHO you should not rely on malloc's implementation. Some mallocs
may return consecutive ranges, others may intersperse the chunks with
their own overhead. Pre-allocating big (page aligned) chunks is always
better, iff you can handle the overhead.


HTH,
AvK
.



Relevant Pages

  • Re: Can Anyone Explain This Memory Leak?
    ... Some `malloc' implementations use mmapto allocate ... allocate many chunks of a certain size, free them, and then allocate many ... requests (as bunches of somewhat-too-small chunks are on the free lists) ...
    (comp.lang.ruby)
  • Re: Virtual memory allocator recommendations?
    ... but being built on top of malloc it doesn't actually allocate ... its own chunks, so it doesn't seem to be suitable for what I want, alas. ... access to the OS memory management facilities. ...
    (comp.lang.c)
  • Re: Virtual memory allocator recommendations?
    ... but being built on top of malloc it doesn't actually allocate ... its own chunks, so it doesn't seem to be suitable for what I want, alas. ...
    (comp.lang.c)
  • Re: xmalloc string functions
    ... Failed malloc() is. ... Why can't you test an allocation failure? ... each can fail on request, each needs to have the request failure dealt ... process Save click because it failed to allocate memory for the event ...
    (comp.lang.c)
  • 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)