🎓 BookMCQ
← Back to 6. CPU Scheduling

📝 Processor Affinity in Multiple Processor Scheduling (44 MCQs)

📖 From Operating System • 6. CPU Scheduling • 44 questions available

What is Processor Affinity in Multiple Processor Scheduling?

Definition:
Processor affinity is the tendency of a process to continue running on the same processor, categorized as soft affinity (preference) or hard affinity (restriction), reducing cache miss rate MrM_r.

Example:
Linux's CFS tracks per-CPU usage and prefers keeping a task on its last CPU to preserve warm L1/L2 caches, migrating only when load imbalance exceeds threshold.

Reason:
Maintaining affinity exploits temporal locality in cache hierarchies, significantly reducing memory access latency and improving throughput, though it must be balanced against load-balancing needs.

8
Easy
14
Medium
22
Hard

📝 All Processor Affinity in Multiple Processor Scheduling MCQs

Q1. What is processor affinity in the context of SMP systems?

A.The tendency of a processor to run faster over time
B.The attempt to keep a process running on the same processor ✅
C.The assignment of processes to memory banks
D.The priority level assigned to a processor
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Processor affinity refers to the attempt to keep a process running on the same processor. This is done to avoid the high cost of cache invalidation and repopulation when a process migrates between processors, improving performance.

Q2. Why do most SMP systems try to avoid process migration?

A.To reduce power consumption
B.To avoid cache invalidation and repopulation costs ✅
C.To simplify scheduling algorithms
D.To balance memory usage
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Most SMP systems try to avoid process migration because migrating a process requires invalidating cache contents on the first processor and repopulating cache on the second processor. This high cost makes keeping processes on the same processor more efficient.

Q3. What happens to cache when a process migrates to another processor?

A.Cache is automatically shared
B.Cache must be invalidated on the first processor and repopulated on the second ✅
C.Cache contents are transferred
D.Cache remains unchanged
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a process migrates, cache memory contents must be invalidated for the first processor (since the process no longer uses them) and repopulated on the second processor (to provide quick memory access). This migration cost is why processor affinity is valuable.

Q4. What is soft affinity in processor scheduling?

A.A guarantee that a process stays on one processor
B.An attempt to keep a process on one processor without guarantee ✅
C.A system call that locks a process to a processor
D.A method of migrating processes between processors
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Soft affinity is a policy where the operating system attempts to keep a process running on the same processor but does not guarantee it. The process may still migrate between processors if necessary, though the system tries to avoid it.

Q5. What is hard affinity in processor scheduling?

A.An attempt to keep a process on one processor without guarantee
B.A guarantee that a process stays on one processor ✅
C.A method of balancing cache
D.A scheduling algorithm for NUMA systems
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Hard affinity provides a guarantee that a process stays on a specific processor or subset of processors. This is typically implemented through system calls that allow processes to specify which processors they may run on.

Q6. Which Linux system call supports hard affinity?

A.sched_setaffinity() ✅
B.sched_getaffinity()
C.pthread_setaffinity()
D.task_setaffinity()
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Linux provides the sched_setaffinity() system call, which supports hard affinity. This allows processes to specify a subset of processors on which they may run, giving them control over processor placement.

Q7. What does NUMA stand for?

A.Non-Uniform Memory Access ✅
B.New Universal Memory Architecture
C.Network Unified Memory Access
D.Non-Universal Memory Allocation
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: NUMA stands for Non-Uniform Memory Access. This architecture has different memory access times depending on the memory's location relative to the processor, with faster access to local memory and slower access to remote memory.

Q8. In NUMA architecture, how does memory access time vary?

A.All memory is accessed at the same speed
B.Local memory is accessed faster than remote memory ✅
C.Remote memory is accessed faster than local memory
D.Memory access time is unpredictable
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: In NUMA architecture, a CPU can access memory on its own board faster than it can access memory on other boards. This non-uniform access time is the defining characteristic of NUMA systems.

Q9. What is the primary benefit of processor affinity?

A.Reduced context switching
B.Avoidance of cache invalidation and repopulation overhead ✅
C.Better load balancing
D.Simpler scheduling algorithms
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The primary benefit of processor affinity is avoiding the high cost of cache invalidation and repopulation when processes migrate between processors. Keeping a process on the same processor maintains cache data usefulness, improving performance.

Q10. What happens to successive memory accesses when a process stays on the same processor?

A.They are slower
B.They are often satisfied in cache memory ✅
C.They require more I/O
D.They use more memory
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a process stays on the same processor, its data remains in that processor's cache. Successive memory accesses are often satisfied in cache, providing faster access and better performance compared to accessing main memory.

Q11. In Linux, how is soft affinity implemented?

A.Through the sched_setaffinity() system call
B.Through the scheduler's attempt to keep processes on the same processor ✅
C.Through mandatory processor locking
D.Through memory placement policies
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Linux implements soft affinity through the scheduler's attempt to keep processes on the same processor. The scheduler tries to maintain processor affinity but may migrate processes if necessary, balancing affinity with other scheduling considerations.

Q12. How does hard affinity differ from soft affinity in terms of guarantee?

A.Hard affinity provides a guarantee, soft affinity does not ✅
B.Soft affinity provides a guarantee, hard affinity does not
C.Both provide guarantees
D.Neither provides guarantees
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Hard affinity provides a guarantee that a process will run on a specific processor or subset of processors. Soft affinity only attempts to keep a process on the same processor without providing any guarantee of compliance.

Q13. What is the relationship between processor affinity and NUMA architecture?

A.NUMA eliminates the need for affinity
B.Affinity becomes more important in NUMA due to memory access differences ✅
C.NUMA and affinity are unrelated
D.Affinity is only used in non-NUMA systems
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Processor affinity becomes more important in NUMA systems because memory access speeds vary. By keeping processes on the same processor, the operating system can also ensure memory is allocated on the same board, optimizing memory access times.

Q14. In a NUMA system, what should work together for optimal performance?

A.CPU scheduler and memory-placement algorithms ✅
B.CPU scheduler and I/O scheduler
C.Memory-placement and file system
D.Process scheduler and network stack
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: For optimal performance in NUMA systems, the CPU scheduler and memory-placement algorithms should work together. This ensures that processes assigned affinity to a particular CPU are allocated memory on the board where that CPU resides, providing faster memory access.

Q15. What is the cost of invalidating and repopulating caches?

A.Very low cost
B.High cost ✅
C.No cost
D.Cost is negligible
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The cost of invalidating and repopulating caches is high. Cache invalidation requires discarding useful data, and repopulation requires fetching data from main memory. This high cost is why SMP systems try to maintain processor affinity.

Q16. What type of system call does Linux provide for hard affinity?

A.sched_setaffinity() ✅
B.pthread_create()
C.fork()
D.exec()
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Linux provides the sched_setaffinity() system call for hard affinity. This system call allows a process to specify a subset of processors on which it may run, providing guaranteed processor placement.

Q17. What is the effect of processor migration on cache memory?

A.Cache becomes faster
B.Cache must be repopulated on the new processor ✅
C.Cache is automatically transferred
D.Cache is shared between processors
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a process migrates, the cache on the new processor must be repopulated with the process's data. This takes time and consumes resources, which is why operating systems try to avoid migration through processor affinity.

Q18. In systems with both soft and hard affinity, which takes precedence?

A.Soft affinity
B.Hard affinity ✅
C.Both are equally important
D.Neither is important
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When both soft and hard affinity are available, hard affinity typically takes precedence. If a process explicitly specifies a processor subset through hard affinity, the scheduler must honor that constraint, while soft affinity is only a best-effort policy.

Q19. What is a key characteristic of NUMA systems?

A.All processors share the same memory
B.Memory access time depends on processor-memory distance ✅
C.All memory is equally accessible
D.Memory is not accessible to processors
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A key characteristic of NUMA systems is that memory access time depends on the distance between the processor and the memory. Local memory on the same board is accessed faster than remote memory on other boards.

Q20. Why might an operating system choose to migrate a process despite soft affinity?

A.To save power
B.To balance load across processors ✅
C.To improve cache utilization
D.To reduce memory usage
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Despite soft affinity attempting to keep processes on the same processor, the operating system might migrate a process for load balancing. If some processors are heavily loaded while others are idle, migration can improve overall system performance even with affinity costs.

Q21. What does a process specify when using hard affinity in Linux?

A.A single processor it must run on
B.A subset of processors it may run on ✅
C.A priority level for its execution
D.A memory region for its data
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Using hard affinity, a process can specify a subset of processors on which it may run. This gives the process control over where it executes, useful for performance tuning and NUMA optimization.

Q22. What is the relationship between processor affinity and CPU cache?

A.Affinity ensures cache data remains valid ✅
B.Affinity eliminates cache usage
C.Affinity reduces cache size
D.Affinity disables cache
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Processor affinity ensures that a process's cache data remains valid and useful. By keeping the process on the same processor, cache data does not need to be invalidated, and the processor can maintain a high cache hit rate.

Q23. What is the primary disadvantage of hard affinity?

A.It is impossible to implement
B.It can reduce scheduling flexibility and load balancing ✅
C.It increases cache invalidation
D.It requires more memory
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Hard affinity reduces scheduling flexibility because the scheduler must honor processor constraints. This can limit load balancing opportunities and may lead to processor underutilization if the specified processors become overloaded.

Q24. In NUMA systems, how does memory allocation relate to processor affinity?

A.Memory is always allocated on a single board
B.Memory should be allocated on the board where the CPU resides ✅
C.Memory is allocated randomly
D.Memory allocation does not affect performance
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: For optimal performance in NUMA systems, memory should be allocated on the board where the CPU resides. If the CPU scheduler and memory-placement algorithms work together, a process with affinity to a particular CPU will get memory from the same board, providing faster access.

Q25. Why might a process with hard affinity to a specific processor cause performance issues?

A.It always improves performance
B.It can cause load imbalance if the processor is busy ✅
C.It reduces cache usage
D.It increases memory bandwidth
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Hard affinity can cause performance issues if the specified processor becomes overloaded. Other processes requiring that processor will wait, while other processors remain idle. This load imbalance can reduce overall system performance.

Q26. What is the effect of NUMA on processor affinity decisions?

A.NUMA makes affinity less important
B.NUMA makes affinity more important ✅
C.NUMA has no effect on affinity
D.NUMA eliminates affinity
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: NUMA makes affinity more important because memory access speeds vary. The affinity decision affects not only cache performance but also memory access performance, as local memory access is faster than remote memory access.

Q27. What happens to a process's cache data when it migrates between processors?

A.The data is preserved
B.The data becomes invalid on the old processor ✅
C.The data is copied to the new processor
D.The data is permanently lost
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When a process migrates, its cache data becomes invalid on the old processor because the process no longer uses that processor. The data must be fetched from main memory to populate the cache on the new processor, which is costly.

Q28. In Linux, what is the relationship between soft and hard affinity?

A.They are mutually exclusive
B.Soft affinity is the default, hard affinity can be set via system call ✅
C.Hard affinity is the default, soft affinity can be set
D.They are identical
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: In Linux, soft affinity is the default scheduler behavior. The scheduler attempts to keep processes on the same processor without guaranteeing it. Hard affinity can be set using the sched_setaffinity() system call, which overrides the default soft affinity behavior.

Q29. What is the role of memory-placement algorithms in NUMA affinity optimization?

A.They allocate memory randomly
B.They allocate memory on the same board as the processor ✅
C.They allocate memory on the fastest board
D.They allocate memory uniformly
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Memory-placement algorithms in NUMA systems should allocate memory on the same board where the processor resides. When combined with processor affinity, this ensures that processes get both processor and memory from the same NUMA node, optimizing access speeds.

Q30. What is the primary reason for the high cost of cache invalidation?

A.Cache is very large
B.Main memory access is slow ✅
C.Cache is directly connected to the processor
D.Invalidation requires hardware reset
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The high cost of cache invalidation comes from the need to access main memory after invalidation. When cache is invalidated, subsequent memory accesses must go to main memory, which is significantly slower than cache access, resulting in a performance penalty.

Q31. How does processor affinity relate to process scheduling in SMP systems?

A.It is a scheduling policy to improve cache performance ✅
B.It is a memory management policy
C.It is an I/O scheduling policy
D.It is a file system policy
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Processor affinity is a scheduling policy in SMP systems designed to improve cache performance. By keeping processes on the same processor, the scheduler maintains cache data validity, reducing the need for expensive cache invalidation and repopulation.

Q32. What is the impact of processor affinity on load balancing?

A.It improves load balancing
B.It can restrict load balancing ✅
C.It has no impact on load balancing
D.It eliminates the need for load balancing
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Processor affinity can restrict load balancing because the scheduler may keep processes on specific processors rather than migrating them for load balance. The scheduler must balance the benefits of affinity against the need for even processor utilization.

Q33. In a NUMA system, what happens if a process with affinity to CPU 1 is allocated memory on board 2?

A.Performance improves
B.Memory access is slower ✅
C.Performance is unchanged
D.The process migrates
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If a process with affinity to CPU 1 is allocated memory on board 2, memory access will be slower because board 2 memory is remote to CPU 1. This is why CPU scheduler and memory-placement algorithms should work together in NUMA systems.

Q34. What is the relationship between processor affinity and process migration?

A.Affinity encourages migration
B.Affinity discourages migration ✅
C.Affinity has no effect on migration
D.Affinity forces migration
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Processor affinity discourages process migration by attempting to keep processes on their current processors. The high cost of migration (cache invalidation and repopulation) makes affinity beneficial, so the scheduler tries to avoid migrating processes when possible.

Q35. What does sched_setaffinity() allow a process to do in Linux?

A.Set its scheduling priority
B.Specify which processors it can run on ✅
C.Set its memory allocation policy
D.Specify its I/O priority
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: sched_setaffinity() allows a process to specify which processors it can run on. This provides hard affinity, giving the process control over its processor placement and enabling optimization for NUMA systems or specific performance requirements.

Q36. How do modern operating systems balance affinity and load balancing?

A.They always prioritize affinity
B.They always prioritize load balancing
C.They use complex algorithms considering both factors ✅
D.They ignore both factors
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Modern operating systems use complex algorithms that consider both affinity benefits and load balancing needs. The scheduler tries to maintain affinity when possible but may migrate processes if load imbalances become significant enough to justify the migration cost.

Q37. What is the significance of dotted lines" between operating system sections?"

A.Sections are completely independent
B.Sections work together through algorithms across boundaries ✅
C.Sections have no interaction
D.Sections are clearly separated
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The dotted lines" metaphor indicates that sections of an operating system (like scheduler and memory management) work together across traditional boundaries. Algorithms create connections between sections to optimize performance and reliability."

Q38. In what systems is NUMA typically found?

A.Single processor systems
B.Systems with combined CPU and memory boards ✅
C.Systems with uniform memory access
D.Systems without cache memory
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: NUMA is typically found in systems containing combined CPU and memory boards. These boards have local memory that is accessed faster than memory on other boards, creating non-uniform memory access characteristics.

Q39. What is the primary goal of combining CPU scheduling and memory placement in NUMA systems?

A.To simplify system design
B.To optimize performance by placing memory near the CPU ✅
C.To reduce memory usage
D.To eliminate cache
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The primary goal of combining CPU scheduling and memory placement in NUMA systems is to optimize performance. By placing memory on the same board as the CPU where the process runs, memory access is faster, improving overall performance.

Q40. How does cache memory behave when a process is running on a processor with affinity?

A.Cache is frequently invalidated
B.Cache data remains useful and accessible ✅
C.Cache is not used
D.Cache size increases
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When a process is running on a processor with affinity, cache data remains useful because the process continues to access the same memory locations. This maintains high cache hit rates and avoids the cost of invalidation and repopulation.

Q41. What is the trade-off in using hard affinity?

A.Guaranteed performance vs reduced scheduling flexibility
B.Better cache vs worse load balancing ✅
C.Faster memory vs slower execution
D.More control vs less portability
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The trade-off in using hard affinity is better cache performance and faster memory access versus reduced scheduling flexibility and load balancing. Hard affinity ensures good local performance but may prevent optimal distribution of workloads across processors.

Q42. Why is processor affinity considered important in high-performance computing?

A.It simplifies programming
B.It maximizes cache utilization and minimizes migration overhead ✅
C.It reduces power consumption
D.It increases processor count
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Processor affinity is important in high-performance computing because it maximizes cache utilization and minimizes the overhead of process migration. This improves performance for compute-intensive applications that benefit from consistent cache access.

Q43. What is the relationship between affinity and NUMA memory allocation?

A.They are independent
B.Affinity should be considered when allocating NUMA memory ✅
C.NUMA memory ignores affinity
D.Affinity disables NUMA
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Affinity and NUMA memory allocation are closely related. For optimal performance, affinity should be considered when allocating NUMA memory - the process should get memory from the same NUMA node as the processor it has affinity to, ensuring fast local memory access.

Q44. What is the impact of not using processor affinity in a NUMA system?

A.Performance improves
B.Performance may degrade due to remote memory access ✅
C.No performance impact
D.System becomes more stable
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Not using processor affinity in a NUMA system can degrade performance because processes may run on processors remote from their memory allocations. This results in slower remote memory access, reducing overall system performance.

🔗 Related Topics (MCQs)