From nobody Thu Apr 25 15:48:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600243626; cv=none; d=zohomail.com; s=zohoarc; b=fb7sTUALcafcQeN2I0tBXZIxgl3NcvsqXH6Wdt4Q6JHkN8NDRk+YumkXPpMGkMV6aQ6E3ozQczu4zgouNW6YyQyVyo6QUd415We+Ppsima6SX09za+Yke3vdCWznaqOQZuYEOuQtWgM0Txs9oh/Otc3UOt5r0we/TsS09rjii8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600243626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=liyeG8gHMAYbtq4juBgYSCD8yA0foSFdSeydiiakjg8=; b=cNcGxh7fGq0/1JHRlRkK+xRYuz7RkZfYCNRbOndMNTcJmFrWP6Y3sqghZ0wzzYzvJHtUN9LRDn/pyRCVBAK9n9tWDeqeb2REgodOur768kev/z4f9zPOAztpG4WTzl+Jpuq130oJn6yUx0TV12Rm4sd0MX+Y/So6VYEl9gT8IdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600243626059526.801339276673; Wed, 16 Sep 2020 01:07:06 -0700 (PDT) Received: from localhost ([::1]:33906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIST2-00078X-Ba for importer@patchew.org; Wed, 16 Sep 2020 04:07:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kISSH-0006jG-5U for qemu-devel@nongnu.org; Wed, 16 Sep 2020 04:06:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kISSE-0003FF-Ss for qemu-devel@nongnu.org; Wed, 16 Sep 2020 04:06:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-PwNg6MhpOimLipsuE_Ev5A-1; Wed, 16 Sep 2020 04:06:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 262BC1017DC3 for ; Wed, 16 Sep 2020 08:06:09 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0F4768D6E; Wed, 16 Sep 2020 08:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600243574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=liyeG8gHMAYbtq4juBgYSCD8yA0foSFdSeydiiakjg8=; b=QA3kr0oUpK/sv77/wqd9AfRGuekBNHutn+VMKMb/RfbvukCjWp6Dp+Jp7GO4qtJlHkx23B zIhif5hRRsu5iffKio2euvY20atdP+2K0tEuu8TW8kD6OA7V40NGMWmw1CiVodDviuL23l WBRDytfy53jXQZro+4FVaYaB2uGHsLQ= X-MC-Unique: PwNg6MhpOimLipsuE_Ev5A-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH] configure: move malloc_trim/tcmalloc/jemalloc to meson Date: Wed, 16 Sep 2020 04:06:08 -0400 Message-Id: <20200916080608.17689-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/16 02:35:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Because LIBS is not used anymore, tcmalloc/jemalloc does not work with binaries whose description is in Meson. The fix is simply to move them to Meson too. For consistency with other configure options, specifying --enable-malloc-trim together with --enable-{tc,je}malloc becomes a fatal error. Reported-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson Reviewed-by: Stefan Hajnoczi --- configure | 84 +++++------------------------------------------ meson.build | 28 +++++++++++++--- meson_options.txt | 5 +++ 3 files changed, 38 insertions(+), 79 deletions(-) diff --git a/configure b/configure index ce27eafb0a..13f53ba231 100755 --- a/configure +++ b/configure @@ -540,7 +540,7 @@ skip_meson=3Dno gettext=3D"" =20 bogus_os=3D"no" -malloc_trim=3D"" +malloc_trim=3D"auto" =20 deprecated_features=3D"" =20 @@ -1222,9 +1222,9 @@ for opt do ;; --enable-tcg) tcg=3D"yes" ;; - --disable-malloc-trim) malloc_trim=3D"no" + --disable-malloc-trim) malloc_trim=3D"disabled" ;; - --enable-malloc-trim) malloc_trim=3D"yes" + --enable-malloc-trim) malloc_trim=3D"enabled" ;; --disable-spice) spice=3D"no" ;; @@ -4428,77 +4428,14 @@ EOF fi fi =20 +malloc=3Dsystem if test "$tcmalloc" =3D "yes" && test "$jemalloc" =3D "yes" ; then echo "ERROR: tcmalloc && jemalloc can't be used at the same time" exit 1 -fi - -# Even if malloc_trim() is available, these non-libc memory allocators -# do not support it. -if test "$tcmalloc" =3D "yes" || test "$jemalloc" =3D "yes" ; then - if test "$malloc_trim" =3D "yes" ; then - echo "Disabling malloc_trim with non-libc memory allocator" - fi - malloc_trim=3D"no" -fi - -####################################### -# malloc_trim - -if test "$malloc_trim" !=3D "no" ; then - cat > $TMPC << EOF -#include -int main(void) { malloc_trim(0); return 0; } -EOF - if compile_prog "" "" ; then - malloc_trim=3D"yes" - else - malloc_trim=3D"no" - fi -fi - -########################################## -# tcmalloc probe - -if test "$tcmalloc" =3D "yes" ; then - cat > $TMPC << EOF -#include -int main(void) { - void *tmp =3D malloc(1); - if (tmp !=3D NULL) { - return 0; - } - return 1; -} -EOF - - if compile_prog "" "-ltcmalloc" ; then - LIBS=3D"-ltcmalloc $LIBS" - else - feature_not_found "tcmalloc" "install gperftools devel" - fi -fi - -########################################## -# jemalloc probe - -if test "$jemalloc" =3D "yes" ; then - cat > $TMPC << EOF -#include -int main(void) { - void *tmp =3D malloc(1); - if (tmp !=3D NULL) { - return 0; - } - return 1; -} -EOF - - if compile_prog "" "-ljemalloc" ; then - LIBS=3D"-ljemalloc $LIBS" - else - feature_not_found "jemalloc" "install jemalloc devel" - fi +elif test "$tcmalloc" =3D "yes" ; then + malloc=3Dtcmalloc +elif test "$jemalloc" =3D "yes" ; then + malloc=3Djemalloc fi =20 ########################################## @@ -7023,10 +6960,6 @@ if test "$gbm" =3D "yes" ; then fi =20 =20 -if test "$malloc_trim" =3D "yes" ; then - echo "CONFIG_MALLOC_TRIM=3Dy" >> $config_host_mak -fi - if test "$avx2_opt" =3D "yes" ; then echo "CONFIG_AVX2_OPT=3Dy" >> $config_host_mak fi @@ -8003,6 +7936,7 @@ NINJA=3D${ninja:-$PWD/ninjatool} $meson setup \ -Dstrip=3D$(if test "$strip_opt" =3D yes; then echo true; else ech= o false; fi) \ -Db_pie=3D$(if test "$pie" =3D yes; then echo true; else echo fals= e; fi) \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ + -Dmalloc=3D$malloc -Dmalloc_trim=3D$malloc_trim \ -Dsdl=3D$sdl -Dsdl_image=3D$sdl_image \ -Dvnc=3D$vnc -Dvnc_sasl=3D$vnc_sasl -Dvnc_jpeg=3D$vnc_jpeg -Dvnc_png=3D$v= nc_png \ -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f\ diff --git a/meson.build b/meson.build index bba766b4bc..d3b1e5c34c 100644 --- a/meson.build +++ b/meson.build @@ -439,6 +439,26 @@ keyutils =3D dependency('libkeyutils', required: false, =20 has_gettid =3D cc.has_function('gettid') =20 +# Malloc tests + +malloc =3D [] +if get_option('malloc') =3D=3D 'system' + has_malloc_trim =3D \ + not get_option('malloc_trim').disabled() and \ + cc.compiles('''#include + int main(void) { malloc_trim(0); return 0; }''') +else + has_malloc_trim =3D false + malloc =3D cc.find_library(get_option('malloc'), required: true) +endif +if not has_malloc_trim and get_option('malloc_trim').enabled() + if get_option('malloc') =3D=3D 'system' + error('malloc_trim not available on this platform.') + else + error('malloc_trim not available with non-libc memory allocator') + endif +endif + # Create config-host.h =20 config_host_data.set('CONFIG_SDL', sdl.found()) @@ -450,6 +470,7 @@ config_host_data.set('CONFIG_VNC_SASL', sasl.found()) config_host_data.set('CONFIG_XKBCOMMON', xkbcommon.found()) config_host_data.set('CONFIG_KEYUTILS', keyutils.found()) config_host_data.set('CONFIG_GETTID', has_gettid) +config_host_data.set('CONFIG_MALLOC_TRIM', has_malloc_trim) config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version(= ))) config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('= .')[0]) config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('= .')[1]) @@ -818,7 +839,7 @@ util_ss.add_all(trace_ss) util_ss =3D util_ss.apply(config_all, strict: false) libqemuutil =3D static_library('qemuutil', sources: util_ss.sources() + stub_ss.sources(= ) + genh, - dependencies: [util_ss.dependencies(), m, gli= b, socket]) + dependencies: [util_ss.dependencies(), m, gli= b, socket, malloc]) qemuutil =3D declare_dependency(link_with: libqemuutil, sources: genh + version_res) =20 @@ -1442,7 +1463,7 @@ summary_info +=3D {'Install blobs': config_host.h= as_key('INSTALL_BLOBS')} # summary_info +=3D {'TCG debug enabled': config_host.has_key('CONFIG_DEB= UG_TCG')} # summary_info +=3D {'TCG interpreter': config_host.has_key('CONFIG_TCG= _INTERPRETER')} #endif -summary_info +=3D {'malloc trim support': config_host.has_key('CONFIG_MALL= OC_TRIM')} +summary_info +=3D {'malloc trim support': has_malloc_trim} summary_info +=3D {'RDMA support': config_host.has_key('CONFIG_RDMA')} summary_info +=3D {'PVRDMA support': config_host.has_key('CONFIG_PVRDMA= ')} summary_info +=3D {'fdt support': config_host.has_key('CONFIG_FDT')} @@ -1504,8 +1525,7 @@ summary_info +=3D {'lzfse support': config_host.h= as_key('CONFIG_LZFSE')} summary_info +=3D {'zstd support': config_host.has_key('CONFIG_ZSTD')} summary_info +=3D {'NUMA host support': config_host.has_key('CONFIG_NUMA')} summary_info +=3D {'libxml2': config_host.has_key('CONFIG_LIBXML= 2')} -summary_info +=3D {'tcmalloc support': config_host.has_key('CONFIG_TCMALL= OC')} -summary_info +=3D {'jemalloc support': config_host.has_key('CONFIG_JEMALL= OC')} +summary_info +=3D {'memory allocator': get_option('malloc')} summary_info +=3D {'avx2 optimization': config_host.has_key('CONFIG_AVX2_O= PT')} summary_info +=3D {'avx512f optimization': config_host.has_key('CONFIG_AVX= 512F_OPT')} summary_info +=3D {'replication support': config_host.has_key('CONFIG_REPL= ICATION')} diff --git a/meson_options.txt b/meson_options.txt index 543cf70043..894e006799 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -6,6 +6,11 @@ option('docdir', type : 'string', value : 'doc', option('gettext', type : 'boolean', value : true, description: 'Localization of the GTK+ user interface') =20 +option('malloc_trim', type : 'feature', value : 'auto', + description: 'enable libc malloc_trim() for memory optimization') +option('malloc', type : 'combo', choices : ['system', 'tcmalloc', 'jemallo= c'], + value: 'system', description: 'choose memory allocator to use') + option('sdl', type : 'feature', value : 'auto', description: 'SDL user interface') option('sdl_image', type : 'feature', value : 'auto', --=20 2.26.2