Skip to content

Commit

Permalink
julia_gc: remove SKIP_GUARD_PAGES mode (#5727)
Browse files Browse the repository at this point in the history
Two reasons for the removal: 1. it doesn't work as implemented;
e.g. on my system it skips 4kb guard page but there actually is an
8kb guard page; 2. it is conceptually the wrong place to do it
here.

Instead, the Julia function `jl_active_task_stack` needs to be
adapted to skip guard pages. Only it has enough information to do
so correctly and in all cases. Indeed, in some task stacks, there
is a guard page allocated by the operating system and hence the
code removed by this commit would do the right thing.

But for other task stacks the guard page is actually created by
Julia (which explains why it can be larger than whatever guard
page size is configured in pthreads), but the details actually
depend on the platform, and so we don't have enough information
about it.

So we just drop the guard page code here. In a future version of
Julia, `jl_active_task_stack` will skip guard pages. And then the
`jl_get_safe_restore` / `jl_set_safe_restore` mechanism just won't
be triggered anymore, and we can eventually remove it, in a future
revision of this code.
  • Loading branch information
fingolfin authored May 28, 2024
1 parent 19ae178 commit d74e52b
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ JL_DLLEXPORT void * jl_get_ptls_states(void);
** Various options controlling special features of the Julia GC code follow
*/

// if SKIP_GUARD_PAGES is set, stack scanning will attempt to determine
// the extent of any guard pages and skip them if needed.
// #define SKIP_GUARD_PAGES

// if REQUIRE_PRECISE_MARKING is defined, we assume that all marking
// functions are precise, i.e., they only invoke MarkBag on valid bags,
// immediate objects or NULL pointers, but not on any other random data
Expand All @@ -87,10 +83,6 @@ JL_DLLEXPORT void * jl_get_ptls_states(void);
// the GAP.jl package.
// #define USE_GAP_INSIDE_JULIA

#ifdef SKIP_GUARD_PAGES
#include <pthread.h>
#endif


/****************************************************************************
**
Expand Down Expand Up @@ -188,10 +180,6 @@ static size_t MaxPoolObjSize;
static int FullGC;
static UInt StartTime, TotalTime;

#ifdef SKIP_GUARD_PAGES
static size_t GuardPageSize;
#endif

#if !defined(USE_GAP_INSIDE_JULIA)
static Bag * GapStackBottom;
static jl_task_t * RootTaskOfMainThread;
Expand Down Expand Up @@ -444,30 +432,8 @@ static void FindLiveRangeReverse(PtrArray * arr, void * start, void * end)
}
}

#ifdef SKIP_GUARD_PAGES

static void SetupGuardPagesSize(void)
{
// This is a generic implementation that assumes that all threads
// have the default guard pages. This should be correct for the
// current Julia implementation.
pthread_attr_t attr;
pthread_attr_init(&attr);
if (pthread_attr_getguardsize(&attr, &GuardPageSize) < 0) {
perror("Julia GC initialization: pthread_attr_getguardsize");
abort();
}
pthread_attr_destroy(&attr);
}

#endif


static void SafeScanTaskStack(PtrArray * stack, void * start, void * end)
{
#ifdef SKIP_GUARD_PAGES
FindLiveRangeReverse(stack, start, end);
#else
volatile jl_jmp_buf * old_safe_restore = jl_get_safe_restore();
jl_jmp_buf exc_buf;
if (!jl_setjmp(exc_buf, 0)) {
Expand All @@ -485,7 +451,6 @@ static void SafeScanTaskStack(PtrArray * stack, void * start, void * end)
FindLiveRangeReverse(stack, start, end);
}
jl_set_safe_restore((jl_jmp_buf *)old_safe_restore);
#endif
}

static void MarkFromList(jl_ptls_t ptls, PtrArray * arr)
Expand Down Expand Up @@ -642,13 +607,6 @@ static void GapTaskScanner(jl_task_t * task, int root_task)
&total_end);

if (active_start) {
#ifdef SKIP_GUARD_PAGES
if (total_start == active_start && total_end == active_end) {
// The "active" range is actually the entire stack buffer
// and may include guard pages at the start.
active_start += GuardPageSize;
}
#endif
#if !defined(USE_GAP_INSIDE_JULIA)
if (task == RootTaskOfMainThread) {
active_end = (char *)GapStackBottom;
Expand Down Expand Up @@ -786,10 +744,6 @@ void GAP_InitJuliaMemoryInterface(jl_module_t * module,
jl_init();
#endif

#ifdef SKIP_GUARD_PAGES
SetupGuardPagesSize();
#endif

#ifdef JULIA_MULTIPLE_GC_THREADS_SUPPORTED
if (jl_n_gcthreads > 1)
pthread_mutex_init(&TaskStacksMutex, NULL);
Expand Down

0 comments on commit d74e52b

Please sign in to comment.