From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 328FBA0A02 for ; Mon, 17 May 2021 18:13:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A5D8410E0; Mon, 17 May 2021 18:13:43 +0200 (CEST) Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by mails.dpdk.org (Postfix) with ESMTP id 21BEE410E0 for ; Mon, 17 May 2021 18:13:42 +0200 (CEST) Received: from 2.general.paelzer.uk.vpn ([10.172.196.173] helo=Keschdeichel.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lifsD-0007yH-Ag; Mon, 17 May 2021 16:13:41 +0000 From: Christian Ehrhardt To: Roy Shterman Cc: Anatoly Burakov , dpdk stable Date: Mon, 17 May 2021 18:08:28 +0200 Message-Id: <20210517161039.3132619-79-christian.ehrhardt@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517161039.3132619-1-christian.ehrhardt@canonical.com> References: <20210517161039.3132619-1-christian.ehrhardt@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'mem: fix freeing segments in --huge-unlink mode' has been queued to stable release 19.11.9 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 19.11.9 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/19/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/cpaelzer/dpdk-stable-queue This queued commit can be viewed at: https://github.com/cpaelzer/dpdk-stable-queue/commit/39b93e36e566816d84911c05acf049fb0c566157 Thanks. Christian Ehrhardt --- >From 39b93e36e566816d84911c05acf049fb0c566157 Mon Sep 17 00:00:00 2001 From: Roy Shterman Date: Mon, 22 Feb 2021 12:41:31 +0200 Subject: [PATCH] mem: fix freeing segments in --huge-unlink mode [ upstream commit edf20bd8a55192616e4a0f26c346b55ddbac1d81 ] When using huge_unlink we unlink the segment right after allocation. Although we unlink the file we keep the fd in fd_list so file still exist just the path deleted. When freeing the hugepage we need to close the fd and assign it with (-1) in fd_list for the page to be released. The current flow fails rte_malloc in the following flow when working with --huge-unlink option: 1. alloc_seg() for segment A - We allocate a segment, unlink the path to the segment and keep the file descriptor in fd_list. 2. free_seg() for segment A - We clear the segment metadata and return - without closing fd or assigning (-1) in fd list. 3. alloc_seg() for segment A again - We find segment A as available, try to allocate it, find the old fd in fd_list try to unlink it as part of alloc_seg() but failed because path doesn't exist. The impact of such error is falsely failing rte_malloc() although we have hugepages available. Fixes: d435aad37da7 ("mem: support --huge-unlink mode") Signed-off-by: Roy Shterman Acked-by: Anatoly Burakov --- lib/librte_eal/linux/eal/eal_memalloc.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c index 22f1ff68eb..e8b2daa66a 100644 --- a/lib/librte_eal/linux/eal/eal_memalloc.c +++ b/lib/librte_eal/linux/eal/eal_memalloc.c @@ -698,7 +698,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, uint64_t map_offset; char path[PATH_MAX]; int fd, ret = 0; - bool exit_early; /* erase page data */ memset(ms->addr, 0, ms->len); @@ -713,17 +712,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, if (madvise(ms->addr, ms->len, MADV_DONTDUMP) != 0) RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", strerror(errno)); - exit_early = false; - /* if we're using anonymous hugepages, nothing to be done */ - if (internal_config.in_memory && !memfd_create_supported) - exit_early = true; - - /* if we've already unlinked the page, nothing needs to be done */ - if (!internal_config.in_memory && internal_config.hugepage_unlink) - exit_early = true; - - if (exit_early) { + if (internal_config.in_memory && !memfd_create_supported) { memset(ms, 0, sizeof(*ms)); return 0; } @@ -749,7 +739,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, /* if we're able to take out a write lock, we're the last one * holding onto this page. */ - if (!internal_config.in_memory) { + if (!internal_config.in_memory && !internal_config.hugepage_unlink) { ret = lock(fd, LOCK_EX); if (ret >= 0) { /* no one else is using this page */ -- 2.31.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-05-17 17:40:32.595603438 +0200 +++ 0079-mem-fix-freeing-segments-in-huge-unlink-mode.patch 2021-05-17 17:40:29.243810043 +0200 @@ -1 +1 @@ -From edf20bd8a55192616e4a0f26c346b55ddbac1d81 Mon Sep 17 00:00:00 2001 +From 39b93e36e566816d84911c05acf049fb0c566157 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit edf20bd8a55192616e4a0f26c346b55ddbac1d81 ] + @@ -29 +30,0 @@ -Cc: stable@dpdk.org @@ -34 +35 @@ - lib/librte_eal/linux/eal_memalloc.c | 14 ++------------ + lib/librte_eal/linux/eal/eal_memalloc.c | 14 ++------------ @@ -37,5 +38,5 @@ -diff --git a/lib/librte_eal/linux/eal_memalloc.c b/lib/librte_eal/linux/eal_memalloc.c -index 00e2662c15..0ec8542283 100644 ---- a/lib/librte_eal/linux/eal_memalloc.c -+++ b/lib/librte_eal/linux/eal_memalloc.c -@@ -709,7 +709,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, +diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c +index 22f1ff68eb..e8b2daa66a 100644 +--- a/lib/librte_eal/linux/eal/eal_memalloc.c ++++ b/lib/librte_eal/linux/eal/eal_memalloc.c +@@ -698,7 +698,6 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, @@ -46,4 +46,0 @@ - const struct internal_config *internal_conf = - eal_get_internal_configuration(); - -@@ -725,17 +724,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, @@ -51 +48,5 @@ - eal_mem_set_dump(ms->addr, ms->len, false); + /* erase page data */ + memset(ms->addr, 0, ms->len); +@@ -713,17 +712,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, + if (madvise(ms->addr, ms->len, MADV_DONTDUMP) != 0) + RTE_LOG(DEBUG, EAL, "madvise failed: %s\n", strerror(errno)); @@ -56 +57 @@ -- if (internal_conf->in_memory && !memfd_create_supported) +- if (internal_config.in_memory && !memfd_create_supported) @@ -60 +61 @@ -- if (!internal_conf->in_memory && internal_conf->hugepage_unlink) +- if (!internal_config.in_memory && internal_config.hugepage_unlink) @@ -64 +65 @@ -+ if (internal_conf->in_memory && !memfd_create_supported) { ++ if (internal_config.in_memory && !memfd_create_supported) { @@ -68 +69 @@ -@@ -761,7 +751,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, +@@ -749,7 +739,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi, @@ -72,2 +73,2 @@ -- if (!internal_conf->in_memory) { -+ if (!internal_conf->in_memory && !internal_conf->hugepage_unlink) { +- if (!internal_config.in_memory) { ++ if (!internal_config.in_memory && !internal_config.hugepage_unlink) {