From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11617 Path: news.gmane.org!.POSTED!not-for-mail From: Vicente Bergas Newsgroups: gmane.linux.lib.musl.general Subject: Re: calloc question about clearing allocated memory Date: Tue, 27 Jun 2017 20:24:21 +0200 Message-ID: References: <20170627131327.GD2032@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1498587880 21312 195.159.176.226 (27 Jun 2017 18:24:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 27 Jun 2017 18:24:40 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11630-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 27 20:24:32 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 1dPvA8-00058g-6s for gllmg-musl@m.gmane.org; Tue, 27 Jun 2017 20:24:32 +0200 Original-Received: (qmail 13999 invoked by uid 550); 27 Jun 2017 18:24:34 -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 13977 invoked from network); 27 Jun 2017 18:24:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=sno8wae3ZIT/mLmgLSYY+qBfJxaZM1aXMEImm4eswVI=; b=OudHp4avgKYoUqV/iPrZJ1KKQ1eI5wW3eO6s2MGBScRGVyWFFIeT+o38nWXCYe79I9 KUyCQPEUEdPa1AmljKVOTSPIwxLog+524Jc8AdGObO/sj5+20wrIzmHfLNUaPSF35S4v Ti3b/WFmMfRDUGI5PUG2+BEqKStUQkjwfSwU86Kt6oakUyxBy3tj6k5KUalOAd3WxnVT l9Ta54UhnMy/OWh8Oh9xv21n8P2/oNpHECM4vP1oAnLcT/7URekYsx6qHS5lt0XqlkWK PiEZg2OdyF5TB1zKCffIjSm/homdDNes/vw6/6xO1dAoudpkJ8/9yVlTWqpywv7J/aj4 JT7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=sno8wae3ZIT/mLmgLSYY+qBfJxaZM1aXMEImm4eswVI=; b=qdNrcQJ77tg0CjIEC7ptKt/3hoOE9WSJHhyDtiQ/VbfP4ug7RgAMxi/9IwPYMtN4ne ZFmnnwkF/lx41gMsCBCdzGuYDU/43ZFiPQ0zz+w13v4lNfEdtyUkTL1j07uWvG4MkSCJ ihmbMzsP0qBfGZJ3ZWjqV4qXbzkITdxnSL2SCIdRZPJf2AxxJz5KAmg252yBdMukUMjJ /1xPwn0vdQ6gG1aau2rCsUU9QARE/K2PY/lOc4wDAQVRlXhooDeQanThQxjhSUEAKTeK lc84GCzt/P/Q2a8vGtfcWAcZFiFHHbUvWHYOPOIFL4UQ8z1q8RxNkf462G/sntTM83Nj dRpA== X-Gm-Message-State: AKS2vOySr4MEQGU7RtTPw50mZOprQ7rWL7VK12tRfT7mK8/CRY5xXWH+ TPzGQLMCFIV2CRLMYXIUjqIPTxoa3w== X-Received: by 10.107.58.135 with SMTP id h129mr7571176ioa.25.1498587861435; Tue, 27 Jun 2017 11:24:21 -0700 (PDT) In-Reply-To: <20170627131327.GD2032@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:11617 Archived-At: Thanks for the explanation, now it is clear! On Tue, Jun 27, 2017 at 3:13 PM, Szabolcs Nagy wrote: > * Vicente Bergas [2017-06-26 23:30:53 +0200]: >> Hello, >> when compiling a program against the musl libc and running it under >> valgrind, then it reports lots of uninitialized value errors. >> I have tracked them down to only two sources: >> http://git.musl-libc.org/cgit/musl/tree/src/string/strlen.c?id=3De6def54= 4#n15 >> http://git.musl-libc.org/cgit/musl/tree/src/malloc/malloc.c?id=3De6def54= 4#n375 >> >> The first one about strlen is clearly an optimization everybody would >> like to have, but the second one in __malloc0 is not that obvious. >> Please, could that be explained: why is *z read just before being >> cleared? >> In fact it is counter-intuitive and looks like an overhead. >> In case there is a reason for it, it would be nice to put an >> explanatory comment there. Otherwise, that extra read could be >> removed to make valgrind happy. > > this should be the faq of the month.. > > a zero page does not take up resources, however when > it is written (even if that's just 0) the page gets > dirty and it does take up resources (and the write > operation would cause a page fault introducing > significant delays) > > so if(*z) *z=3D0; should be an obvious optimization. > that said the current code is not optimal and an > improvement was just posted: > http://www.openwall.com/lists/musl/2017/06/26/1 > but that won't fix the valgrind issue: to fix that > valgrind just needs to be taught not to report > uninitialized error for calloced memory. > >> >> Regards, >> Vicen=C3=A7. >> >> P.S.: Please, CC me as I am not subscribed to the list.