Skip to content

Commit ee37ef9

Browse files
apaz-cliKeno
andauthored
Using MADV_FREE in jl_gc_free_page(), with fallback to MADV_DONTNEED. (#46362)
Co-authored-by: Keno Fischer <[email protected]>
1 parent ec98087 commit ee37ef9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/gc-pages.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ void jl_gc_free_page(void *p) JL_NOTSAFEPOINT
302302
}
303303
#ifdef _OS_WINDOWS_
304304
VirtualFree(p, decommit_size, MEM_DECOMMIT);
305+
#elif defined(MADV_FREE)
306+
static int supports_madv_free = 1;
307+
if (supports_madv_free) {
308+
if (madvise(p, decommit_size, MADV_FREE) == -1) {
309+
assert(errno == EINVAL);
310+
supports_madv_free = 0;
311+
}
312+
}
313+
if (!supports_madv_free) {
314+
madvise(p, decommit_size, MADV_DONTNEED);
315+
}
305316
#else
306317
madvise(p, decommit_size, MADV_DONTNEED);
307318
#endif

0 commit comments

Comments
 (0)