This document summarizes Erlang processes and scheduling in Erlang. It discusses the process control block, stack and heap, message passing, the scheduler, workload balancing across schedulers, and garbage collection. The scheduler prioritizes ports, maximum, high and normal/low priority queues. It will consume all reductions for a process or pause it waiting for a message. The garbage collector uses copying collection for process heaps and reference counting for shared binaries.
4. Process Structure
• C Struct : erl_process.h
• PCB: process control block
• process id
• stack/heap position
• argument registers
• program counter
• stack
• private heap : compound data structures, such as tuples, lists etc.
• heap fragments: used when there is not enough free space in the heap and
garbage collection cannot be performed to get more free memory.
9. Scheduler
• Reductions: 2000
• erl_vm.h :
• #define CONTEXT_REDS 2000 /* Swap process out after this number */
• erts_schedule in erl_process.c
• consumes all its reductions
• or pauses to wait for a message
• Four priorities: low | normal | high | max
• Four queues: ports, maximum, high, normal/low.
• ports > max > high > normal/low
• normal/low: skip a low priority process for a number of times
• Round-Robin in queue.
13. Workload Balancing
• Check workload periodically by one scheduler
• Default period: 2000*2000 reductions.
• erl_process.c:
• #define ERTS_RUNQ_CHECK_BALANCE_REDS_PER_SCHED
(2000*CONTEXT_REDS)
• check_balance in erl_process.c
• During a period:
• work sharing/stealing
• determines the number of active schedulers for the next period based on
the load of the current period