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 12B1BA00C2; Fri, 24 Apr 2020 14:38:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E35651C1F9; Fri, 24 Apr 2020 14:38:52 +0200 (CEST) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 7ABF71C1E7 for ; Fri, 24 Apr 2020 14:38:51 +0200 (CEST) Received: by mail-pf1-f193.google.com with SMTP id p25so4728975pfn.11 for ; Fri, 24 Apr 2020 05:38: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=ciG/9JXPvCp1Ka9oltbEcPKpqdQJ3YYcqIQzkK8vmAw=; b=bpDKQQdDMIV57t7zRJB4Ri/EI0kEnE7mBfAn0mTGhd5uiqKbA3zKUlJPoCVbykNJNc 6J1zBBJKso4O0PZ35WeKHQoRb0zBm5posfJzLuuZ+KYv19DiZrthY6yBixPIP45I5mtX /2LNcdnsB/JWO9nRtiAaM94bfzfpGsbYV1/sDROARJwBqAI69y0JgNuRjb+twqo7U0Ea KsZOJRpmFH7jUeCnzPHKh0qj8nI85nwB87NrTvhfoNEXYJgGUhHgRUnvBHjxBOZvrC2n ZJZygGPmty0sQKL513yb7tjSED3zMDiDLv4GQ+xgjDai3PNozMh7a6QyYf9By5d903vq UF4g== 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=ciG/9JXPvCp1Ka9oltbEcPKpqdQJ3YYcqIQzkK8vmAw=; b=BZZ7OxsN2qkrdIuqINqbaKh3QAn79ihc8u1/jCRyuowAZiTMwKzdkgp//gubsn0JbM Gr0PM6IAIyeS+nZqZN58ggIjEKLRKiMX4spsAS4VfpasaRReCzVCwJ4dzEuqjXj0veV3 mM0Ps7UcRHjyxLuWIPPXscu4q0k2KyLbnxF1kLBQBw0jhOWQu+nriu03gJ5TlbgN2+on DDWylR01GlkRT79jUVljou+0xNoig4LzE8c/H77yLFX7NP5BKOPTNmNHDxIutcOhhOu5 14GIdtSL3wcWcWsgLspkM1hI4s+1mLnJpmpLXhcF0G8I0OL1M0S6WlxzvkPhO/Lwabn/ d9+A== MIME-Version: 1.0 X-Gm-Message-State: AGi0Pua8flHblco0bEYfwGX3dDQxY+XAjwUnrbRy1pe5f/ZXspdpVKj9 t3yMSZMhJz2urLAdiTDV8sGFiGpij+BqRJTjcEsRidKJWVcp+6D3FicgGlNeipoh9m1cg5dX X-Google-Smtp-Source: APiQypJtHlnC256ZDgLa/IyNt2x+ivkdvEN/jUbrK/liwgKFwX/GFvoKDo0kKv0ZmOyChvgNFcqDpg== X-Received: by 2002:a62:be19:: with SMTP id l25mr9123054pff.304.1587731930624; Fri, 24 Apr 2020 05:38:50 -0700 (PDT) Received: from 31_216.localdomain ([47.240.167.159]) by smtp.gmail.com with ESMTPSA id m6sm4863438pjo.5.2020.04.24.05.38.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 05:38: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 20:39:28 +0800 Message-Id: <20200424123928.3729-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 v4] 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 --- 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..2fea1bdb2 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, MADV_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.