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 ED7B5591A for ; Fri, 28 Aug 2015 14:39:41 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 28 Aug 2015 05:39:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,424,1437462000"; d="scan'208,217";a="792710884" Received: from kmsmsx153.gar.corp.intel.com ([172.21.73.88]) by orsmga002.jf.intel.com with ESMTP; 28 Aug 2015 05:39:39 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by KMSMSX153.gar.corp.intel.com (172.21.73.88) with Microsoft SMTP Server (TLS) id 14.3.224.2; Fri, 28 Aug 2015 20:39:38 +0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.248]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.171]) with mapi id 14.03.0224.002; Fri, 28 Aug 2015 20:39:37 +0800 From: "Tan, Jianfeng" To: "Gonzalez Monroy, Sergio" , "dev@dpdk.org" Thread-Topic: Hugetlbfs mounted with size option leads to mmap failure Thread-Index: AdDhjck8rolyRHCcRPiDqOd1CRpXFQ== Date: Fri, 28 Aug 2015 12:39:36 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] Hugetlbfs mounted with size option leads to mmap failure X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2015 12:39:42 -0000 Hi Monroy, As hugetlbfs mounted with option "size=3Dxxx", and xxx is smaller than that= from /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages, error is raised like, EAL: map_all_hugepages(): mmap failed: Cannot allocate memory. Although this can be avoided by the parameter of "--sock-mem=3D", I wrote a= patch to rectify num_pages. Any comments would be highly appreciated. diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_e= al/linuxapp/eal/eal_hugepage_info.c index 18858e2..db6a4d5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -124,6 +125,50 @@ get_default_hp_size(void) return size; } +static uint64_t +get_hugepages_mount_size(const char *mnt_dir) +{ + char *start, *end, *opt_size; + struct mntent *ent; + uint64_t size; + FILE *f; + int len; + + f =3D setmntent("/proc/mounts", "r"); + if (f =3D=3D NULL) { + RTE_LOG(ERR, EAL, "setmntent() error: %s\n", strerror(errno= )); + return 0; + } + while (NULL !=3D (ent =3D getmntent(f))) { + if (! strcmp(ent->mnt_dir, mnt_dir)) { + break; + } + } + if (ent =3D=3D NULL) { + RTE_LOG(ERR, EAL, "no hugetlbfs found at %s\n", mnt_dir); + return 0; + } + + start =3D hasmntopt(ent, "size"); + if (start =3D=3D NULL) { + RTE_LOG(DEBUG, EAL, "option size not specified for %s\n", m= nt_dir); + return 0; + } + start +=3D strlen("size=3D"); + end =3D strstr(start, ","); + if (end !=3D NULL) { + len =3D end - start; + } else { + len =3D strlen(start); + } + opt_size =3D strndup(start, len); + size =3D rte_str_to_size(opt_size); + free(opt_size); + + endmntent(f); + return size; +} + static const char * get_hugepage_dir(uint64_t hugepage_sz) { @@ -333,6 +378,17 @@ eal_hugepage_info_init(void) * later they will be sorted */ hpi->num_pages[0] =3D get_num_hugepages(dirent->d_name); + /* if mount_size < total_hugepages*hugepagesz correct it */ + + uint64_t size, num; + size =3D get_hugepages_mount_size(hpi->hugedir); + if (size !=3D 0) { + num =3D size / hpi->hugepage_sz; + + if (num < hpi->num_pages[0]) + hpi->num_pages[0] =3D num; + } + #ifndef RTE_ARCH_64 /* for 32-bit systems, limit number of hugepages to * 1GB per page size */ Thanks, Jianfeng