The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+29 votes

Which of the following actions is/are typically not performed by the operating system when switching context from process $A$ to process $B$?

  1. Saving current register values and restoring saved register values for process $B$.
  2. Changing address translation tables.
  3. Swapping out the memory image of process $A$ to the disk.
  4. Invalidating the translation look-aside buffer.
asked in Operating System by Veteran (59.5k points)
edited by | 2.8k views
@Bikram Sir @Debashish

Context switching can occur only in kernel mode it means it is done only by operating system then how swapping process is not performed by os ?

I got answer that memory manager swaps process .pls explain


swapping-out of the memory-image of a process to disk is not done on every context switch by OS as it would cause a huge over head

Bikram sir According to korth,,
whenever the cpu scheduler decides to execute a process it calls the dispatcher .the dispatcher checks to see whether the next process in the queue is in memory.if not,the dispatcher swaps out a process currently in memory and swapped in the desired process .it then reloads registers as normal and transfer control to the selected process .The context switch time in such a swaping system is fairly high.

 Bikram sir,pls also explain this line ,m confused between user and memory manager

"if a new process is loaded and there is insufficient main memory an od process is swapped to disk.This os ,however does not provide full swaping,because the user,rather than the scheduler ,decides when it is time to preempt one process for another.Any swapped out process remains swapped out until the user selects that process to run"

As wiki says

swapping can be implemented in various ways. For example, swapping can be priority based. That means if a higher priority process arrives and wants service, the memory manager can swap out the lower priority process to the secondary memory so that it higher priority process can be loaded to main memory for execution. As soon higher priority process finishes, the lower priority process will be swapped back to main memory and execution will be continued

2 Answers

+45 votes
Best answer

The above answer covers most of the things. Trying to add some more points to make it clear for people like me for those it is quite difficult to understand.

Processes are generally swapped out from memory to Disk (secondary memory) when they are suspended. So. Processes are not swapped during context switching.

TLB : Whenever any page table entry is referred for the first time it is temporarily saved in TLB. Every element of this memory has a tag. And whenever anything is searched it is compared against TLB and we can get that entry/data with less memory access.

And Invalidation of TLB means resetting TLB which is necessary because A TLB entry may belong to any page table of any process thus resetting ensures that the entry corresponds to the process that we are searching for.

Hence, option (C) is correct.

answered by Boss (28k points)
edited by
But TLB's have ASID(ADDRESS SPACE IDENTIFIER) ....which help it to distinguish between processes & their memory space ie Address Space Protection .

then why is Invalidating TLB necessary with each context Switch >
When a task exits, the ASID is invalidated from the caches and TLBs and is reallocated to another task.
how about changing address translation tables comes into the play?
why we are changing address Translation table?
In case of Logical address to Physical address translation Address translation Table is used.

A program is comprised of segments (data, code, stack, etc.)

A logical address is a pair consisting of a segment number and a byte offset (displacement) within the segment.

The hardware architecture defines a segment table containing one entry per segment.  It is normally implemented as an array indexed by segment number.

Each segment table entry contains the base address and limit / length of the segment. This segment table is  known as address translation table.
Isn't that address translation table also called page table which contains entries of pages(the segment is divided into these pages) specific to that segment?
+33 votes
option C) because swapping out of the memory image of a process to disk is not done on every context switch as it would cause a huge over head but can solve problems like trashing.
answered by Active (1.5k points)
is it necessary that "invalidating TLB" during context switch ???
Yes. Invalidation is necessary. Otherwise the new process might end up using the translation of the old process. Saving and reuse of TLB is not necessary but can lead to better performance.
But TLB's have ASID(ADDRESS SPACE IDENTIFIER) ....which help it to distinguish between processes & their memory space ie Address Space Protection .

then why is Invalidating TLB necessary with each context Switch >
how about changing address translation tables?
If OS isn't involve in Swapping out the memory image of process A to the disk then which part of the system is involved?
yes, OS is involved in " Swapping out the memory image of process A to the disk "

but in case of context switch swapping to disk is not done ..due to huge overhead.


Changing address translation tables

means changing the size of segments or length of that segment in table .

 This address translation table contains the base address and length of the segment.  so changing length of the segment  is performed by the operating system when switching context from process A to process B.

there can be two approaches in case of TLB we can invalidate it or we need not in case we need not we can increase efficiency as the TLB in case of multi programming environment contains the frame base addresses of the pages used by the processes recently(more than one ) so if we invalidate it and in case we swap the present process immedeatly then this may lead us to access that from the page table instead of being a TLB HIT and what i think about address translation tables is changing the PAGE TABLE BASE REGISTERS ADDRESS MAINTAINED BY THE PROCESSOR AND THIS SHOULD BE SURELY DONE ...SO the answer is obviously C

@Arjun sir , if i am not wrong .isn't the explanation for TLB contradicting this answer

What is the contradiction?

sir answer to this 

says -:$\text{TLB are NOT necessarily saved during Context switch , }$

$\text{they are done just to ensure better perfromance}$

based on this, answer to this question should be both $C,D$

I am not sure i am right .

Saving and invalidating are not the same. "Invalidation" is necessary -- because otherwise the process can get corrupted. If not saved, while resumption there will just be a lot more TLB misses -- slow execution but still correct.
Thats it .I missed to specify that i got confused between Invalidation and saving .Thank you sir :)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,941 questions
45,453 answers
48,210 users