LightMySky
به انگلیسی

Processes, Context Switches and What They Cost

A process is an active program instance with execution state and OS-managed resources. It may be ready, running or blocked. A process switch saves and restores CPU execution state and selects the next process's existing address-space context. Memory mappings and open-file records remain stored, rather than being copied into saved CPU state. Context handling takes time; added cache costs depend on hardware and workload.

شروع یادگیری این موضوعبه حساب کاربری نیازی نیست. پیشرفت در همین مرورگر ذخیره می‌شود.

کارهایی که یادگیرنده بعد از این درس می‌تواند انجام دهد

  • Distinguish saved and restored CPU context from process memory and resource records that remain stored
  • Follow a process through the ready, running and blocked states
  • Explain why a switch costs more than the register copying suggests

۱ · بخوان

You have followed requests into the kernel. The kernel also tracks processes: active instances of programs with execution state, memory and resources such as open files. A process still exists when it is not executing. One application may use several processes, and several processes may run the same program.

ready: waiting for CPUrunning: executingblocked: waiting for eventevent occurs: ready
Ready means able to run but waiting for a CPU. Running means executing. Blocked means waiting for an event. An event makes it ready, not immediately running.

An address space is the memory-address view available to a process. In this simplified model of single-threaded processes, the kernel saves A's CPU execution state, selects B's existing address-space context, restores B's saved CPU state, and resumes B. Saved CPU state includes the instruction position and required register values. Its exact contents depend on the processor and OS. A blocking request can let the kernel schedule another ready process.

save outgoing contextselect next address spacerestore incoming contextresume execution

A switch need not clear caches. Some needed instructions or data may remain cached. A missing line causes a miss in that cache and a fetch from a lower memory level, which may be another cache or main memory. Competing working sets may evict useful lines. The added cost depends on the cache hardware, what remains cached and the incoming process's accesses.

needed line present: hitneeded line absent: miss

Saving and restoring context and running scheduler code take time even when needed data remains cached. More frequent switches can leave less time for program work, and cache disruption can add further cost. The size of the effect depends on the hardware, workload and implementation. A switch is not necessarily harmful: it can let useful work proceed while another process waits.

A paused process retains its memory mappings and open-file records. A switch selects the next process's existing address-space context, which tells the hardware how to use that process's mappings. It does not copy every memory byte or recreate its open files. Saving CPU execution state differs from retaining these resources. Address-space selection can require hardware-control updates; the details and cost depend on the processor and OS.

For a register-copy count, specify how many individual copies each switch performs, including both saving and restoring. Multiply that total by the number of switches. In a toy model, two switches with twelve total register copies each perform 2 × 12 = 24 copies. This counts copies only, not scheduler time or cache costs.

A process can be ready, running or blocked. Switches save and restore CPU state, select address-space context and retain resources. Context work takes time; cache costs vary by hardware and workload.

Original lesson, questions and flashcards written for this dataset.

Original readings and flashcards written for this dataset.

۲ · ببین

به انگلیسی

دور از صفحه‌نمایش

چاپ کاربرگکاغذ A4، با یک صفحهٔ جواب‌ها برای بزرگ‌ترها. بدون صفحه‌نمایش، بدون اینترنت.

جایگاه این موضوع

سپس تمرین

۸ سؤال پشت این درس منتظرند، هر کدام با پاسخ توضیح‌داده‌شده. هر پاسخ آسمان را پر می‌کند: ستاره‌ها هنگام یادگیری روشن می‌شوند و وقتی زمان برگشتن است کمرنگ می‌شوند.

شروع یادگیری این موضوع