Skip to content

Commit 7ba983b

Browse files
gh-143807: prevent JIT executor overflow from large backoff values
1 parent f50a321 commit 7ba983b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Include/internal/pycore_backoff.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ trigger_backoff_counter(void)
119119
// Initial JUMP_BACKWARD counter.
120120
// Must be larger than ADAPTIVE_COOLDOWN_VALUE, otherwise when JIT code is
121121
// invalidated we may construct a new trace before the bytecode has properly
122-
// re-specialized:
123-
// Note: this should be a prime number-1. This increases the likelihood of
124-
// finding a "good" loop iteration to trace.
125-
// For example, 4095 does not work for the nqueens benchmark on pyperformance
126-
// as we always end up tracing the loop iteration's
127-
// exhaustion iteration. Which aborts our current tracer.
128-
#define JUMP_BACKWARD_INITIAL_VALUE 4000
122+
// re-specialized.
123+
// Note: this should be a prime number -1. This increases the likelihood
124+
// of finding a "good" loop iteration to trace.
125+
// Large initial values can cause excessive executor creation and overflow
126+
// MAX_EXECUTORS_SIZE in JIT builds. A smaller value keeps executor growth
127+
// bounded while still satisfying cooldown and tracing requirements.
128+
#define JUMP_BACKWARD_INITIAL_VALUE 63
129129
#define JUMP_BACKWARD_INITIAL_BACKOFF 6
130130
static inline _Py_BackoffCounter
131131
initial_jump_backoff_counter(_PyPolicy *policy)
@@ -136,10 +136,13 @@ initial_jump_backoff_counter(_PyPolicy *policy)
136136
}
137137

138138
/* Initial exit temperature.
139-
* Must be larger than ADAPTIVE_COOLDOWN_VALUE,
140-
* otherwise when a side exit warms up we may construct
141-
* a new trace before the Tier 1 code has properly re-specialized. */
142-
#define SIDE_EXIT_INITIAL_VALUE 4000
139+
* Must be larger than ADAPTIVE_COOLDOWN_VALUE, otherwise when a side exit
140+
* warms up we may construct a new trace before the Tier 1 code has properly
141+
* re-specialized.
142+
* Large initial values can cause excessive executor creation and overflow
143+
* MAX_EXECUTORS_SIZE in JIT builds. A smaller value keeps executor growth
144+
* bounded while still satisfying cooldown requirements. */
145+
#define SIDE_EXIT_INITIAL_VALUE 63
143146
#define SIDE_EXIT_INITIAL_BACKOFF 6
144147

145148
static inline _Py_BackoffCounter

0 commit comments

Comments
 (0)