第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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值