Reason for doing malloc / bzero over calloc (performance)?

Joerg Sonnenberger joerg at britannica.bec.de
Fri Jun 15 15:47:43 UTC 2007


On Thu, Jun 14, 2007 at 06:04:27PM -0700, Matthew Dillon wrote:
>     From this point of view it is much, much better to bzero() memory that
>     is already mapped then it is to map/unmap new memory.

For kernel land, you are right. For userland, there's one big down-side
to always bzero/memset newly allocated memory: it touches the page and
thereby can add a lot of back pressure on you are not having that much
memory. This can be completely uncessary at that point and at least one
application of using calloc with large parameter values is creation of a
hash table. Forcing it to consume memory is not such a good idea.

Joerg


More information about the freebsd-hackers mailing list