From nobody Fri May 3 22:41:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510899926174810.2042835836863; Thu, 16 Nov 2017 22:25:26 -0800 (PST) Received: from localhost ([::1]:44087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFa5V-0000ky-Ec for importer@patchew.org; Fri, 17 Nov 2017 01:25:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFa4b-0000T4-QN for qemu-devel@nongnu.org; Fri, 17 Nov 2017 01:24:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFa4Y-0005Np-KD for qemu-devel@nongnu.org; Fri, 17 Nov 2017 01:24:21 -0500 Received: from mga11.intel.com ([192.55.52.93]:56601) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFa4Y-0005Iy-C0 for qemu-devel@nongnu.org; Fri, 17 Nov 2017 01:24:18 -0500 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Nov 2017 22:24:13 -0800 Received: from yangzhon-virtual.bj.intel.com ([10.238.145.49]) by fmsmga007.fm.intel.com with ESMTP; 16 Nov 2017 22:24:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,407,1505804400"; d="scan'208";a="147041" From: Yang Zhong To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 17 Nov 2017 14:23:34 +0800 Message-Id: <1510899814-19372-1-git-send-email-yang.zhong@intel.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH] rcu: reduce half heap memory size by malloc_trim() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, weidong.huang@huawei.com, arei.gonglei@huawei.com, liujunjie23@huawei.com, wangxinxin.wang@huawei.com, stone.xulei@huawei.com, anthony.xu@intel.com, stefanha@redhat.com, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since there are some issues in memory alloc/free machenism in glibc for little chunk memory, if Qemu frequently alloc/free little chunk memory, the glibc doesn't alloc little chunk memory from free list of glibc and still allocate from OS, which make the heap size bigger and bigger. This patch introduce malloc_trim(), which will free heap memory. Below are test results from smaps file. 55f0783e1000-55f07992a000 rw-p 00000000 00:00 0 [heap] Size: 21796 kB Rss: 14260 kB Pss: 14260 kB 55cc5fadf000-55cc61008000 rw-p 00000000 00:00 0 [heap] Size: 21668 kB Rss: 6940 kB Pss: 6940 kB Signed-off-by: Yang Zhong --- util/rcu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/rcu.c b/util/rcu.c index ca5a63e..8d491a6 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -26,6 +26,7 @@ * IBM's contributions to this file may be relicensed under LGPLv2 or late= r. */ =20 +#include #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/rcu.h" @@ -272,6 +273,9 @@ static void *call_rcu_thread(void *opaque) node->func(node); } qemu_mutex_unlock_iothread(); +#ifdef CONFIG_LINUX + malloc_trim(0); +#endif } abort(); } --=20 1.9.1