[SOLVED] Search for free and used pages
Posted: Sat Feb 08, 2014 11:12 am
Hello mates,
I know that this is not a so technical question, but I'll ask it anyway in the hope that somebody will give it a look
I'm trying to write a function that tell me how many free and used pages there are in a given range of virtual address (page table aligned!!),
here is the function I wrote:
This code works, but have one issue: some pages that are used, will result free..
I think that the if statement that I used to check if a page is present might be the problem:
There might be a better way to check if a page is present or not..
Thanks a lot for any help (or any hint in the right direction)
I know that this is not a so technical question, but I'll ask it anyway in the hope that somebody will give it a look
I'm trying to write a function that tell me how many free and used pages there are in a given range of virtual address (page table aligned!!),
here is the function I wrote:
Code: Select all
uint32_t check_pages(uint32_t startAddr,uint32_t length){
pdirectory* dir = vmm_get_directory ();
pd_entry* pagedir = dir->m_entries;
int cfreepage = 0;
int cusedpage = 0;
uint32_t x = 0, y = 0;
for(x = startAddr; x < (startAddr+length) ; x+=4096*1024){ // check 1 pagetable at a time
if(pagedir[x>>22] != 0){ // check if pagetable exist
ptable* table =(ptable*) pagedir[x>>22];
for(y=x;;y+=4096){ // scan every single pages in the pagetable
pt_entry* page = (pt_entry*)table->m_entries [ PAGE_TABLE_INDEX (y) ];
if(((uint32_t)(page)>>22) != 0){ // check if a page is present FIXME this might be the problem
cusedpage++;
kernelPrintf("Found used page number: %d\n",PAGE_TABLE_INDEX (y));
}
else{
cfreepage++;
kernelPrintf("Found free page number: %d\n",PAGE_TABLE_INDEX (y));
}
if(PAGE_TABLE_INDEX (y)==1023) break;
}
}
else{ // if a pagetable doesn't exist add 1024 free pages to the counter
kernelPrintf("found free pagetable! (1024 free pages)\n");
cfreepage+=1024;
}
}
kernelPrintf("Used Pages Found: %d\n",cusedpage);
kernelPrintf("Free Pages Found: %d\n",cfreepage);
return 0;
}
I think that the if statement that I used to check if a page is present might be the problem:
Code: Select all
if(((uint32_t)(page)>>22) != 0)
Thanks a lot for any help (or any hint in the right direction)