* one question about pgd allocation
@ 2005-07-01 13:00 liyu@WAN
0 siblings, 0 replies; 2+ messages in thread
From: liyu@WAN @ 2005-07-01 13:00 UTC (permalink / raw)
To: LKML
hi LKML:
I am reading kernel code about memory management.
on i386 platform, the function pgd_alloc() alloc one page table
directory,
every directory entry is one PMD address. that is OK.
pgd_t *pgd_alloc(struct mm_struct *mm)
{
int i;
pgd_t *pgd = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
if (PTRS_PER_PMD == 1 || !pgd)
return pgd;
for (i = 0; i < USER_PTRS_PER_PGD; ++i) {
pmd_t *pmd = kmem_cache_alloc(pmd_cache, GFP_KERNEL);
if (!pmd)
goto out_oom;
set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
}
return pgd;
out_oom:
for (i--; i >= 0; i--)
kmem_cache_free(pmd_cache, (void *)__va(pgd_val(pgd[i])-1));
kmem_cache_free(pgd_cache, pgd);
return NULL;
}
My question is the statement:
set_pgd(&pgd[i], __pgd(1 + __pa(pmd)));
why here is not :
set_pgd(&pgd[i], __pgd(__pa(pmd)));
I can not understand this. I search intel developer mannal. but
nothing to help.
Who can tell me why?
thank in advanced.
liyu
2005/7/1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: one question about pgd allocation
[not found] <42C53E7D.7090404@ccoss.com.cn.suse.lists.linux.kernel>
@ 2005-07-01 13:15 ` Andi Kleen
0 siblings, 0 replies; 2+ messages in thread
From: Andi Kleen @ 2005-07-01 13:15 UTC (permalink / raw)
To: liyu@WAN; +Cc: linux-kernel
"liyu@WAN" <liyu@ccoss.com.cn> writes:
>
> I can not understand this. I search intel developer mannal. but
> nothing to help.
> Who can tell me why?
bit 0 is the present bit which needs to be set on the PGD, otherwise
the CPU will ignore it. A clearer way to write this would have been
__pgd(__pa(pmd) | _PAGE_PRESENT)
-Andi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-07-01 13:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-01 13:00 one question about pgd allocation liyu@WAN
[not found] <42C53E7D.7090404@ccoss.com.cn.suse.lists.linux.kernel>
2005-07-01 13:15 ` Andi Kleen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox