实验八 Linux虚拟内存 实验9.1:统计系统缺页次数成功案例

运行环境:

  1. VMware17.5.1 build-23298084
  2. Ubuntu 16.04LTS ubuntu版本下载地址
  3. Linux-4.16.10 linux历史版本下载地址
  4. 虚拟机配置:硬盘一般不少于40G就行

内核版本不同内核文件代码也有出入,版本差异性令c文件要修改,如若要在linux6.7.8运行,则

static struct file_operations my_fops = {

    .owner = THIS_MODULE,

    .open = my_proc_open,

    .release = single_release,

    .read = seq_read,

    .llseek = seq_lseek,

};

要修改成

static const struct proc_ops my_fops = {

    //.proc_owner = THIS_MODULE,

    .proc_open = my_proc_open,

    .proc_release = single_release,

    .proc_read = seq_read,

    .proc_lseek = seq_lseek,

};

同时Makefile文件也要进行修改Tab缩进等等。之前试图用VMware15.5、虚拟机配置两个双核CPU、内存10G、Ubuntu22版本与linux6.7.8编译,一直出现卡死。降级linux4.16.10提示客户机已禁用CPU,请关闭或重置客户机,多种方法尝试均无解。最后把VMware卸载重装、虚拟机配置调低才顺利编译。

是
之前内核文件按实验要求修改后,linux6.7.8成功编译的一次,但是insmod readpfcount.ko时卡死

遇到的问题:

  1. 断电重启导致vmdk文件损坏虚拟机无法打开 :解决办法参考Ubuntu意外断电vmdk损坏--打不开磁盘“***.vmdk”或它所依赖的某个快照磁盘。
  2. 提示客户机已禁用CPU,请关闭或重置客户机:各种方法试过都无效,我的办法是把虚拟机配置调低,重新新建一个虚拟机

  3. 解压缩、复制粘贴文件提示permission denied:解决方法参考解决Ubuntu系统移动或复制文件权限不够Ubuntu20.04系统下进行复制粘贴文件显示没有权限的解决办法

  4. sudo make完成后sudo make modules卡死:完成sudo make后先保存快照,然后卡死的话先等一会,如果等了较长时间直接重启,调整虚拟机内存等配置,恢复快照。

  5. 卸载旧VMware并安装另一个版本Vmware:VMware如何彻底卸载删除干净详细教程

有参考意义的文章:

  1. OS实验之玩转linux内核
  2. 高版本内核编译低版本内核全过程

附上readpfcount.c源码:

#include <linux/module.h>

#include <linux/sched.h>

#include <linux/uaccess.h>

#include <linux/proc_fs.h>

#include <linux/fs.h>

#include <linux/mm.h>

#include <linux/seq_file.h>

#include <linux/slab.h>

extern unsigned long pfcount;

static int my_proc_show(struct seq_file* m, void* v) {

    seq_printf(m, "The pfcount is %ld and jiffies is %ld!\n", pfcount,jiffies);

    return 0;

}

static int my_proc_open(struct inode* inode, struct file* file) {

    return single_open(file, my_proc_show, NULL);

}

static struct file_operations my_fops = {

    .owner = THIS_MODULE,

    .open = my_proc_open,

    .release = single_release,

    .read = seq_read,

    .llseek = seq_lseek,

};

static int __init my_init(void) {

    struct proc_dir_entry* file = proc_create("readpfcount",0x0644, NULL,&my_fops);

    if (!file) {

         printk("proc_create failed.\n");

         return -ENOMEM;

    }

    return 0;

}

static void __exit my_exit(void) {

    remove_proc_entry("readpfcount", NULL);

}

module_init(my_init);

module_exit(my_exit);

MODULE_LICENSE("GPL");

Makefile文件:

 ifneq ($(KERNELRELEASE),)
    obj-m := readpfcount.o
else
    KDIR := /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)
    default:
                $(MAKE) -C $(KDIR) M=$(PWD) modules
    clean:
                $(MAKE) -C $(KDIR) M=$(PWD) clean
endif

  • 24
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值