supported_cpu="no"
supported_os="no"
bogus_os="no"
+malloc_trim=""
# parse CC options first
for opt do
;;
--enable-tcg) tcg="yes"
;;
+ --disable-malloc-trim) malloc_trim="no"
+ ;;
+ --enable-malloc-trim) malloc_trim="yes"
+ ;;
--disable-spice) spice="no"
;;
--enable-spice) spice="yes"
Default:trace-<pid>
--disable-slirp disable SLIRP userspace network connectivity
--enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)
+ --enable-malloc-trim enable libc malloc_trim() for memory optimization
--oss-lib path to OSS library
--cpu=CPU Build for host CPU [$cpu]
--with-coroutine=BACKEND coroutine backend. Supported options:
exit 1
fi
+# Even if malloc_trim() is available, these non-libc memory allocators
+# do not support it.
+if test "$tcmalloc" = "yes" || test "$jemalloc" = "yes" ; then
+ if test "$malloc_trim" = "yes" ; then
+ echo "Disabling malloc_trim with non-libc memory allocator"
+ fi
+ malloc_trim="no"
+fi
+
+#######################################
+# malloc_trim
+
+if test "$malloc_trim" != "no" ; then
+ cat > $TMPC << EOF
+#include <malloc.h>
+int main(void) { malloc_trim(0); return 0; }
+EOF
+ if compile_prog "" "" ; then
+ malloc_trim="yes"
+ else
+ malloc_trim="no"
+ fi
+fi
+
##########################################
# tcmalloc probe
echo "TCG debug enabled $debug_tcg"
echo "TCG interpreter $tcg_interpreter"
fi
+echo "malloc trim support $malloc_trim"
echo "RDMA support $rdma"
echo "fdt support $fdt"
echo "preadv support $preadv"
fi
fi
+if test "$malloc_trim" = "yes" ; then
+ echo "CONFIG_MALLOC_TRIM=y" >> $config_host_mak
+fi
+
if test "$avx2_opt" = "yes" ; then
echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
fi
#include "qemu/atomic.h"
#include "qemu/thread.h"
#include "qemu/main-loop.h"
+#if defined(CONFIG_MALLOC_TRIM)
+#include <malloc.h>
+#endif
/*
* Global grace period counter. Bit 0 is always one in rcu_gp_ctr.
qemu_event_reset(&rcu_call_ready_event);
n = atomic_read(&rcu_call_count);
if (n == 0) {
+#if defined(CONFIG_MALLOC_TRIM)
+ malloc_trim(4 * 1024 * 1024);
+#endif
qemu_event_wait(&rcu_call_ready_event);
}
}