In: Computer Science
Q1. a: Why time sharing a CPU with multiple processes reduces the effectiveness of temporal locality?
b: Why time sharing a CPU with multiple processes reduces the effectiveness of spatial locality?
Q2. Why the context switching overhead need to be low for a CPU scheduler?
Answer:
1 (a) Why time sharing a CPU with multiple processes reduces the effectiveness of temporal locality?
Temporal locality is the reuse of specific data, and/or resources by the processor within a reasonably short time span. So if a process is using some resources or data and is currently running then the CPU/processor will store and fetch it from high-speed cache thus improving the speed of execution. If multiple processes are running they will be time-shared, hence the data and/or resources are constantly updated thus overall reducing the effectiveness of temporal locality.
1 (b) Why time sharing a CPU with multiple processes reduces the effectiveness of spatial locality?
Spatial locality/ data locality is the use of data elements used by the processes within comparatively close storage locations. Since we store programs in locations that are relatively close to each other. It works when data elements are stored, arranged and accessed linearly So if multiple processes are running in a time-bound fashion, they could be using different data elements, and/or resources, so the cache will be updated many times hence reducing the effectiveness of spatial locality.
2 Why the context switching overhead needs to be low for a CPU scheduler?
A context switch is a process of storing the state of a process or thread so that it can be restored and recommence execution at a later point in time. This allows a multitasking operating system to run multiple processes by sharing a single central processing unit (CPU). Storing these state values many times can be an expensive process and hence the context switch overhead should be low ideally for a CPU Scheduler.