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 5AF4DA00C2; Fri, 24 Apr 2020 12:51:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2A3E81C1C1; Fri, 24 Apr 2020 12:51:31 +0200 (CEST) Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by dpdk.org (Postfix) with ESMTP id 84CCF1C1C1 for ; Fri, 24 Apr 2020 12:51:29 +0200 (CEST) Received: by mail-pj1-f67.google.com with SMTP id t9so3752009pjw.0 for ; Fri, 24 Apr 2020 03:51:29 -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 :content-transfer-encoding; bh=DssYjyPFAAyCKKDJo1mrWyZj66pzxsslobSIj5HdQe8=; b=YiRY8MaQVZqIzUSu/7p7vvMAFZngcBVz5G/vPQMWdzx6XEkobUY40putaLPMdHmLcu m0wUWBiuliUeiU2f4UHmpGC7Ol9odM46azhhPOq8539qOTmaqrdP+vPPb0k9B5iVLtZz lGlZm6CAVzpVahMOhnyDfQAcO+fiCGAwMQE2wvMyBZ1PvlKRi0sNVoHR2KFxREtsosSQ rBxdQJjnFYOWtieHTUAg4asQ44wJV9A8I2i0mU3sOmt8td1OKEhCtWrgt2EDP6hNhoKm L8iYuCqKlwrAjf3IpKM3XAJIyg2adgg0xY1rBGUOCEOg+ubFrd7G6K/VqFgx8ZssCH1u bjQQ== 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 :content-transfer-encoding; bh=DssYjyPFAAyCKKDJo1mrWyZj66pzxsslobSIj5HdQe8=; b=tK7SpTrwmA6D0RGOKGK7VQYUFudYq14xURaPun94hXx+heM1sO5SohHArTlgG0B02W CZcOCzyopwngQ2Rrj3jVHQOA2WUXLHMXGvY6E/ZJ4D8nPTKyjk55GD4x/m7IqKHNt1ZO cQ3svrpqji7QwYwO+311XMZaALdfGURa64WGm/VEJP8TSg+4euz4cxxg+ErMPBElOypO 04DUypDwjQ7PfTMhYisont/el3BXmdJ+nxcRLGX9BU4IVZaAFldGdm1gP/KBdwszciRt H/F5/i/GKpX5aRhJwaiQMNsL4M+7HsmYzkqs6ug+MNfR000Az41KPkVWKgtuwk2HKmEx LJ3A== MIME-Version: 1.0 X-Gm-Message-State: AGi0PuaoqdCpvSZrY1esdlbPeWRBHOqtlm/U4a17ewntDjVXwKW/AiU+ NF+4aDtz+L0AG84f2K+rX6AVtmLkyXr3KPgNbs/+eSSBKyFXdhLZHI7bJ/q/GrfQx9FWUdln X-Google-Smtp-Source: APiQypI3Be68r4AMogLtS2Cqa1ESw28fefUjYQvQRfSgIAX0ad+Obhpv0kVl7iBBf9uWrse8pp7p7g== X-Received: by 2002:a17:90a:7486:: with SMTP id p6mr5559029pjk.62.1587725488550; Fri, 24 Apr 2020 03:51:28 -0700 (PDT) Received: from 31_216.localdomain (nz132l98.bb27109.ctm.net. [27.109.132.98]) by smtp.gmail.com with ESMTPSA id y10sm5428661pfb.53.2020.04.24.03.51.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 03:51:28 -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 18:50:16 +0800 Message-Id: <20200424105016.28974-1-fengli@smartx.com> X-Mailer: git-send-email 2.11.0 Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH v2] 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 --- V2: - 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 | 26 ++++++++++++++++++++++++++ lib/librte_eal/linux/eal_memalloc.c | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/com= mon/eal_common_memory.c index cc7d54e0c..83be94a20 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -177,6 +177,32 @@ eal_get_virtual_area(void *requested_addr, size_t *siz= e, after_len =3D RTE_PTR_DIFF(map_end, aligned_end); if (after_len > 0) munmap(aligned_end, after_len); + + /* + * Exclude this pages from a core dump. + */ +#ifdef RTE_EXEC_ENV_LINUX + if (madvise(aligned_addr, *size, MADV_DONTDUMP) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", + strerror(errno)); +#elif RTE_EXEC_ENV_FREEBSD + if (madvise(aligned_addr, *size, MADV_NOCORE) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", + strerror(errno)); +#endif + } else { + /* + * Exclude this pages from a core dump. + */ +#ifdef RTE_EXEC_ENV_LINUX + if (madvise(mapped_addr, map_sz, MADV_DONTDUMP) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", + strerror(errno)); +#elif RTE_EXEC_ENV_FREEBSD + if (madvise(mapped_addr, map_sz, MADV_NOCORE) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", + strerror(errno)); +#endif } =20 return aligned_addr; diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal= _memalloc.c index af6d0d023..9d2a6fc6f 100644 --- a/lib/librte_eal/linux/eal_memalloc.c +++ b/lib/librte_eal/linux/eal_memalloc.c @@ -571,6 +571,9 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket= _id, goto resized; } =20 + if (madvise(addr, alloc_sz, MADV_DODUMP) !=3D 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", strerror(errno)); + /* In linux, hugetlb limitations, like cgroup, are * enforced at fault time instead of mmap(), even * with the option of MAP_POPULATE. Kernel will send @@ -687,6 +690,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.