Skip to contentSkip to conversation

one question about pgd allocation

DISCUSSION liyu@WAN 1 participant 1 message Jul 1, 2005

lore
Share & tools
lore

liyu@WAN

author
#0 lore raw

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