0

In xv6 each process has a struct called proc which stores the process's state. it has a field called pgdir which point to it's page directory. My question is that: It should store the index of the last element in its page directory. I mean if it wants to allocate a new page table it should put a reference of it in pgdir. My question is how does it know where the next element of page directory is?

This image explains my question more: enter image description here

Thanks for your help.

Kamran Hosseini
  • 478
  • 5
  • 25

2 Answers2

0

I asked from some people in the real world and I understood p->sz stores the index of the first free element in the process's page directory

Kamran Hosseini
  • 478
  • 5
  • 25
0

The process always keep track on how much bytes his program uses with sz field in the proc struct. With this knowledge, it's easy to calculate what is the last page table entry and page directory entry used.

For example, if a program uses 8000 bytes at the moment (meaning sz = 8000): In XV6, each memory page is 4096 bytes (PGSIZE) and there are 1024 page table entries in each page directory entry. therefore, each page directory entry can point to 4096 * 1024 bytes (4 MB) and each page table entry can point to 4096 bytes (4 KB).

That means that the process last page directory entry is: sz / 4 MB (rounded down). and that the process last page table in the lasts page directory is: sz / 4 KB (rounded down). In sz = 8000 example, that means: page directory entry 0 (first) & page table entry 1 (second).

Omer Efrat
  • 295
  • 1
  • 5