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 EBB9DA00C2; Fri, 24 Apr 2020 15:18:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6D97F1C231; Fri, 24 Apr 2020 15:18:53 +0200 (CEST) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by dpdk.org (Postfix) with ESMTP id BCFED1C22C for ; Fri, 24 Apr 2020 15:18:51 +0200 (CEST) Received: by mail-pl1-f194.google.com with SMTP id c21so2904886plz.4 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=SAy3jD7gSHuIIH8OZAc/lw0i2fSMUToYmA4ikpa58S9BerZAwM+hy7leazJbGiN+Sl /Zhm54DV2Ow+vsbnXTG7G6Hi1TRN+Npqa0x+cxYK+84st8fxZPJU4Y66hKO3o1Wig/7n pSzUXrwAgiJEiWga7HFMhPVKp+s6UVl2vk9spA/jfqxL0DStW0S8utPU77fNuEJcI72q bLXcT31Mh3v/QPfuKMYiA/nyqDVW10GfGK+k9yLzfEf0hzkMhvN0VD+aHVK1f5r9R6Jr 96ImZ9SdNwSy26gGPVnf+UjxjvNImaZz6qeF/6UtokHG4XDXMBBgsydqSVCkeYNDJkNn yypA== MIME-Version: 1.0 X-Gm-Message-State: AGi0PuamcuOw2w1e6aLyzHsbQp5tQyfk3rrcQOGP/y+mp3+UkJR5Ir6o qgAcXR8iDPD5Q7sH+SUxESOdWz85n7RFLRD6JfWKFcx8SnDjGWtRMVaeb0JmOcMkzK6zOMtL 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-dev] [PATCH v6] 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" 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.