实验六系统缺页次数统计实验_第1页
实验六系统缺页次数统计实验_第2页
实验六系统缺页次数统计实验_第3页
实验六系统缺页次数统计实验_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精品实验6系统缺页次数统计实验1. 实验目的理解内存管理中缺页的概念综合运用实验1,实验4,实验5中/proc文件系统、内存管理、系统调用、内 核编译的知识掌握向/proc文件系统中增加文件的方法掌握Linux内核模块的概念和操作方法2. 实验内容(上交的实验2统一取名为:test2)通过在内核中自建变量并利用/proc文件系统作为中介的方法来统计系统缺页次数3. 设计思想及算法流程缺页次数:虚拟内存技术的应用使得进程线性地址空间里的页面不必常驻内存。当CPU请求一个不在内存中的页面时,会发生缺页,比如我们从内存读取/写入数据,而数据未在内存,此时都 会发生缺页。缺页被定义为一种异常(缺页异常

2、),会触发缺页中断处理流程。每种CPU结构提供一个do_page_fault 处理缺页中断。由于每发生一次缺页都要进 入缺页中断服务函数 do_page_fault 一次,所以统计该函数被调用的次数就可以得到系统 从开机到现在的缺页次数。/proc文件系统:/proc文件系统的文件记录了当前所有的系统信息,包括进程、文件系统、硬件等等。因此,可以通过在/proc中添加一个文件的方式,查看内存进程中的一些自定义运行参数, 从而达到使用/proc实现内核与用户空间通信的目的。在do_page_fault函数上一行定义统计缺页次数全局变量pfcountun sig ned long volatile

3、 pfcount;将pfcount 加入到do_page_fault 中,用以统计缺页次数pfcoun t+;unsigned laog volatile pfcount;严w This routine handles pagis faults.ir determines rhe- addressf b 知宕nd thg probl? and then pa生會e专 it off tu ong 口f thg 自ppr口prfmtm w routinesV .dotraplinkage void _kprobesdo_pagau11(struct pt_regs regs, unsigned T

4、ung 程ror_code)struct vm_arE_striirt vma;siruct taskjtruct sk;gn昌d lung aH日巳struct nuwstruct wnim;Int write;irrt fault;pfcDumt+;声明全局变量 pfcount 到头文件 mm.h中exter n un sig ned long volatile pfcount;extern im page_c luster:extern unsignEd long volatile pfcount:导出pfcount全局变量,让整个内核都可以访问EXPORT_SYMBOL(pfcou n

5、t);4. 源程序/*内核模块代码*/#in clude #i nclude #in clude #in clude #i nclude #in clude #in clude struct proc_dir_e ntry *proc_pf; struct proc_dir_e ntry *proc_pfc ount;exter n un sig ned long volatile pfcount;static in li ne struct proc_dir_e ntry *proc_pf_create(c onst char* n ame, mode_t mode, read_proc_t

6、 *get_i nfo)return create_proc_read_e ntry(n ame, mode, proc_pf, get_ info, NULL);int get_pfc oun t(char *buffer, char *start, off_t offset, i nt le ngth, int *peof, void *data)int len = 0;len = spri ntf(buffer, %ld n, pfcou nt);return len;static int pf_in it(void)proc_pf = proc_mkdir(pf, 0);proc_pf

7、_create(pfc oun t, 0, get_pfc oun t);return 0;static void pf_exit(void)remove_proc_e ntry(pfc oun t, proc_pf);remove_proc_e ntry(pf, 0);module_ in it(pf_ in it);module_exit(pf_exit);MODULE_LICENSE(GPL);MODULE_AUTHOR(Aro n.t.wa ng);5. 运行结果osltnuxoslinuXVtrtual-machlnei/sourceS sudo cat /proc/pf/pfcount 1776297sltnuxosLtnuXvirtual-machi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论