Shop PCMemoryStore.com Today! MacSpeech Dictate 1.5

Wednesday, November 18, 2009

Estimating RSS size in linux kernel through a page table walk

·

以下是代码估算Linux内核的大小新闻 我已经尝试过在RedHat #include #include #include #include #include long long rss = 0; long long rss_temp = 0; long long vma = 0; static int pid; module_param(pid, int, 0); //页表不走这个功能 int walk(unsigned long addr, struct mm_struct* mm){ pgd_t *pgd; pud_t *pud; pmd_t *pmd; pte_t *ptep, pte; pgd = pgd_offset(mm, addr); if (pgd_none(*pgd) || pgd_bad(*pgd) || !pgd_present(*pgd)) return 1; pud = pud_offset(pgd, addr); if (pud_none(*pud) || pud_bad(*pud) || !pud_present(*pud)) return 1; pmd = pmd_offset(pud, addr); if (pmd_none(*pmd) || pmd_bad(*pmd) || !pmd_present(*pmd)) return 1; ptep = pte_offset_map(pmd, addr); if (!ptep) return 1; pte = *ptep; if(pte_none(pte)) return 1; if(!pte_present(pte)) return 2; struct page *page; page = NULL; page = pte_page(pte); if (!page) return 1; pte_unmap(ptep); rss = rss + PAGE_SIZE; rss_temp += PAGE_SIZE; printk("VA %lx has PA %p\n", addr, pte.pte); return 0; } //堆积在这里完成 void printmm(struct task_struct *tsk){ struct vm_area_struct *vm; vm = tsk->mm->mmap; int i; for(i=tsk->active_mm->map_count; i>0; i--){ unsigned long addr = vm->vm_start; rss_temp = 0; while(addr < vm->vm_end){ int val = walk(addr, tsk->active_mm); if (val != 0) printk("VA %lx not found\n",addr); if(val==2) printk("page has been swapped out"); addr += PAGE_SIZE; } vma += vm->vm_end - vm->vm_start; printk("RSS for this area: %lldkb\n", rss_temp/1024); vm = vm->vm_next; } printk("RSS: %lldkb\n", rss/1024); } int init_module() { struct task_struct *task = pid_task(find_vpid(pid), PIDTYPE_PID); printmm(task); return 0; } void cleanup_module() { } MODULE_LICENSE("GPL");

0 comments:

Post a Comment

Related Articles


Related Article Widget by Hoctro

About Me


嗨,我是花,居住在印度兴奋的Windows,Linux中国的外籍人士和所有高科技的东西

Hi, I am Hua, a chinese expat residing in India excited about windows, linux and all things tech

Receive updates for free

Enter your email address:

Delivered by FeedBurner

Mobile Version

Bookmark

Bookmark and Share

Blog Archive

matchmaker.com gold membership valentine's