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 3EC86A00C2 for ; Fri, 24 Apr 2020 15:18:55 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F39971C29A; Fri, 24 Apr 2020 15:18:54 +0200 (CEST) Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by dpdk.org (Postfix) with ESMTP id CE1AC1C231 for ; Fri, 24 Apr 2020 15:18:51 +0200 (CEST) Received: by mail-pj1-f66.google.com with SMTP id fu13so3291629pjb.5 for ; Fri, 24 Apr 2020 06:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:content-transfer-encoding; bh=1OXypELrhJuYYDen6foC8ne6MJ3Cen6lvRTej/0Qxis=; b=wtAwU2dXZfFspg4cDybQ09/e47FdoLfw/rZZh0V8kX2ot0GLC3ooPaGMA3gTQqAp5E bIBZu60Dx6XikIeUQNbtWuwvVzeekIDhdiMqSuL/8VI8u5DBRGEqXTlKyI8R4tLxcbnd bp9hcLhr55bZKBCHBza1ojoUrSYibg1DrDsCwtfkMobypi7dNUra+LpdRmaKopKur9N/ OFU50aCdHXY9o3wsxTsRgaMQcamGYKsEXyiOMsm3EkxMTV6hRjxmRd3qNgi1xZyB66dT gISI6lhWlDnj+/T2ajaq1Zac2ppkuhwIYoC65ckPhEHMaoHpQIOJlZsfAEz4u/1b9fmD FoMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:content-transfer-encoding; bh=1OXypELrhJuYYDen6foC8ne6MJ3Cen6lvRTej/0Qxis=; b=n/zwVAYmMvsJZBP2Dakckf2PcceqjFvIeAlY8dCTiu6UJuQPlP7cnogJ6YkSgY3iqS 7anNMsExlZLbM9crlkg+nf3ju+5vr9oTNvWKrlkAb+XlmOUq05vT8TUw5Hqbfa1zkkpc XHBS4uApXimdbQjiiaeHs630xGpWx+f1VXkh3MY3tmNgBXPVoJIyLbwoXqHtAOx+i+fu +t2zKRxv7RTxt4+LknMOiNOesrkG4iK8cSuiUr+NE1+zfCCyARETKpQQmKRl1APOfiEE 9Ttn3RyBWyuPlp8JMoWWG3yyFGpxjK39CuewSoZ+97r4VXiALpsts9JnaCv7V1OrIZuT N9Eg== MIME-Version: 1.0 X-Gm-Message-State: AGi0Puag+UQx39H10S/iZ5czHX/g5bnU2ZSTOwORA4d7xthQQzO75wXb UOErSEXyH/eFJF/SqsQbWhe3lQ6yMCLRlnOUrlWoKBroZg8TDLs1Yiybyxh4IgE32PcTVbfHyYL d X-Google-Smtp-Source: APiQypIYeURRyw38PQXELfaUosNH2A/iqfYiwMVF0e4I0Zp5KhBYmiJvuBpwVFlFGJbdYpuz+mQqKw== X-Received: by 2002:a17:902:a586:: with SMTP id az6mr9051536plb.201.1587734330810; Fri, 24 Apr 2020 06:18:50 -0700 (PDT) Received: from 31_216.localdomain ([47.240.167.159]) by smtp.gmail.com with ESMTPSA id w30sm5877476pfj.25.2020.04.24.06.18.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 06:18:50 -0700 (PDT) From: Li Feng To: Anatoly Burakov Cc: dev@dpdk.org, stable@dpdk.org, kyle@smartx.com, lifeng1519@gmail.com, fanyang@smartx.com, david.marchand@redhat.com, bruce.richardson@intel.com, Li Feng Date: Fri, 24 Apr 2020 21:19:05 +0800 Message-Id: <20200424131905.18315-1-fengli@smartx.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200424105016.28974-1-fengli@smartx.com> References: <20200424105016.28974-1-fengli@smartx.com> Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH v6] eal: use madvise to exclude unmapped memory from being dumped X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" 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 --- v6: - use RTE_DONTDUMP in right place. 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/com= mon/eal_common_memory.c index cc7d54e0c..cd20672ce 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; =20 +#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 + #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 *siz= e, munmap(aligned_end, after_len); } =20 + if (!unmap) { + /* + * Exclude this pages from a core dump. + */ + if (madvise(aligned_addr, *size, RTE_DONTDUMP) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", + strerror(errno)); + } + return aligned_addr; } =20 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 *h= i, return -1; } =20 + if (madvise(ms->addr, ms->len, MADV_DONTDUMP) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", strerror(errno)); + exit_early =3D false; =20 /* if we're using anonymous hugepages, nothing to be done */ --=20 2.11.0 --=20 The SmartX email address is only for business purpose. Any sent message=20 that is not related to the business is not authorized or permitted by=20 SmartX. =B1=BE=D3=CA=CF=E4=CE=AA=B1=B1=BE=A9=D6=BE=C1=E8=BA=A3=C4=C9=BF=C6=BC=BC=D3= =D0=CF=DE=B9=AB=CB=BE=A3=A8SmartX=A3=A9=B9=A4=D7=F7=D3=CA=CF=E4. =C8=E7=B1= =BE=D3=CA=CF=E4=B7=A2=B3=F6=B5=C4=D3=CA=BC=FE=D3=EB=B9=A4=D7=F7=CE=DE=B9=D8= ,=B8=C3=D3=CA=BC=FE=CE=B4=B5=C3=B5=BD=B1=BE=B9=AB=CB=BE=C8=CE=BA=CE=B5=C4= =C3=F7=CA=BE=BB=F2=C4=AC=CA=BE=B5=C4=CA=DA=C8=A8.