From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout3.w1.samsung.com (mailout3.w1.samsung.com [210.118.77.13]) by dpdk.org (Postfix) with ESMTP id EB1B698; Thu, 16 Feb 2017 14:01:43 +0100 (CET) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OLG00IRXXITZ9A0@mailout3.w1.samsung.com>; Thu, 16 Feb 2017 13:01:41 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170216130140eucas1p2aca7346e80450015157099a73f07d04c~jxhY180C00510505105eucas1p2l; Thu, 16 Feb 2017 13:01:40 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges5.samsung.com (EUCPMTA) with SMTP id BD.88.17477.4B2A5A85; Thu, 16 Feb 2017 13:01:40 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170216130139eucas1p2512567d6f5db9eaac5ee840b56bf920a~jxhYIAPQz1767517675eucas1p2L; Thu, 16 Feb 2017 13:01:39 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d000004445-ba-58a5a2b46fc4 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 03.6B.06687.403A5A85; Thu, 16 Feb 2017 13:03:00 +0000 (GMT) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OLG00AOCXI43N00@eusync3.samsung.com>; Thu, 16 Feb 2017 13:01:39 +0000 (GMT) From: Ilya Maximets To: dev@dpdk.org, David Marchand , Sergio Gonzalez Monroy Cc: Heetae Ahn , Yuanhan Liu , Jianfeng Tan , Neil Horman , Yulong Pei , Ilya Maximets , stable@dpdk.org Date: Thu, 16 Feb 2017 16:01:10 +0300 Message-id: <1487250070-13973-1-git-send-email-i.maximets@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRmVeSWpSXmKPExsWy7djP87pbFi2NMOj9L2axoqOdxeLdp+1M FtM+32a3uNL+k92ie/YXNotbzSfZLFZMOMJo8a/jD7vF9QkXWC2+PfjO7MDlcbH/DqPHrwVL WT0W73nJ5DHvZKBH35ZVjB5Xvq9mDGCL4rJJSc3JLEst0rdL4MrY0tPLUnDdsOLvm5WMDYy/ 1bsYOTkkBEwklv1+wQphi0lcuLeerYuRi0NIYCmjxI6mJ1DOZ0aJ02s3s8B0HP29gBEisYxR YuGCVUwQTjOTxJXe/UwgVWwCOhKnVh9hBLFFBCokGjpXs4AUMQs0MUmce97NBpIQFjCTuHdz O1gRi4CqxM6rh9hBbF4BN4m/2zZDHSUncfNcJzNIs4TAZzaJHdfOAxVxADmyEpsOMEPUuEhs +TCNDcIWlnh1fAs7hC0j0dlxkAnCrpaYuLWNHWJOC9DZE39ALbCXOHXzKlgRswCfxKRt05kh 5vNKdLQJQZR4SBzasBRqvqPE4/O9YPOFBGIlTp3ZzT6BUXoBI8MqRpHU0uLc9NRiU73ixNzi 0rx0veT83E2MwJg+/e/41x2MS49ZHWIU4GBU4uF9kbokQog1say4MvcQowQHs5IIr+f8pRFC vCmJlVWpRfnxRaU5qcWHGKU5WJTEefcsuBIuJJCeWJKanZpakFoEk2Xi4JRqYPTvPFOneV72 ywK+9dbJuemJdy5pbzywS2Ziy/wPxtkcOyW+V0+J87qSMnmhWJyn4Zmj371/KAe+vVljtUZC +8SpzEkdVyyv9d+Qu2pRoGdmZ2EmNePU53sXLls5vvNrmmaqx8XO+sSSOb/hfbzOUd53mQWz zu41bfE2C/7j07d+3WZjTrfVn5VYijMSDbWYi4oTAY0SN5rlAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRmVeSWpSXmKPExsVy+t/xq7osi5dGGHzYr2axoqOdxeLdp+1M FtM+32a3uNL+k92ie/YXNotbzSfZLFZMOMJo8a/jD7vF9QkXWC2+PfjO7MDlcbH/DqPHrwVL WT0W73nJ5DHvZKBH35ZVjB5Xvq9mDGCLcrPJSE1MSS1SSM1Lzk/JzEu3VQoNcdO1UFLIS8xN tVWK0PUNCVJSKEvMKQXyjAzQgINzgHuwkr5dglvGlp5eloLrhhV/36xkbGD8rd7FyMkhIWAi cfT3AkYIW0ziwr31bCC2kMASRomlzbpdjFxAdiuTxK0f/UwgCTYBHYlTq4+ANYgIVEhMe72S DaSIWaCFSaLp3np2kISwgJnEvZvbwYpYBFQldl49BBbnFXCT+LttMyvENjmJm+c6mScwci9g ZFjFKJJaWpybnltsqFecmFtcmpeul5yfu4kRGMTbjv3cvIPx0sbgQ4wCHIxKPLwvUpdECLEm lhVX5h5ilOBgVhLh9Zy/NEKINyWxsiq1KD++qDQntfgQoynQ8onMUqLJ+cAIyyuJNzQxNLc0 NDK2sDA3MlIS5y35cCVcSCA9sSQ1OzW1ILUIpo+Jg1OqgZFF2uWuA4/adu7YS5W8AbMOne9O tdWcIn5alnX327zXG+UumthEb7hkKyd8St4ybW5EV8ESdcdZu3dpiwoGGkxo3aHcrNPU1B+7 /1VsRiaP4Y8PTZ9kLic/VRB1c2zx9nBYybw5p2Cm3iL9XbLfp64S+mcXuWpi6A2OR73adjuf 7ZC8z2t6WImlOCPRUIu5qDgRAPCSI8R4AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170216130139eucas1p2512567d6f5db9eaac5ee840b56bf920a X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?SWx5YSBNYXhpbWV0cxtTUlItVmlydHVhbGl6YXRpb24gTGFi?= =?UTF-8?B?G+yCvOyEseyghOyekBtFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?SWx5YSBNYXhpbWV0cxtTUlItVmlydHVhbGl6YXRpb24gTGFi?= =?UTF-8?B?G1NhbXN1bmcgRWxlY3Ryb25pY3MbRW5naW5lZXI=?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170216130139eucas1p2512567d6f5db9eaac5ee840b56bf920a X-RootMTR: 20170216130139eucas1p2512567d6f5db9eaac5ee840b56bf920a References: Subject: [dpdk-stable] [PATCH] mem: balanced allocation of hugepages X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Feb 2017 13:01:44 -0000 Currently EAL allocates hugepages one by one not paying attention from which NUMA node allocation was done. Such behaviour leads to allocation failure if number of available hugepages for application limited by cgroups or hugetlbfs and memory requested not only from the first socket. Example: # 90 x 1GB hugepages availavle in a system cgcreate -g hugetlb:/test # Limit to 32GB of hugepages cgset -r hugetlb.1GB.limit_in_bytes=34359738368 test # Request 4GB from each of 2 sockets cgexec -g hugetlb:test testpmd --socket-mem=4096,4096 ... EAL: SIGBUS: Cannot mmap more hugepages of size 1024 MB EAL: 32 not 90 hugepages of size 1024 MB allocated EAL: Not enough memory available on socket 1! Requested: 4096MB, available: 0MB PANIC in rte_eal_init(): Cannot init memory This happens beacause all allocated pages are on socket 0. Fix this issue by setting mempolicy MPOL_PREFERRED for each hugepage to one of requested nodes in a round-robin fashion. In this case all allocated pages will be fairly distributed between all requested nodes. New config option RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES introduced and disabled by default because of external dependency from libnuma. Cc: Fixes: 77988fc08dc5 ("mem: fix allocating all free hugepages") Signed-off-by: Ilya Maximets --- config/common_base | 1 + lib/librte_eal/Makefile | 4 ++ lib/librte_eal/linuxapp/eal/eal_memory.c | 66 ++++++++++++++++++++++++++++++++ mk/rte.app.mk | 3 ++ 4 files changed, 74 insertions(+) diff --git a/config/common_base b/config/common_base index 71a4fcb..fbcebbd 100644 --- a/config/common_base +++ b/config/common_base @@ -97,6 +97,7 @@ CONFIG_RTE_EAL_ALWAYS_PANIC_ON_ERROR=n CONFIG_RTE_EAL_IGB_UIO=n CONFIG_RTE_EAL_VFIO=n CONFIG_RTE_MALLOC_DEBUG=n +CONFIG_RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES=n # Default driver path (or "" to disable) CONFIG_RTE_EAL_PMD_PATH="" diff --git a/lib/librte_eal/Makefile b/lib/librte_eal/Makefile index cf11a09..5ae3846 100644 --- a/lib/librte_eal/Makefile +++ b/lib/librte_eal/Makefile @@ -35,4 +35,8 @@ DIRS-y += common DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += linuxapp DIRS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += bsdapp +ifeq ($(CONFIG_RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES),y) +LDLIBS += -lnuma +endif + include $(RTE_SDK)/mk/rte.subdir.mk diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index a956bb2..8536a36 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -82,6 +82,9 @@ #include #include #include +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES +#include +#endif #include #include @@ -359,6 +362,21 @@ static int huge_wrap_sigsetjmp(void) return sigsetjmp(huge_jmpenv, 1); } +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES +#ifndef ULONG_SIZE +#define ULONG_SIZE sizeof(unsigned long) +#endif +#ifndef ULONG_BITS +#define ULONG_BITS (ULONG_SIZE * CHAR_BIT) +#endif +#ifndef DIV_ROUND_UP +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#endif +#ifndef BITS_TO_LONGS +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, ULONG_SIZE) +#endif +#endif + /* * Mmap all hugepages of hugepage table: it first open a file in * hugetlbfs, then mmap() hugepage_sz data in it. If orig is set, the @@ -375,10 +393,48 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, void *virtaddr; void *vma_addr = NULL; size_t vma_len = 0; +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES + unsigned long nodemask[BITS_TO_LONGS(RTE_MAX_NUMA_NODES)] = {0UL}; + unsigned long maxnode = 0; + int node_id = -1; + + for (i = 0; i < RTE_MAX_NUMA_NODES; i++) + if (internal_config.socket_mem[i]) + maxnode = i + 1; +#endif for (i = 0; i < hpi->num_pages[0]; i++) { uint64_t hugepage_sz = hpi->hugepage_sz; +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES + if (maxnode) { + node_id = (node_id + 1) % RTE_MAX_NUMA_NODES; + while (!internal_config.socket_mem[node_id]) + node_id = (node_id + 1) % RTE_MAX_NUMA_NODES; + + nodemask[node_id / ULONG_BITS] = + 1UL << (node_id % ULONG_BITS); + + RTE_LOG(DEBUG, EAL, + "Setting policy MPOL_PREFERRED for socket %d\n", + node_id); + /* + * Due to old linux kernel bug (feature?) we have to + * increase maxnode by 1. It will be unconditionally + * decreased back to normal value inside the syscall + * handler. + */ + if (set_mempolicy(MPOL_PREFERRED, + nodemask, maxnode + 1) < 0) { + RTE_LOG(ERR, EAL, + "Failed to set policy MPOL_PREFERRED: " + "%s\n", strerror(errno)); + return i; + } + + nodemask[node_id / ULONG_BITS] = 0UL; + } +#endif if (orig) { hugepg_tbl[i].file_id = i; hugepg_tbl[i].size = hugepage_sz; @@ -489,6 +545,10 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, vma_len -= hugepage_sz; } +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES + if (maxnode && set_mempolicy(MPOL_DEFAULT, NULL, 0) < 0) + RTE_LOG(ERR, EAL, "Failed to set mempolicy MPOL_DEFAULT\n"); +#endif return i; } @@ -573,6 +634,11 @@ find_numasocket(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi) if (hugepg_tbl[i].orig_va == va) { hugepg_tbl[i].socket_id = socket_id; hp_count++; +#ifdef RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES + RTE_LOG(DEBUG, EAL, + "Hugepage %s is on socket %d\n", + hugepg_tbl[i].filepath, socket_id); +#endif } } } diff --git a/mk/rte.app.mk b/mk/rte.app.mk index 92f3635..c2153b9 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -159,6 +159,9 @@ ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),n) # The static libraries do not know their dependencies. # So linking with static library requires explicit dependencies. _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrt +ifeq ($(CONFIG_RTE_LIBRTE_EAL_NUMA_AWARE_HUGEPAGES),y) +_LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lnuma +endif _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lm _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lrt _LDLIBS-$(CONFIG_RTE_LIBRTE_METER) += -lm -- 2.7.4