Efficient Use of Compute Resources
1. Reasons for Wasted Cores
Not enough Threads
Blocked Threads lead to not enough threads
2. Goal
need at least one ready/running thread for each CPU core
generally need more threads than cores (threads are often blocked)
threads could be in one process (or many)
3. Solutions
Multi-threaded applications
good when multiple threads need to access frequently modified data structures
new kinds of bugs possible (race conditions, deadlock)
Multi-process applications
easier to program (or just manually launch several processes in background)
better at keeping multiple cores busy simultaneously (Python specific)
Virtual Address Spaces
1. Process and Address Spaces
A
process
is a running program, runs independently and has its own memory space, resources, and system resources.
Virtual Address
:
Regular processes cannot directly access physical memory or other address spaces (avoid spying)
Each process has its own virtual address space
The
same
virtual address generally refers to
different
memory in
different
processes
Virtual address spaces can have “holes” (the length of virtual address is usually greater than physical address)
Physical memory for a process need not be contiguous
Address Space in Details:
Locations of Code and Variables:
CPU Execution
CPUs are attached to at most one instruction pointer at any given time (CPU points to interpreter code, which points to Python bytecode)
They run code by executing instructions and advancing the instruction pointer
Threads