From owner-freebsd-hackers Thu Aug 22 19:12:38 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EE58637B400 for ; Thu, 22 Aug 2002 19:12:35 -0700 (PDT) Received: from cms2.etri.re.kr (cms2.etri.re.kr [129.254.16.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2D9E443E3B for ; Thu, 22 Aug 2002 19:12:34 -0700 (PDT) (envelope-from skun@etri.re.kr) Received: from skun (skun.etri.re.kr [129.254.242.27]) by cms2.etri.re.kr with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id P6YSDPAJ; Fri, 23 Aug 2002 11:10:52 +0900 Message-ID: <001601c24a4a$121fbb60$1bf2fe81@etri.re.kr> From: "Un, SungKyong" To: Subject: userland malloc() and zeroed page allocation in Kernel Date: Fri, 23 Aug 2002 11:09:07 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="ks_c_5601-1987" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi. Is there anyone who knows the relationship between userland malloc() and page allocation in Kernel? I know that userland malloc() do not allocate zeroed memory block. If someone want pre-zeroed memory block, he have to use calloc() or malloc options. Right? But when I try to test this, something strange happed. for (i=0; i<200;i++) { malloc(1MB); check it's all zeroed; set this block to 'X'; } free all allocated memory(200MB); for (i=0; i<200;i++) { malloc(1MB); check it's all 'X'; } The first for loop shows that 200 1MB blocks are all zeroed. The second for loop shows that only the first 1MB has 'X' value and rest blocks are all zeroed. It seems that Kernel zero-out all free pages before allocation. I know the Kernel allocate pre-zeroed page for BSS area but not for heap area. Can anyone tell me the page allocation policy in Kernel? Thanks in advance. ============================== Un, SungKyong Information Security Dept., ETRI Email : skun@etri.re.kr Phone : 82-42-860-5741 FAX : 82-42-860-5611 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message