3
$\begingroup$

I'm working on learning operating systems and I've come across a strange question that I don't know how to answer.

The question is:

Assuming a 1-KB page size, what are the page numbers and offsets for the following address references (provided as decimal numbers)?

21205

The notes and slides I have are very confusing and I can't find anything quite like this from my searches. I understand that a 1KB page size means that it's 2^10 but what do I do after that exactly? Most descriptions I see involve splitting that in half and using the first half as your offset and the other half as the page number but then I see others saying not to do this and my notes, as I mentioned, are useless. I'm sure this is extremely easy but I feel like I've been given only 1/3 of the knowledge needed.

Any help would be greatly appreciated!


Addendum

I took a step back for a little while and I think I realized where my confusion was coming from.

I determined that 21,205 is within the range of 2^15, so it's a fifteen bit number. If I subtract the size of the page (10) from the size of the number (15) then that should, in theory, give me a page number of 10 and an offset of 5.

The next bit is pure speculation on my part but I'm assuming that I then take the decimal form of 21,205, which is 101001011010101, and segment it accordingly. The first ten bits (1010010110) equals 662 and the last five bits (10101) equals 21. So my tentative answer is

Page Number = 662 & Offset = 21.

Is this at all reasonable or do I do it completely wrong?

$\endgroup$

5 Answers 5

2
$\begingroup$

You got it a little mix up and wrong
Page number = logical address / page size in this case is $\frac{21205}{1024} = 20$

Offset = logical address mod page size in this case is $21205 \mod 1024 = 725$

Sources:
http://www.yorku.ca/pkashiya/cse1520/Paged%20memory%20technique.htm http://www2.cs.uregina.ca/~hamilton/courses/330/notes/memory/paging.html

$\endgroup$
1
  • $\begingroup$ Thanks for the answer $\endgroup$ Commented Oct 24, 2021 at 13:32
1
$\begingroup$

You are correct in thinking that you are completely wrong. What you need to do is forget all your notes and work everything out from first principles. That is the delight of maths (for example): there are no facts.

First, try an easier problem. Suppose you have a civilised computer with a 1000-byte page size. Then the address 21205 will be at page 21 (the first page is page 0) and the offset is 205.

Next, try to explain what you have just done in an unnecessarily complicated way. You got “21” not because it was obvious but because you laboriously calculated 21205÷1000. You got “205” not because it was obvious but because you took 21205 and worked out the remainder on dividing by 1000.

Next, take what you did in the last paragraph but instead of 1000 use 1024. You will get a page number and an offset and the answer to your question.

Finally, have an attack of laziness. Realise that you never needed to divide by 1000: you only needed to write down 21205 in decimal and cut off the last three digits. Realise that you never needed to take the remainder after division by 1000: you only needed to take the last three digits on their own.

So the finally final step is to replace “1000” by “1024”, “decimal” by “binary”, and “three” by “ten”.

And then, at last, you can look at your half remembered notes and see what you got wrong. It was a simple transposition - but there’s no point in correcting them because now you know why it all works, you can reinvent the formula yourself any time you want to.

The great thing about maths is that there are no facts.

$\endgroup$
0
$\begingroup$

I think Page numbers will be given by first 5 bits and last 10 bits will give the offset. With the first 5 bit first you locate which page no. you want to go and then remaining 10 bits will tell you the offset at that page taking you at the exact location

$\endgroup$
0
$\begingroup$

I'll give an answer with different arguments for page size and logical address:

Note this passage from Operating System Concepts by Silberschatz, et al.:

If the size of the logical address space is 2^m, and a page size is 2^n bytes, then the high-order m - n bits of a logical address designate the page number, and the n low-order bits designate the page offset. Thus the logical address is as follows:

page number | page offset = m - n | n

Imagine you have a page size of 2KB (2048 bytes). log_2(2048) = 11, therefore n = 11

Given a decimal reference address of 42095, this equals the 16-bit binary representation 1010 0100 0110 1111, with the low-order n bits being 100 0110 1111. The remaining 5 bits give you the page number, in this case 20, since 10100 = 20.

page number = m - n = 16 - 11 = high-order 5 bits of the 16-bit binary representation of 42,095 = 20

page offset = n = 11 = low-order 11 bits = 1135

Note that this approach is consistent with the formulaic approaches already answered here (both get you the same answer).

$\endgroup$
-1
$\begingroup$

215201 is logical address space provided to us which means it is a process size. 1 KB is page size which is equivalent to 2^10 or 1024 Bytes. Process divided by page size gives a quotient and remainder, 215201/1024 = 210 quotient which is number of pages and 161 as a remainder which is offset.

$\endgroup$
3
  • $\begingroup$ My mistake , its 21205 $\endgroup$ Commented May 22, 2023 at 16:03
  • $\begingroup$ Therefore 21205/1024 = which gives 20 pages and 770 as offset $\endgroup$ Commented May 22, 2023 at 16:04
  • $\begingroup$ (Don't comment: Edit your answer.)(Double-check your arithmetic.) $\endgroup$
    – greybeard
    Commented May 22, 2023 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.