Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-123516: Improve JIT memory consumption by invalidating cold executors#123402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
0eac77bd57629668e95d6c903af45ca6b7fbeb4f65427dbf592d55900cdf63858e74476c047e426450237c7ae986d6d3064d086fed08e45a6315877622c266e5117b27c6704c1d72fdd17781852506821fca6dec29436fdb969b11a669e0fdeb73ec9fa55e8e4a461ad5a2bedd232e63e4a456ab7d2d5a6dcd2dc219f890fb7b04dea397a3310d20cd2f9dc4d755d56c9534c061cd3c5e5065ad2d09259d2e8e29a894598758ee031927bfe8ee0d7fcedd65d0a9b5b6180a68e7cb9cba8939ecf00f03d24981ab23c59316306c3c3fe50615d51817bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improved JIT memory consumption by periodically freeing memory used by infrequently-executed code. | ||
| This change is especially likely to improve the memory footprint of long-running programs. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -182,6 +182,12 @@ _PyOptimizer_Optimize( | ||
| if (err <= 0){ | ||
| return err; | ||
| } | ||
| if (++interp->new_executors >= JIT_CLEANUP_THRESHOLD){ | ||
| interp->new_executors = 0; | ||
| _Py_Executors_InvalidateCold(interp); | ||
| } | ||
| assert(*executor_ptr != NULL); | ||
| if (progress_needed){ | ||
| int index = get_index_for_executor(code, start); | ||
| @@ -565,6 +571,7 @@ translate_bytecode_to_trace( | ||
| code->co_firstlineno, | ||
| 2 * INSTR_IP(initial_instr, code)); | ||
| ADD_TO_TRACE(_START_EXECUTOR, 0, (uintptr_t)instr, INSTR_IP(instr, code)); | ||
| ADD_TO_TRACE(_MAKE_WARM, 0, 0, 0); | ||
| uint32_t target = 0; | ||
| for (;){ | ||
| @@ -1194,6 +1201,9 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil | ||
| executor->jit_code = NULL; | ||
| executor->jit_side_entry = NULL; | ||
| executor->jit_size = 0; | ||
| // This is initialized to true so we can prevent the executor | ||
| // from being immediately detected as cold and invalidated. | ||
| executor->vm_data.warm = true; | ||
| if (_PyJIT_Compile(executor, executor->trace, length)){ | ||
| Py_DECREF(executor); | ||
| return NULL; | ||
| @@ -1659,4 +1669,42 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation) | ||
| } | ||
| } | ||
| void | ||
| _Py_Executors_InvalidateCold(PyInterpreterState *interp) | ||
| { | ||
savannahostrowski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| /* Walk the list of executors */ | ||
| /* TO DO -- Use a tree to avoid traversing as many objects */ | ||
| PyObject *invalidate = PyList_New(0); | ||
| if (invalidate == NULL){ | ||
| goto error; | ||
| } | ||
| /* Clearing an executor can deallocate others, so we need to make a list of | ||
| * executors to invalidate first */ | ||
| for (_PyExecutorObject *exec = interp->executor_list_head; exec != NULL;){ | ||
| assert(exec->vm_data.valid); | ||
| _PyExecutorObject *next = exec->vm_data.links.next; | ||
savannahostrowski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if (!exec->vm_data.warm && PyList_Append(invalidate, (PyObject *)exec) < 0){ | ||
| goto error; | ||
| } | ||
| else{ | ||
| exec->vm_data.warm = false; | ||
| } | ||
| exec = next; | ||
| } | ||
| for (Py_ssize_t i = 0; i < PyList_GET_SIZE(invalidate); i++){ | ||
| _PyExecutorObject *exec = (_PyExecutorObject *)PyList_GET_ITEM(invalidate, i); | ||
| executor_clear(exec); | ||
| } | ||
| Py_DECREF(invalidate); | ||
| return; | ||
savannahostrowski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| error: | ||
| PyErr_Clear(); | ||
| Py_XDECREF(invalidate); | ||
| // If we're truly out of memory, wiping out everything is a fine fallback: | ||
| _Py_Executors_InvalidateAll(interp, 0); | ||
| } | ||
| #endif /* _Py_TIER2 */ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.