Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Aug 2002 11:09:07 +0900
From:      "Un, SungKyong" <skun@etri.re.kr>
To:        <freebsd-hackers@freebsd.org>
Subject:   userland malloc() and zeroed page allocation in Kernel
Message-ID:  <001601c24a4a$121fbb60$1bf2fe81@etri.re.kr>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001601c24a4a$121fbb60$1bf2fe81>