第18章 分页:介绍

Homework

In this homework, you will use a simple program, which is known as paging-linear-translate.py, to see if you understand how simple virtual-to-physical address translation works with linear page tables. See the README for details.

Questions:

1. Before doing any translations, let’s use the simulator to study how linear page tables change size given different parameters. Compute the size of linear page tables as different parameters change. Some suggested inputs are below; by using the -v flag, you can see how many page-table entries are filled. First, to understand how linear page table size changes as the address space grows, run with these flags:

线性页表大小:1024

python paging-linear-translate.py -P 1k -a 1m -p 512m -v -n 0 

线性页表大小:2048 

python paging-linear-translate.py -P 1k -a 2m -p 512m -v -n 0 

线性页表大小:4096 

python paging-linear-translate.py -P 1k -a 4m -p 512m -v -n 0

结论:在页的大小固定的情况下,页表大小随着地址空间的增长而增加 

线性页表大小:1024

python paging-linear-translate.py -P 1k -a 1m -p 512m -v -n 0 

线性页表大小:512

python paging-linear-translate.py -P 2k -a 1m -p 512m -v -n 0  

线性页表大小:256 

python paging-linear-translate.py -P 4k -a 1m -p 512m -v -n 0 

结论:页表大小随着页大小的增长而减小

页越大,页表就越小,从而节约了页表所占用的内存;但会导致页中产生碎片(每个页不可能100%填满),浪费内存

2. Now let’s do some translations. Start with some small examples, and change the number of pages that are allocated to the address space with the -u flag. For example:

hat happens as you increase the percentage of pages that are allocated in each address space?

增加每个地址空间中页的百分比,可以看到地址空间中更多的页有效

就像一个进程被加载到内存,一开始所占用的地址空间很小,这时有效的页也很少;随着不断调用函数和申请内存,栈和堆不断增大,有效的页增多

python paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 0 -c

python paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 25 -c 

python paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 50 -c 

python paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 75 -c 

python paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 100 -c 

3. Now let’s try some different random seeds, and some different (and sometimes quite crazy) address-space parameters, for variety:

Which of these parameter combinations are unrealistic? Why?

感觉这3个都对着呢

python paging-linear-translate.py -P 8 -a 32 -p 1024 -v -s 1 -c 

python paging-linear-translate.py -P 8k -a 32k -p 1m -v -s 1 -c 

python paging-linear-translate.py -P 1m -a 256m -p 512m -v -s 1 -c 

4. Use the program to try out some other problems. Can you find the limits of where the program doesn’t work anymore? For example, what happens if the address-space size is bigger than physical memory?

Error: physical memory size must be GREATER than address space size (for this simulation) 

 python paging-linear-translate.py -P 8 -a 1024 -p 32 -v -s 1 -c

Error in argument: address space must be a multiple of the pagesize 

python paging-linear-translate.py -P 32 -a 8 -p 1024 -v -s 1 -c 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis PageHelper 是一个 MyBatis 分页插件,能够快速、便捷的进行分页查询,支持多种数据库。使用 PageHelper 可以避免手写 SQL 语句进行分页操作,同时 PageHelper 支持物理分页和逻辑分页两种方式。 下面是使用 PageHelper 进行分页查询的步骤: 1. 导入 PageHelper 依赖 Maven 项目在 pom.xml 文件中添加以下依赖: ``` <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.11</version> </dependency> ``` 2. 配置 PageHelper 在 MyBatis 的配置文件中添加以下配置: ``` <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <property name="dialect" value="mysql"/> </plugin> </plugins> ``` 其中 dialect 属性指定了数据库类型,PageHelper 支持的数据库类型包括:oracle、mysql、mariadb、sqlite、hsqldb、postgresql、db2、sqlserver、informix、达梦、人大金仓、南大通用、神通、PostgreSQL9.3-9.5。 3. 使用 PageHelper 进行分页查询 在需要进行分页查询的方法中使用 PageHelper.startPage 方法进行分页设置,然后调用查询方法获取查询结果。例如: ``` PageHelper.startPage(1, 10); // 第一页,每页显示 10 条记录 List<User> userList = userDao.selectUserList(); // 查询用户列表 PageInfo<User> pageInfo = new PageInfo<>(userList); // 封装分页结果 ``` 其中 PageHelper.startPage 方法接收两个参数,第一个参数为当前页码,第二个参数为每页显示的记录数。 最后使用 PageInfo 类对查询结果进行封装,得到分页结果。PageInfo 类中包含了分页信息和查询结果。 以上就是使用 MyBatis PageHelper 进行分页查询的基本步骤。需要注意的是,在使用 PageHelper 进行分页查询时,需要确保查询语句中不要使用 limit 关键字。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值