From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0CB3A00C2; Fri, 24 Apr 2020 15:05:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 09DB92C5E; Fri, 24 Apr 2020 15:02:57 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 9F2231C23F; Fri, 24 Apr 2020 15:02:54 +0200 (CEST) IronPort-SDR: 1qDoLm5DLqtxYn3NTw8+GeIGyD9gaYMo6hRjfGhBPguU4hhbnizB2W9sLwQZmwAYihwqfToKcu 8/RgbIiXvFfA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2020 06:02:52 -0700 IronPort-SDR: Rq/W357InuJhVpdIlK53H6bY0jUv19o93p6tEHRGjVNEeMkowZJM0oKMiQBSct6wKJ4E44zb8F pIOgQ8f0LCcA== X-IronPort-AV: E=Sophos;i="5.73,311,1583222400"; d="scan'208";a="403293471" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.36.26]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 24 Apr 2020 06:02:49 -0700 Date: Fri, 24 Apr 2020 14:02:46 +0100 From: Bruce Richardson To: Li Feng Cc: Anatoly Burakov , dev@dpdk.org, stable@dpdk.org, kyle@smartx.com, lifeng1519@gmail.com, fanyang@smartx.com, david.marchand@redhat.com Message-ID: <20200424130246.GB1446@bricha3-MOBL.ger.corp.intel.com> References: <20200424105016.28974-1-fengli@smartx.com> <20200424125311.25364-1-fengli@smartx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200424125311.25364-1-fengli@smartx.com> Subject: Re: [dpdk-dev] [PATCH v5] eal: use madvise to exclude unmapped memory from being dumped X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, Apr 24, 2020 at 08:53:11PM +0800, Li Feng wrote: > Currently, even though memory is mapped with PROT_NONE, this does not > cause it to be excluded from core dumps. This is counter-productive, > because in a lot of cases, this memory will go unused (e.g. when the > memory subsystem preallocates VA space but hasn't yet mapped physical > pages into it). > > Use `madvise()` call with MADV_DONTDUMP parameter to exclude the > unmapped memory from being dumped. > > Signed-off-by: Li Feng > --- > v5: > - fix a code style. > > V4: > - simplify the code; > - remove the undo code in V3; > > V3: > - add support for freebsd. > - when free_seg is called, mark the memory MADV_DONTDUMP. > - when alloc_seg is called, mark the memory MADV_DODUMP. > > lib/librte_eal/common/eal_common_memory.c | 17 +++++++++++++++++ > lib/librte_eal/linux/eal_memalloc.c | 3 +++ > 2 files changed, 20 insertions(+) > > diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c > index cc7d54e0c..161e49825 100644 > --- a/lib/librte_eal/common/eal_common_memory.c > +++ b/lib/librte_eal/common/eal_common_memory.c > @@ -40,6 +40,14 @@ > static void *next_baseaddr; > static uint64_t system_page_sz; > > +#ifdef RTE_EXEC_ENV_LINUX > +#define RTE_DONTDUMP MADV_DONTDUMP > +#elif RTE_EXEC_ENV_FREEBSD > +#define RTE_DONTDUMP MADV_NOCORE > +#else > +#error "madvise doesn't support this OS" > +#endif > + You forgot to use RTE_DONTDUMP in place of MADV_DONTDUMP below. > #define MAX_MMAP_WITH_DEFINED_ADDR_TRIES 5 > void * > eal_get_virtual_area(void *requested_addr, size_t *size, > @@ -179,6 +187,15 @@ eal_get_virtual_area(void *requested_addr, size_t *size, > munmap(aligned_end, after_len); > } > > + if (!unmap) { > + /* > + * Exclude this pages from a core dump. > + */ > + if (madvise(aligned_addr, *size, MADV_DONTDUMP) != 0) > + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", > + strerror(errno)); > + } > + > return aligned_addr; > } > > diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal_memalloc.c > index af6d0d023..f628e0991 100644 > --- a/lib/librte_eal/linux/eal_memalloc.c > +++ b/lib/librte_eal/linux/eal_memalloc.c > @@ -687,6 +687,9 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, > return -1; > } > > + if (madvise(ms->addr, ms->len, MADV_DONTDUMP) != 0) > + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", strerror(errno)); > + > exit_early = false; > > /* if we're using anonymous hugepages, nothing to be done */ > -- > 2.11.0 > > > -- > The SmartX email address is only for business purpose. Any sent message > that is not related to the business is not authorized or permitted by > SmartX. > 本邮箱为北京志凌海纳科技有限公司(SmartX)工作邮箱. 如本邮箱发出的邮件与工作无关,该邮件未得到本公司任何的明示或默示的授权. > >