以下是代码估算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");
Wednesday, November 18, 2009
Subscribe to:
Post Comments (Atom)
Check out my new blog:
Translation
Recent Posts
Who's Online?
Pageviews Today
About Me
嗨,我是花,居住在印度兴奋的Windows,Linux中国的外籍人士和所有高科技的东西
Receive updates for free
Labels
- Tips 'n' Tricks (171)
- Windows Vista (105)
- Website/ Blogging (91)
- General (88)
- Windows XP (84)
- Internet (59)
- Windows 7 (54)
- Software (43)
- Mobile-Tips and Tricks (35)
- Review (28)
- Security (28)
- SEO Tools (25)
- iPhone (17)
- Linux (14)
- Windows Mobile (14)
- mac (13)
- Mobile (12)
- MS Office (7)
- Hardware (6)
- Windows 98 (6)
- Zune (6)
- Games (4)
- Mobile Reviews (3)
- Disclaimer (2)
Blog Archive
- June (2)
- May (2)
- August (2)
- July (1)
- June (1)
- May (2)
- April (4)
- March (4)
- February (1)
- December (2)
- November (1)
- November (1)
- June (2)
- May (28)
- April (54)
- March (83)
- February (60)
- January (57)
- December (48)
- November (17)
- October (28)
- September (22)
- August (19)
- July (34)
- June (59)
- May (1)
- April (5)
- March (22)
- February (5)
- January (31)
0 comments:
Post a Comment