From owner-freebsd-hackers Tue Jul 20 10:17:55 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from kronos.alcnet.com (kronos.alcnet.com [63.69.28.22]) by hub.freebsd.org (Postfix) with ESMTP id 8F91A1533F for ; Tue, 20 Jul 1999 10:17:40 -0700 (PDT) (envelope-from kbyanc@alcnet.com) X-Provider: ALC Communications, Inc. http://www.alcnet.com/ Received: from kbyanc (ws-41.alcnet.com [63.69.28.41]) by kronos.alcnet.com (8.9.3/8.9.3/antispam) with SMTP id NAA56392; Tue, 20 Jul 1999 13:31:54 -0400 (EDT) From: "Kelly Yancey" To: Cc: Subject: RE: Overcommit and calloc() Date: Tue, 20 Jul 1999 13:28:21 -0400 Message-ID: <005101bed2d5$433a16e0$291c453f@kbyanc.alcnet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > From: Charles Randall > >I have another post on this list which begs the question: if memory given > >to us from sbrk() is already zeroed, why zero it again if we don't have > >too.... if we make calloc() smarter, we could save come clock cycles. > > Because the memory returned from malloc() might be from a previous > malloc()/free() and may be dirty. > > Charles Specifically, if there are no blocks on the heap that can be re-used by malloc(), it calls sbrk() to extend the process' address space. sbrk() always returns memory that the kernel has already gone through the effort of zero'ing...why do it again? I am thinking about making calloc() more intellegent like malloc(): if it re-uses a free()'ed memory block, then it has to bzero() it (exactly like it does now), if it has to sbrk() then it can skip the bzero() step and save some clock cycles. I'm expecting that in addition of gaining clock cycles from not zeroing the memory twice, the fact that calloc() won't have to touch all newly allocated pages would reduce the amount of work by the VM system and give another little performance boost. On recent thought though, I seem to recall having read in the 4.4BSD Daemon book that having the kernel zero memory is not the preferred practice, but present because when they tried to stop many progrems dies which assumed memory was initialized to zero. If I am remembering that correctly, then, the only real concern is that one day we may want to kernel to stop zeroing pages, in which case the extra logic in calloc() would be for nought. Really the jist of the changes I'm looking to make are to use the fact that the kernel is already zeroing pages to optimize the calloc() implementation. If this ever changes, then the optimization would go away. Kelly ~kbyanc@posi.net~ FreeBSD - The Power To Serve - http://www.freebsd.org/ Join Team FreeBSD - http://www.posi.net/freebsd/Team-FreeBSD To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message