From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11532 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Query regarding malloc if statement Date: Tue, 20 Jun 2017 16:35:49 +0200 Message-ID: <20170620143548.GM27071@port70.net> References: <20170619183451.mwuqlq5oybbbgxgm@voyager> <20170620041429.zjmzwpeyycwwpcvr@voyager> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1497969369 11140 195.159.176.226 (20 Jun 2017 14:36:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 20 Jun 2017 14:36:09 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-11545-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 20 16:36:01 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dNKG7-0002R2-7C for gllmg-musl@m.gmane.org; Tue, 20 Jun 2017 16:35:59 +0200 Original-Received: (qmail 18225 invoked by uid 550); 20 Jun 2017 14:36:01 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 18188 invoked from network); 20 Jun 2017 14:36:00 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: <20170620041429.zjmzwpeyycwwpcvr@voyager> Xref: news.gmane.org gmane.linux.lib.musl.general:11532 Archived-At: * Markus Wichmann [2017-06-20 06:14:29 +0200]: > On Mon, Jun 19, 2017 at 09:02:00PM +0000, Jamie Mccrae wrote: > > My understanding is that doing a read followed by a possible write is slower than always doing a write for the reason that upon doing a read the process will halt > > until the memory is brought into the CPU's cache which isn't a problem when just doing a write. I've just thrown together a simple application to test this (testing on a modern PC running alpine linux 64-bit in a virtualbox VM with 512MB RAM and 1 CPU core) with a normal musl library and a modified one whereby I've removed the 'if' check: > > > > Woah, you're mixing up a few things here. A cache miss and a page fault > are two very different things. > > Besides, doesn't a cache miss on write mean that a cache-line for the > write area has to be allocated first? > are you arguing with somebody off-list? (i only see your replies) in any case the calloc code should not be controversial on linux. writing to each allocated page when they are potentially unused is a huge waste of memory not just time. (a benchmark that calls calloc/free in a loop is obviously bogous, try calloc(1000*1000*1000,1) vs memset(malloc(1000*1000*1000),0,1000*1000*1000))