From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 157D52A66 for ; Thu, 3 May 2018 12:11:30 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 03:11:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="52053033" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 03 May 2018 03:11:28 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w43ABRoh021990; Thu, 3 May 2018 11:11:27 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w43ABRgW025750; Thu, 3 May 2018 11:11:27 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w43ABRFd025746; Thu, 3 May 2018 11:11:27 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: yong.liu@intel.com, anatoly.burakov@intel.com Date: Thu, 3 May 2018 11:11:27 +0100 Message-Id: <88ac531b5b13288971edcee16785c8cc612bdfe0.1525342009.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <556d606e3af8ab32e920611d166a0154e472fe25.1525342009.git.anatoly.burakov@intel.com> References: <556d606e3af8ab32e920611d166a0154e472fe25.1525342009.git.anatoly.burakov@intel.com> In-Reply-To: <556d606e3af8ab32e920611d166a0154e472fe25.1525342009.git.anatoly.burakov@intel.com> References: <556d606e3af8ab32e920611d166a0154e472fe25.1525342009.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 3/3] memalloc: fix unmapping and marking segments as free 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: Thu, 03 May 2018 10:11:31 -0000 Currently, page deallocation might fail if allocator cannot get page fd, which will leave VA space still mapped, and will also not mark page as free. Fix page deallocation function to always unmap space before trying to get rid of the page itself, and always mark page as free even if page deallocation failed. Fixes: a5ff05d60fc5 ("mem: support unmapping pages at runtime") Fixes: 1a7dc2252f28 ("mem: revert to using flock and add per-segment lockfiles") Cc: anatoly.burakov@intel.com Signed-off-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index 3282293..c1a0211 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -610,14 +610,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, /* erase page data */ memset(ms->addr, 0, ms->len); - /* if we are not in single file segments mode, we're going to unmap the - * segment and thus drop the lock on original fd, so take out another - * shared lock before we do that. - */ - fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx); - if (fd < 0) - return -1; - if (mmap(ms->addr, ms->len, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) { @@ -625,6 +617,14 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, return -1; } + /* if we are not in single file segments mode, we're going to unmap the + * segment and thus drop the lock on original fd, but hugepage dir is + * now locked so we can take out another one without races. + */ + fd = get_seg_fd(path, sizeof(path), hi, list_idx, seg_idx); + if (fd < 0) + return -1; + if (internal_config.single_file_segments) { map_offset = seg_idx * ms->len; if (resize_hugefile(fd, path, list_idx, seg_idx, map_offset, @@ -735,12 +735,13 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg) &cur_msl->memseg_arr; tmp = rte_fbarray_get(arr, j); - if (free_seg(tmp, wa->hi, msl_idx, j)) { - RTE_LOG(ERR, EAL, "Cannot free page\n"); - continue; - } - rte_fbarray_set_free(arr, j); + + /* free_seg may attempt to create a file, which + * may fail. + */ + if (free_seg(tmp, wa->hi, msl_idx, j)) + RTE_LOG(DEBUG, EAL, "Cannot free page\n"); } /* clear the list */ if (wa->ms) -- 2.7.4