<p dir="ltr">Depending on the implementation of the allocator used, calloc may not have any additional overhead. When it does, there are really only a couple cases it shouldn't happen on modern systems:</p>
<p dir="ltr"> * If an object is allocated and freed in a tight loop. This shouldn't be happening anyway -- reuse / pool objects with this sort of access pattern.<br>
 * If the object is large. Malloced memory should not be immediately visible to multiple concurrent processes, and objects that consist of only a few cache lines cost very little to zero on modern processors.</p>
<p dir="ltr">It may be worth auditing for these situations, but I've done extensive profiling of extremely memory heavy workloads (hundreds of gb) in Varnish over the past few years, and I promise that calloc is not a current limiting factor in terms of latency or throughput.</p>
<p dir="ltr">Of course, if you're concerned about swapping, I'd also argue that your cache is not properly sized.</p>
<br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 8, 2016, 04:28 Poul-Henning Kamp <<a href="mailto:phk@phk.freebsd.dk">phk@phk.freebsd.dk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">--------<br>
In message <CAJV_h0YVCRfTOFk=<a href="mailto:6N3H9jNxnrXM05ht2pQkyJ-FY-LGfu1H_g@mail.gmail.com" target="_blank">6N3H9jNxnrXM05ht2pQkyJ-FY-LGfu1H_g@mail.gmail.com</a>><br>
, Federico Schwindt writes:<br>
<br>
>We use calloc in many places, I do wonder how many of them do really need<br>
>it. The downside of using calloc when is not really needed is that by<br>
>zeroing the memory you end up with resident memory and not virtual, which<br>
>in turn might lead to swapping.<br>
<br>
This is almost always intentional, as we generally do not over-allocate.<br>
<br>
The exception is the malloc stevedore where we do.<br>
<br>
<br>
--<br>
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20<br>
phk@FreeBSD.ORG         | TCP/IP since RFC 956<br>
FreeBSD committer       | BSD since 4.3-tahoe<br>
Never attribute to malice what can adequately be explained by incompetence.<br>
<br>
_______________________________________________<br>
varnish-dev mailing list<br>
<a href="mailto:varnish-dev@varnish-cache.org" target="_blank">varnish-dev@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev" rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev</a><br>
</blockquote></div>