4
$\begingroup$

Does a process's page table too gets swapped out to secondary storage from main memory when the process gets swapped out to secondary storage from main memory? And gets swapped back in when the process is swapped in?

I tried to find the answer in text books and online, but none is clear.

Also, it would be helpful if you can tell me if the PCB (process control block) of a process also gets swapped out when the process is swapped out.

$\endgroup$
3
  • 2
    $\begingroup$ Are you asking about a particular OS? If so, you should edit your question to specify it. Some of this sounds to me like design decisions that could vary from OS to OS. The definitions of some terms may well vary per OS too. $\endgroup$ Commented Feb 24, 2017 at 19:04
  • 4
    $\begingroup$ Swapping out any data owned by the kernel is extra difficult, and many operating systems don't even try. Page tables in particular usually can't be swapped out, because they record what has been swapped out, which the page-fault handler may need to know at any moment. "Process control block" sounds very OS-specific to my ear, but I think I know what you mean, and those usually can't be swapped out either because basic information about all processes needs to be available at all times. $\endgroup$ Commented Jun 5, 2017 at 21:14
  • 1
    $\begingroup$ A process' pages need not be all swapped out to disk, so the process' page table needs to be resident. $\endgroup$ Commented Feb 6, 2023 at 15:37

1 Answer 1

0
$\begingroup$

There are two different methods: Method 1 is that the page table maps a logical address to a physical address. Since two processes use the same logical addresses (for totally different things), process B using the page table set up for process A would be fatal, so that page table needs to be swapped out. That's time consuming and painful.

Method 2 is that the page table maps a combination of logical address + an identifier for the process to a physical address. So having entries for other processes in your page table is not a problem, they will not be used, they may be swapped out at some point if the new process needs more page table address, but the transition is smooth, and there is only one method for changing page table entries.

With Method 2, in the not uncommon case that two processes don't actually need the whole page table, it's quite possible that the CPU can switch forth and back between these two processes without touching the page table at all.

No idea why this question has come back, but since it's here, a little addition. There are two things that you never, ever, ever swap out. One is your hard disk driver, because it's no good to you if it is somewhere on your hard disk and you can't read it because you need a hard disk driver in real accessible RAM. The other is the part of the page table that tells you were your page table is stored. If that is swapped out, then you can't read your page table.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.