[dpdk-dev,v2,01/13] EAL: count nr_overcommit_hugepages as available

Message ID 3da244231b6868ccc3e70d91dc277df39a3695bd.1481592081.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Michał Mirosław Dec. 13, 2016, 1:28 a.m. UTC
  Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
---
 lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 43 ++++++++++++++++++-------
 1 file changed, 32 insertions(+), 11 deletions(-)
  

Comments

Thomas Monjalon April 30, 2017, 3:53 p.m. UTC | #1
13/12/2016 02:28, Michał Mirosław:
> Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
> ---
>  lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 43 ++++++++++++++++++-------
>  1 file changed, 32 insertions(+), 11 deletions(-)

There is neither explanation nor comments for this patch.
Michal, please check with Sergio (mem maintainer) what can be done.
  
Michał Mirosław May 4, 2017, 6:43 p.m. UTC | #2
On Sun, Apr 30, 2017 at 05:53:55PM +0200, Thomas Monjalon wrote:
> 13/12/2016 02:28, Michał Mirosław:
> > Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
> > ---
> >  lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 43 ++++++++++++++++++-------
> >  1 file changed, 32 insertions(+), 11 deletions(-)
> There is neither explanation nor comments for this patch.
> Michal, please check with Sergio (mem maintainer) what can be done.

I think the patch needs to be rebased and verified on new version. I won't
be able to come back to this in next two weeks, but if you have any comments,
please send them in.

Best Regards,
Michał Mirosław
  
Ferruh Yigit Jan. 17, 2019, 5:18 p.m. UTC | #3
On 5/4/2017 7:43 PM, mirq-linux at rere.qmqm.pl (Michał Mirosław) wrote:
> On Sun, Apr 30, 2017 at 05:53:55PM +0200, Thomas Monjalon wrote:
>> 13/12/2016 02:28, Micha? Miros?aw:
>>> Signed-off-by: Micha? Miros?aw <michal.miroslaw at atendesoftware.pl>
>>> ---
>>>  lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 43 ++++++++++++++++++-------
>>>  1 file changed, 32 insertions(+), 11 deletions(-)
>> There is neither explanation nor comments for this patch.
>> Michal, please check with Sergio (mem maintainer) what can be done.
> 
> I think the patch needs to be rebased and verified on new version. I won't
> be able to come back to this in next two weeks, but if you have any comments,
> please send them in.

Hi Michal,

This patch is waiting for an update for a long time, I am updating it's status
as "Change Requested", if this is still relevant please sent a patch on top of
latest repo.

For reference, patch: https://patches.dpdk.org/patch/17888/

Thanks,
ferruh
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
index 18858e2..b68f060 100644
--- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
+++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c
@@ -61,30 +61,38 @@ 
 
 static const char sys_dir_path[] = "/sys/kernel/mm/hugepages";
 
+static int get_hp_sysfs_value(const char *subdir, const char *file, unsigned long *val)
+{
+	char path[PATH_MAX];
+
+	snprintf(path, sizeof(path), "%s/%s/%s",
+			sys_dir_path, subdir, file);
+	return eal_parse_sysfs_value(path, val);
+}
+
 /* this function is only called from eal_hugepage_info_init which itself
  * is only called from a primary process */
 static uint32_t
 get_num_hugepages(const char *subdir)
 {
-	char path[PATH_MAX];
-	long unsigned resv_pages, num_pages = 0;
+	unsigned long resv_pages, num_pages, over_pages, surplus_pages;
 	const char *nr_hp_file = "free_hugepages";
 	const char *nr_rsvd_file = "resv_hugepages";
+	const char *nr_over_file = "nr_overcommit_hugepages";
+	const char *nr_splus_file = "surplus_hugepages";
 
 	/* first, check how many reserved pages kernel reports */
-	snprintf(path, sizeof(path), "%s/%s/%s",
-			sys_dir_path, subdir, nr_rsvd_file);
-	if (eal_parse_sysfs_value(path, &resv_pages) < 0)
+	if (get_hp_sysfs_value(subdir, nr_rsvd_file, &resv_pages) < 0)
 		return 0;
 
-	snprintf(path, sizeof(path), "%s/%s/%s",
-			sys_dir_path, subdir, nr_hp_file);
-	if (eal_parse_sysfs_value(path, &num_pages) < 0)
+	if (get_hp_sysfs_value(subdir, nr_hp_file, &num_pages) < 0)
 		return 0;
 
-	if (num_pages == 0)
-		RTE_LOG(WARNING, EAL, "No free hugepages reported in %s\n",
-				subdir);
+	if (get_hp_sysfs_value(subdir, nr_over_file, &over_pages) < 0)
+		over_pages = 0;
+
+	if (get_hp_sysfs_value(subdir, nr_splus_file, &surplus_pages) < 0)
+		surplus_pages = 0;
 
 	/* adjust num_pages */
 	if (num_pages >= resv_pages)
@@ -92,6 +100,19 @@  get_num_hugepages(const char *subdir)
 	else if (resv_pages)
 		num_pages = 0;
 
+	if (over_pages >= surplus_pages)
+		over_pages -= surplus_pages;
+	else
+		over_pages = 0;
+
+	if (num_pages == 0 && over_pages == 0)
+		RTE_LOG(WARNING, EAL, "No available hugepages reported in %s\n",
+				subdir);
+
+	num_pages += over_pages;
+	if (num_pages < over_pages) /* overflow */
+		num_pages = UINT32_MAX;
+
 	/* we want to return a uint32_t and more than this looks suspicious
 	 * anyway ... */
 	if (num_pages > UINT32_MAX)