Skip to content

Commit f9fae9f

Browse files
spredolacguangli-dai
authored andcommitted
Experimental configuration option for fast path prefetch from cache_bin
1 parent c45b622 commit f9fae9f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

configure.ac

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,36 @@ if test "x$enable_experimental_smallocx" = "x1" ; then
14341434
fi
14351435
AC_SUBST([enable_experimental_smallocx])
14361436

1437+
dnl Do not enable fastpath prefetch by default.
1438+
AC_ARG_ENABLE([experimental_fp_prefetch],
1439+
[AS_HELP_STRING([--enable-experimental-fp-prefetch], [Enable experimental fastpath prefetch])],
1440+
[if test "x$enable_experimental_fp_prefetch" = "xno" ; then
1441+
enable_experimental_fp_prefetch="0"
1442+
else
1443+
dnl Check if we have __builtin_prefetch.
1444+
JE_CFLAGS_SAVE()
1445+
JE_CFLAGS_ADD([-Werror=implicit-function-declaration])
1446+
JE_COMPILABLE([builtin prefetch], [], [
1447+
void foo(void *p) { __builtin_prefetch(p, 1, 3); }
1448+
],
1449+
[je_cv_have_builtin_prefetch])
1450+
1451+
if test "x${je_cv_have_builtin_prefetch}" = "xyes" ; then
1452+
enable_experimental_fp_prefetch="1"
1453+
else
1454+
enable_experimental_fp_prefetch="0"
1455+
AC_MSG_ERROR([--enable--experimental-fp-prefetch can only be used when builtin_preftech is available])
1456+
fi
1457+
JE_CFLAGS_RESTORE()
1458+
fi
1459+
],
1460+
[enable_experimental_fp_prefetch="0"]
1461+
)
1462+
if test "x$enable_experimental_fp_prefetch" = "x1" ; then
1463+
AC_DEFINE([JEMALLOC_EXPERIMENTAL_FASTPATH_PREFETCH], [ ], [ ])
1464+
fi
1465+
AC_SUBST([enable_experimental_fp_prefetch])
1466+
14371467
dnl Do not enable profiling by default.
14381468
AC_ARG_ENABLE([prof],
14391469
[AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],

include/jemalloc/internal/jemalloc_internal_defs.h.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
/* JEMALLOC_EXPERIMENTAL_SMALLOCX_API enables experimental smallocx API. */
161161
#undef JEMALLOC_EXPERIMENTAL_SMALLOCX_API
162162

163+
/* JEMALLOC_EXPERIMENTAL_FASTPATH_PREFETCH enables prefetch
164+
* on malloc fast path.
165+
*/
166+
#undef JEMALLOC_EXPERIMENTAL_FASTPATH_PREFETCH
167+
163168
/* JEMALLOC_PROF enables allocation profiling. */
164169
#undef JEMALLOC_PROF
165170

include/jemalloc/internal/jemalloc_internal_inlines_c.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ imalloc_fastpath(size_t size, void *(fallback_alloc)(size_t)) {
374374
*/
375375
ret = cache_bin_alloc_easy(bin, &tcache_success);
376376
if (tcache_success) {
377+
#if defined(JEMALLOC_EXPERIMENTAL_FASTPATH_PREFETCH)
378+
cache_bin_sz_t lb = (cache_bin_sz_t)(uintptr_t)bin->stack_head;
379+
if(likely(lb != bin->low_bits_empty)) {
380+
util_prefetch_write_range(*(bin->stack_head), usize);
381+
}
382+
#endif
377383
fastpath_success_finish(tsd, allocated_after, bin, ret);
378384
return ret;
379385
}

0 commit comments

Comments
 (0)