Daniel Rodrick wrote:
Hi, I was determining a reason for the need_resched flag to be per process rather than being a global variable. I read that the sole reason is for performance. I could not understand how would having it (need_resched) per process result in a better performance? Having it as a global variable in the kernel address space would be just a matter of getting the value at a known address. On the other hand, having a per process copy sure results in unecessary memory occupancy.
1) not every CPU needs to reschedule simultaneously, think about an 8-cpu core SMP system where one of the current tasks needs to reschedule 2) the cacheline with the current task_struct pointer in it is probably in the CPU's L2 cache, since it is used very frequently - a global variable would probably not be in the CPU cache 3) the thread struct (IIRC need_resched lives there, please correct me if I misremember) is the first few bytes of a task's kernel thread, so it doesn't really take any extra memory -- "You don't have to be crazy to do this... but it helps." -- Bob Ross -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/