# Segmentation and paging

I am given a system with a segmented paging architecture. Both physical and virtual address spaces contain $2^{16}$ bytes each. The virtual address space is divided in $8$ equal size segments. The page table consist of $2$ byte page table entries.

## Question 1:

What is the minimum page size in bytes so that page table for a segment requires at most 1 page to store it?

### My interpretation:

There are $2^{16}$ virtual addresses. These are evenly divided between $8$ segments so each segment is $\frac{2^{16}}{2^3}=2^{13}$ bytes.

Now each segments will be divided into pages. Each page will be $2^n$ bytes. So there are $2^{13-n}$ pages (and page table entries) per segment. A page table entry is $2$ bytes long and page size is $2^n$. So $2^{n+1}$.

$2^{13-n} = 2^{n+1}$ gives $n = 6$. But the answer should be $n = 7$.

I know I made a mistake in page table entry as I didn't get the page table entry concept properly. Is that a f (f+d = memory address)? I am not getting page table entry. Please explain to me this concept.

## Question 2:

Assume that page size is $512$ bytes. Each page table entry contains (besides other information) $1$ valid bit, $3$ bits for page protection and $1$ dirty bit. How many bits are available in a page table entry for storing the aging information for the page?

$16$ bits for physical memory. Page size is $512$ bytes means $9$ bits required. That's $16-9= 7$ bits for a frame.

Now I'm stuck.

If $2^n$ is the size of the page then there are $2^{13-n}$ pages.

We know that each page table entry is 2 bytes.

So size of the page table will be $2\times 2^{13-n}$ bytes because $2^{13-n}$ is the number of pages and each page has an entry in the page table.

They have given that page table takes at most one page to store.

So, $2\times 2^{13-n}=2^n \Rightarrow n=7$.

Each page table entry is two bytes which is $16$ bits so the remaining bits other than the valid bits (protection bits and the dirty bit) are $16-5=11$ bits.
Page size is $512=2^9$ bytes.
Physical address space $2^{16}$ bytes.
Number of bits required to represent a page is $16-9=7$ bits.
So, the available bits to store the aging information is $11-7=4$ bits.