From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 4E89F4CA1 for ; Fri, 1 Jun 2018 11:17:37 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jun 2018 02:17:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,465,1520924400"; d="scan'208";a="52616246" Received: from kraken.imu.intel.com (HELO Sent) ([10.217.246.153]) by fmsmga002.fm.intel.com with SMTP; 01 Jun 2018 02:17:34 -0700 Received: by Sent (sSMTP sendmail emulation); Fri, 01 Jun 2018 15:00:34 +0200 From: Dariusz Stojaczyk To: dev@dpdk.org, Anatoly Burakov Cc: Dariusz Stojaczyk Date: Fri, 1 Jun 2018 14:51:09 +0200 Message-Id: <1527857469-159391-2-git-send-email-dariuszx.stojaczyk@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527857469-159391-1-git-send-email-dariuszx.stojaczyk@intel.com> References: <1527857469-159391-1-git-send-email-dariuszx.stojaczyk@intel.com> Subject: [dpdk-dev] [PATCH 2/2] memalloc: keep in mind a failed MAP_FIXED mmap may still perform an unmap 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: , X-List-Received-Date: Fri, 01 Jun 2018 09:17:37 -0000 This isn't documented in the manuals, but a failed mmap(..., MAP_FIXED) may still unmap overlapping regions. In such case, we need to remap these regions back into our address space to ensure mem contiguity. We do it unconditionally now on mmap failure just to be safe. Verified on Linux 4.9.0-4-amd64. I was getting ENOMEM when trying to map in hugetlbfs with no space left, but the previous anonymous mapping was still being removed. Signed-off-by: Dariusz Stojaczyk --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index b959ea5..e59ad6e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -527,7 +527,13 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, if (va == MAP_FAILED) { RTE_LOG(DEBUG, EAL, "%s(): mmap() failed: %s\n", __func__, strerror(errno)); - goto resized; + if (errno == ENOMEM) { + /* mmap failed, but the previous region might have + * been unmapped anyway; try to remap it */ + goto unmapped; + } else { + goto resized; + } } if (va != addr) { RTE_LOG(DEBUG, EAL, "%s(): wrong mmap() address\n", __func__); @@ -588,6 +594,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id, mapped: munmap(addr, alloc_sz); +unmapped: flags = MAP_FIXED; #ifdef RTE_ARCH_PPC_64 flags |= MAP_HUGETLB; -- 2.7.4