chapter18

hisun9發表於2024-11-12

paging-linear-translate.py引數

img

第一題

問題

在做地址轉換之前,讓我們用模擬器來研究線性頁表在給定不同引數的情況下如何改變大小。在不同引數變化時,計算線性頁表的大小。一些建議輸入如下,透過使用-v 標誌,你可以看到填充了多少個頁表項。

首先,要理解線性頁表大小如何隨著地址空間的增長而變化:

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

然後,理解線性頁面大小如何隨頁大小的增長而變化:

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

在執行這些命令之前,請試著想想預期的趨勢。頁表大小如何隨地址空間的增長而改變?隨著頁大小的增長呢?為什麼一般來說,我們不應該使用很大的頁呢?

輸出太長了,只給出頁表的專案數。

paging-linear-translate.py -P 1k -a 1m -p 512m -v -n 0 
1024項
paging-linear-translate.py -P 1k -a 2m -p 512m -v -n 0 
2048項
paging-linear-translate.py -P 1k -a 4m -p 512m -v -n 0
4096項
paging-linear-translate.py -P 1k -a 1m -p 512m -v -n 0 
1024項
paging-linear-translate.py -P 2k -a 1m -p 512m -v -n 0 
512項
paging-linear-translate.py -P 4k -a 1m -p 512m -v -n 0 
256項

頁表大小隨著地址空間的增大而增大,隨著頁大小的增大而減小。

如果使用很大的頁,會產生很多內部碎片,空間被浪費了。

第二題

問題

現在讓我們做一些地址轉換。從一些小例子開始,使用-u 標誌更改分配給地址空間的頁數。例如:

paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 0 
paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 25 
paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 50 
paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 75 
paging-linear-translate.py -P 1k -a 16k -p 32k -v -u 100 

如果增加每個地址空間中的頁的百分比,會發生什麼?

img

img

img

img

img

增加百分比,更多的地址轉換成功。

第三題

問題

現在讓我們嘗試一些不同的隨機種子,以及一些不同的(有時相當瘋狂的)地址空間引數:

paging-linear-translate.py -P 8 -a 32 -p 1024 -v -s 1 
paging-linear-translate.py -P 8k -a 32k -p 1m -v -s 2 
paging-linear-translate.py -P 1m -a 256m -p 512m -v -s 3 

哪些引數組合是不現實的?為什麼?

img

img

太長了,不截圖

[whq@whq01 vm-paging]$ python paging-linear-translate.py -P 1m -a 256m -p 512m -v -s 3 -c
ARG seed 3
ARG address space size 256m
ARG phys mem size 512m
ARG page size 1m
ARG verbose True
ARG addresses -1


The format of the page table is simple:
The high-order (left-most) bit is the VALID bit.
  If the bit is 1, the rest of the entry is the PFN.
  If the bit is 0, the page is not valid.
Use verbose mode (-v) if you want to print the VPN # by
each entry of the page table.

Page Table (from entry 0 down to the max size)
  [       0]  0x00000000
  [       1]  0x800000bd
  [       2]  0x80000140
  [       3]  0x00000000
  [       4]  0x00000000
  [       5]  0x80000084
  [       6]  0x00000000
  [       7]  0x800000f0
  [       8]  0x800000f3
  [       9]  0x8000004d
  [      10]  0x800001bc
  [      11]  0x8000017b
  [      12]  0x80000020
  [      13]  0x8000012e
  [      14]  0x00000000
  [      15]  0x00000000
  [      16]  0x800000f2
  [      17]  0x800001c1
  [      18]  0x800001d7
  [      19]  0x00000000
  [      20]  0x800000e3
  [      21]  0x00000000
  [      22]  0x00000000
  [      23]  0x00000000
  [      24]  0x800000df
  [      25]  0x8000009a
  [      26]  0x800000c5
  [      27]  0x00000000
  [      28]  0x8000012b
  [      29]  0x8000015d
  [      30]  0x800001b6
  [      31]  0x80000157
  [      32]  0x00000000
  [      33]  0x800001ed
  [      34]  0x80000123
  [      35]  0x8000006c
  [      36]  0x80000125
  [      37]  0x00000000
  [      38]  0x00000000
  [      39]  0x800001fa
  [      40]  0x00000000
  [      41]  0x800000d2
  [      42]  0x00000000
  [      43]  0x00000000
  [      44]  0x800001be
  [      45]  0x00000000
  [      46]  0x80000017
  [      47]  0x800000a9
  [      48]  0x800001f6
  [      49]  0x800001ff
  [      50]  0x00000000
  [      51]  0x00000000
  [      52]  0x80000010
  [      53]  0x00000000
  [      54]  0x00000000
  [      55]  0x8000004f
  [      56]  0x00000000
  [      57]  0x800000a0
  [      58]  0x800001cb
  [      59]  0x00000000
  [      60]  0x00000000
  [      61]  0x80000149
  [      62]  0x8000011e
  [      63]  0x800001e1
  [      64]  0x800000dc
  [      65]  0x80000079
  [      66]  0x00000000
  [      67]  0x8000010a
  [      68]  0x80000005
  [      69]  0x00000000
  [      70]  0x8000000a
  [      71]  0x80000143
  [      72]  0x00000000
  [      73]  0x800000ee
  [      74]  0x800000b4
  [      75]  0x80000179
  [      76]  0x00000000
  [      77]  0x00000000
  [      78]  0x00000000
  [      79]  0x00000000
  [      80]  0x800000a3
  [      81]  0x00000000
  [      82]  0x00000000
  [      83]  0x00000000
  [      84]  0x80000099
  [      85]  0x00000000
  [      86]  0x8000000d
  [      87]  0x80000178
  [      88]  0x00000000
  [      89]  0x00000000
  [      90]  0x8000007a
  [      91]  0x00000000
  [      92]  0x00000000
  [      93]  0x80000034
  [      94]  0x00000000
  [      95]  0x00000000
  [      96]  0x800000e0
  [      97]  0x80000056
  [      98]  0x00000000
  [      99]  0x800001c5
  [     100]  0x00000000
  [     101]  0x00000000
  [     102]  0x00000000
  [     103]  0x80000061
  [     104]  0x800001ad
  [     105]  0x00000000
  [     106]  0x00000000
  [     107]  0x80000148
  [     108]  0x800000b0
  [     109]  0x00000000
  [     110]  0x00000000
  [     111]  0x8000008a
  [     112]  0x00000000
  [     113]  0x00000000
  [     114]  0x00000000
  [     115]  0x00000000
  [     116]  0x00000000
  [     117]  0x800001c2
  [     118]  0x800000de
  [     119]  0x800001da
  [     120]  0x00000000
  [     121]  0x800001ac
  [     122]  0x80000109
  [     123]  0x00000000
  [     124]  0x00000000
  [     125]  0x00000000
  [     126]  0x00000000
  [     127]  0x80000092
  [     128]  0x80000163
  [     129]  0x80000127
  [     130]  0x00000000
  [     131]  0x80000057
  [     132]  0x00000000
  [     133]  0x8000010c
  [     134]  0x00000000
  [     135]  0x80000139
  [     136]  0x00000000
  [     137]  0x00000000
  [     138]  0x800000f4
  [     139]  0x00000000
  [     140]  0x800001a2
  [     141]  0x00000000
  [     142]  0x800001a5
  [     143]  0x00000000
  [     144]  0x800001b9
  [     145]  0x00000000
  [     146]  0x00000000
  [     147]  0x00000000
  [     148]  0x800000d8
  [     149]  0x00000000
  [     150]  0x80000000
  [     151]  0x00000000
  [     152]  0x00000000
  [     153]  0x00000000
  [     154]  0x00000000
  [     155]  0x800001b5
  [     156]  0x00000000
  [     157]  0x800000a1
  [     158]  0x00000000
  [     159]  0x00000000
  [     160]  0x8000012c
  [     161]  0x00000000
  [     162]  0x00000000
  [     163]  0x00000000
  [     164]  0x00000000
  [     165]  0x8000016e
  [     166]  0x00000000
  [     167]  0x00000000
  [     168]  0x00000000
  [     169]  0x00000000
  [     170]  0x80000190
  [     171]  0x00000000
  [     172]  0x8000013e
  [     173]  0x00000000
  [     174]  0x00000000
  [     175]  0x00000000
  [     176]  0x800000d7
  [     177]  0x800000eb
  [     178]  0x00000000
  [     179]  0x00000000
  [     180]  0x00000000
  [     181]  0x00000000
  [     182]  0x800001df
  [     183]  0x00000000
  [     184]  0x80000194
  [     185]  0x00000000
  [     186]  0x00000000
  [     187]  0x00000000
  [     188]  0x80000153
  [     189]  0x80000195
  [     190]  0x80000177
  [     191]  0x80000002
  [     192]  0x00000000
  [     193]  0x80000016
  [     194]  0x00000000
  [     195]  0x00000000
  [     196]  0x8000005b
  [     197]  0x00000000
  [     198]  0x8000003e
  [     199]  0x80000158
  [     200]  0x800001e7
  [     201]  0x80000198
  [     202]  0x00000000
  [     203]  0x80000105
  [     204]  0x80000036
  [     205]  0x800001de
  [     206]  0x00000000
  [     207]  0x00000000
  [     208]  0x800001a7
  [     209]  0x00000000
  [     210]  0x00000000
  [     211]  0x00000000
  [     212]  0x80000181
  [     213]  0x00000000
  [     214]  0x00000000
  [     215]  0x00000000
  [     216]  0x00000000
  [     217]  0x00000000
  [     218]  0x00000000
  [     219]  0x800001f2
  [     220]  0x00000000
  [     221]  0x80000052
  [     222]  0x80000183
  [     223]  0x80000108
  [     224]  0x00000000
  [     225]  0x00000000
  [     226]  0x00000000
  [     227]  0x800001d5
  [     228]  0x800000e2
  [     229]  0x8000005f
  [     230]  0x00000000
  [     231]  0x00000000
  [     232]  0x00000000
  [     233]  0x800001e8
  [     234]  0x00000000
  [     235]  0x800000d3
  [     236]  0x00000000
  [     237]  0x00000000
  [     238]  0x00000000
  [     239]  0x00000000
  [     240]  0x00000000
  [     241]  0x00000000
  [     242]  0x00000000
  [     243]  0x00000000
  [     244]  0x80000049
  [     245]  0x800000f5
  [     246]  0x800000ef
  [     247]  0x800001a4
  [     248]  0x800000f6
  [     249]  0x00000000
  [     250]  0x800001eb
  [     251]  0x00000000
  [     252]  0x00000000
  [     253]  0x00000000
  [     254]  0x80000159
  [     255]  0x00000000

Virtual Address Trace
  VA 0x0308b24d (decimal: 50901581) --> 1f68b24d (decimal 526955085) [VPN 48]
  VA 0x042351e6 (decimal: 69423590) -->  Invalid (VPN 66 not valid)
  VA 0x02feb67b (decimal: 50247291) --> 0a9eb67b (decimal 178173563) [VPN 47]
  VA 0x0b46977d (decimal: 189175677) -->  Invalid (VPN 180 not valid)
  VA 0x0dbcceb4 (decimal: 230477492) --> 1f2cceb4 (decimal 523030196) [VPN 219]

這三個都存在正確的轉換,因此都不能算“錯誤”。但是三個的組合都不太合理。

1和2:地址空間太小,只能容下4個頁。

3:頁大小有點大了

第四題

問題

利用該程式嘗試其他一些問題。你能找到讓程式無法工作的限制嗎?例如,如果地址空間大小大於實體記憶體,會發生什麼情況?

img

會報錯,提示實體記憶體大小應該大於地址空間大小