From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 38DD99205 for ; Thu, 12 Nov 2015 14:14:51 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 12 Nov 2015 05:14:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,281,1444719600"; d="scan'208";a="818196335" Received: from smonroyx-mobl.ger.corp.intel.com (HELO [10.237.221.47]) ([10.237.221.47]) by orsmga001.jf.intel.com with ESMTP; 12 Nov 2015 05:14:38 -0800 To: Jianfeng Tan , dev@dpdk.org References: <1447287477-49292-1-git-send-email-jianfeng.tan@intel.com> <1447294255-69446-1-git-send-email-jianfeng.tan@intel.com> From: Sergio Gonzalez Monroy Message-ID: <564490BE.9000300@intel.com> Date: Thu, 12 Nov 2015 13:14:38 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1447294255-69446-1-git-send-email-jianfeng.tan@intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2] mem: calculate space left in a hugetlbfs 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: Thu, 12 Nov 2015 13:14:52 -0000 Hi, On 12/11/2015 02:10, Jianfeng Tan wrote: > This patch enables calculating space left in a hugetlbfs. > There are three sources to get the information: 1. from > sysfs; 2. from option size specified when mount; 3. use > statfs. We should use the minimum one of these three sizes. We could improve the message by stating the current issue (when the hugetlbfs mount specifies size= option), then how the patch deals with the problem and also outstanding issues. > Signed-off-by: Jianfeng Tan > --- > Changes in v2: > - reword title > - fix compiler error of v1 > > lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 85 ++++++++++++++++++++++++- > 1 file changed, 84 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c > index 18858e2..8305a58 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c > +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c > @@ -44,6 +44,8 @@ > #include > #include > #include > +#include > +#include > > #include > #include > @@ -189,6 +191,70 @@ get_hugepage_dir(uint64_t hugepage_sz) > return retval; > } > > +/* Caller to make sure this mnt_dir exist > + */ > +static uint64_t > +get_hugetlbfs_mount_size(const char *mnt_dir) > +{ > + char *start, *end, *opt_size; > + struct mntent *ent; > + uint64_t size; > + FILE *f; > + int len; > + > + f = setmntent("/proc/mounts", "r"); > + if (f == NULL) { > + RTE_LOG(ERR, EAL, "setmntent() error: %s\n", > + strerror(errno)); > + return 0; > + } > + while (NULL != (ent = getmntent(f))) { > + if (!strcmp(ent->mnt_dir, mnt_dir)) > + break; > + } > + > + start = hasmntopt(ent, "size"); > + if (start == NULL) { > + RTE_LOG(DEBUG, EAL, "option size not specified for %s\n", > + mnt_dir); > + size = 0; > + goto end; > + } > + start += strlen("size="); > + end = strstr(start, ","); > + if (end != NULL) > + len = end - start; > + else > + len = strlen(start); > + opt_size = strndup(start, len); > + size = rte_str_to_size(opt_size); > + free(opt_size); > + > +end: > + endmntent(f); > + return size; > +} > + The function above is very similar to get_hugepage_dir, ie. open and parse /proc/mounts. I think it would be better to have a more generic function that retrieves all needed info from /proc/mounts. > +/* Caller to make sure this mount has option size > + * so that statfs is not zero. > + */ > +static uint64_t > +get_hugetlbfs_free_size(const char *mnt_dir) > +{ > + int r; > + struct statfs stats; > + > + r = statfs(mnt_dir, &stats); > + if (r != 0) { > + RTE_LOG(ERR, EAL, "statfs() error: %s\n", > + strerror(errno)); > + return 0; > + } > + > + return stats.f_bfree * stats.f_bsize; > +} > + > + > /* > * Clear the hugepage directory of whatever hugepage files > * there are. Checks if the file is locked (i.e. > @@ -329,9 +395,26 @@ eal_hugepage_info_init(void) > if (clear_hugedir(hpi->hugedir) == -1) > break; > > + /* there are three souces of how much space left in a > + * hugetlbfs dir. > + */ > + uint64_t sz_left, sz_sysfs, sz_option, sz_statfs; > + > + sz_sysfs = get_num_hugepages(dirent->d_name) * > + hpi->hugepage_sz; > + sz_left = sz_sysfs; > + sz_option = get_hugetlbfs_mount_size(hpi->hugedir); > + if (sz_option) { > + sz_statfs = get_hugetlbfs_free_size(hpi->hugedir); > + sz_left = RTE_MIN(sz_sysfs, sz_statfs); > + RTE_LOG(INFO, EAL, "sz_sysfs: %"PRIu64", sz_option: " > + "%"PRIu64", sz_statfs: %"PRIu64"\n", > + sz_sysfs, sz_option, sz_statfs); > + } > + > /* for now, put all pages into socket 0, > * later they will be sorted */ > - hpi->num_pages[0] = get_num_hugepages(dirent->d_name); > + hpi->num_pages[0] = sz_left / hpi->hugepage_sz; > > #ifndef RTE_ARCH_64 > /* for 32-bit systems, limit number of hugepages to A couple more things: - Update release-notes and/or relevant doc about improved detection of free hugepages - Update the status of previous/old patches in patchwork Sergio