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 1A6A1A00C2; Fri, 24 Apr 2020 14:53:04 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 790A51C222; Fri, 24 Apr 2020 14:53:03 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 29F751C209 for ; Fri, 24 Apr 2020 14:53:01 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id d184so4762233pfd.4 for ; Fri, 24 Apr 2020 05:53:01 -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=Pn3PPizjcesVRxgAx7tZCW+5akxPqPT8RgNe+l1JqE8=; b=YtfXQM3timIJmXj/mEo7FRDt8qunozdKdK53YtdQGfJqRihYAietv0nAwKGFaLj7gD gCmRZ9k/D+HJ4Kpfj9XrIoE2HK4r4YCkO1nhzY/R2hPcrVI3SD9BjXHqjE+806qwpmYI ft7LVeuxUjOUDzYFmYuUmZi2NTNZxeUkik0brUw7RaE6KRk9jsdcGU3vCA4d5o3yeJfP imj02ytU9Z1W4FUB0TIyoHFR/NxsYOjy7YA3fBNpjwqm8zS9XZdH1yg/kJQJQZ1RIa01 uJeBEsP5MLNEMmenez0QFuaWwgRPLWJ1tE347GFBQnWTg6ws6ZLIjkn9paRgxsqMQSNB 6b9w== 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=Pn3PPizjcesVRxgAx7tZCW+5akxPqPT8RgNe+l1JqE8=; b=i1usPZ5z3+cryqLaSh+kBegIs6i1NKaiWkwpGNY+mJbI8DoMV2Z5nRz9mlM5K5AbgW 4rNjJGyrseDwdMbhppmkJyj+h8OgkqjSjg6WuJ+w852I68+1Odbue6xInYULMDeP4rgY bJg+f4JR3RJser32AsTqr6FZq/k3TGzQoXkeuQiohF/QAv62jNptLYn85z71QZt1n3H0 AK/AQtnBlvZZEphey9JlvyWwm8VFcaPWPO/pIdAM3HcZ1Kv+pkBTC1eGcQi15ItnJGQZ eaaMzriPCs6wudU92V1UZEf+GOIgOGLKXG+8VBbM9WdJ1f4hHM4Xt6kM54TvKulhi1/U 7ftA== MIME-Version: 1.0 X-Gm-Message-State: AGi0PuYqO4/ashKNbn1duSwcBfTx0RJPAUgySCDy7qCaRPo4pUV+xw6l BPprzPsdr8MiKBi3ihXLWu+qPhZKLlWLjCtPTpfFR3JCBgLUd2ptruWvDeZstI4fTQzfdmfP X-Google-Smtp-Source: APiQypJJBwkSmeoQsErtVBu8wu7f7CxY6CUKv4GKGJ/7svDxaUJjV4o2J+wQPxSUvovXG5qZPnkEbQ== X-Received: by 2002:a63:1a52:: with SMTP id a18mr9347812pgm.422.1587732780192; Fri, 24 Apr 2020 05:53:00 -0700 (PDT) Received: from 31_216.localdomain (nz132l98.bb27109.ctm.net. [27.109.132.98]) by smtp.gmail.com with ESMTPSA id l1sm2151455pgn.66.2020.04.24.05.52.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 05:52:59 -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:53:11 +0800 Message-Id: <20200424125311.25364-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 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" 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/com= mon/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; =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.