@@ -50,7 +50,6 @@ static jl_gc_callback_list_t *gc_cblist_post_gc;
5050static jl_gc_callback_list_t * gc_cblist_notify_external_alloc ;
5151static jl_gc_callback_list_t * gc_cblist_notify_external_free ;
5252static jl_gc_callback_list_t * gc_cblist_notify_gc_pressure ;
53- typedef void (* jl_gc_cb_notify_gc_pressure_t )(void );
5453
5554#define gc_invoke_callbacks (ty , list , args ) \
5655 do { \
@@ -138,12 +137,12 @@ JL_DLLEXPORT void jl_gc_set_cb_notify_external_free(jl_gc_cb_notify_external_fre
138137}
139138
140139JL_DLLEXPORT void jl_gc_set_cb_notify_gc_pressure (jl_gc_cb_notify_gc_pressure_t cb , int enable )
141- {
142- if (enable )
143- jl_gc_register_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
144- else
145- jl_gc_deregister_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
146- }
140+ {
141+ if (enable )
142+ jl_gc_register_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
143+ else
144+ jl_gc_deregister_callback (& gc_cblist_notify_gc_pressure , (jl_gc_cb_func_t )cb );
145+ }
147146
148147// Protect all access to `finalizer_list_marked` and `to_finalize`.
149148// For accessing `ptls->finalizers`, the lock is needed if a thread
@@ -676,6 +675,7 @@ static void gc_sweep_foreign_objs(void)
676675}
677676
678677// GC knobs and self-measurement variables
678+ static int under_memory_pressure ;
679679static int64_t last_gc_total_bytes = 0 ;
680680
681681// max_total_memory is a suggestion. We try very hard to stay
@@ -3495,6 +3495,7 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
34953495 // If the live data outgrows the suggested max_total_memory
34963496 // we keep going with full gcs until we either free some space or get an OOM error.
34973497 if (live_bytes > max_total_memory ) {
3498+ under_memory_pressure = 1 ;
34983499 sweep_full = 1 ;
34993500 }
35003501 if (gc_sweep_always_full ) {
@@ -3702,10 +3703,12 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection)
37023703
37033704 gc_invoke_callbacks (jl_gc_cb_post_gc_t ,
37043705 gc_cblist_post_gc , (collection ));
3705- if (under_pressure )
3706+
3707+ if (under_memory_pressure ) {
37063708 gc_invoke_callbacks (jl_gc_cb_notify_gc_pressure_t ,
37073709 gc_cblist_notify_gc_pressure , ( ));
3708- under_pressure = 0 ;
3710+ }
3711+ under_memory_pressure = 0 ;
37093712#ifdef _OS_WINDOWS_
37103713 SetLastError (last_error );
37113714#endif
0 commit comments