diff mbox

[PATCHv4,1/2] linux-generic: use default huge page size

Message ID 1463424720-32215-2-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov May 16, 2016, 6:51 p.m. UTC
odp_shm_reserve() relays on huge page size to round up
requested size. If 1 Gb pages present than parser takes
it first as first alphabetical file name in sysfs. That
lead to issue where all allocations wants 1 GB HP. This
patch takes system default huge pages which are usually 2Mb,
and has to be enough for existence odp example apps and
validation tests.

Reported-by: B.Nousilal <bnousilal@gmail.com>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/odp_system_info.c | 43 +++++++++++---------------------
 1 file changed, 15 insertions(+), 28 deletions(-)

Comments

Bill Fischofer May 16, 2016, 8:53 p.m. UTC | #1
For this series:

Reviewed-by: Bill Fischofer <bll.fischofer@linaro.org:

On Mon, May 16, 2016 at 1:51 PM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> odp_shm_reserve() relays on huge page size to round up
> requested size. If 1 Gb pages present than parser takes
> it first as first alphabetical file name in sysfs. That
> lead to issue where all allocations wants 1 GB HP. This
> patch takes system default huge pages which are usually 2Mb,
> and has to be enough for existence odp example apps and
> validation tests.
>
> Reported-by: B.Nousilal <bnousilal@gmail.com>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  platform/linux-generic/odp_system_info.c | 43
> +++++++++++---------------------
>  1 file changed, 15 insertions(+), 28 deletions(-)
>
> diff --git a/platform/linux-generic/odp_system_info.c
> b/platform/linux-generic/odp_system_info.c
> index 0f1f3c7..8e95e05 100644
> --- a/platform/linux-generic/odp_system_info.c
> +++ b/platform/linux-generic/odp_system_info.c
> @@ -24,12 +24,9 @@
>  #include <sys/types.h>
>  #include <dirent.h>
>
> -
>  #define CACHE_LNSZ_FILE \
>         "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
>
> -#define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages"
> -
>  /*
>   * Report the number of logical CPUs detected at boot time
>   */
> @@ -77,37 +74,27 @@ static int systemcpu_cache_line_size(void)
>  #endif
>
>
> -static int huge_page_size(void)
> +static uint64_t default_huge_page_size(void)
>  {
> -       DIR *dir;
> -       struct dirent *dirent;
> -       int size = 0;
> +       char str[1024];
> +       unsigned long sz;
> +       FILE *file;
>
> -       dir = opendir(HUGE_PAGE_DIR);
> -       if (dir == NULL) {
> -               ODP_ERR("%s not found\n", HUGE_PAGE_DIR);
> -               return 0;
> -       }
> -
> -       while ((dirent = readdir(dir)) != NULL) {
> -               int temp = 0;
> -
> -               if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)
> -                       continue;
> -
> -               if (temp > size)
> -                       size = temp;
> -       }
> +       file = fopen("/proc/meminfo", "rt");
>
> -       if (closedir(dir)) {
> -               ODP_ERR("closedir failed\n");
> -               return 0;
> +       while (fgets(str, sizeof(str), file) != NULL) {
> +               if (sscanf(str, "Hugepagesize:   %8lu kB", &sz) == 1) {
> +                       ODP_DBG("defaut hp size is %" PRIu64 " kB\n", sz);
> +                       fclose(file);
> +                       return (uint64_t)sz * 1024;
> +               }
>         }
>
> -       return size * 1024;
> +       ODP_ERR("unable to get default hp size\n");
> +       fclose(file);
> +       return 0;
>  }
>
> -
>  /*
>   * Analysis of /sys/devices/system/cpu/ files
>   */
> @@ -137,7 +124,7 @@ static int systemcpu(odp_system_info_t *sysinfo)
>                 return -1;
>         }
>
> -       sysinfo->huge_page_size = huge_page_size();
> +       sysinfo->huge_page_size = default_huge_page_size();
>
>         return 0;
>  }
> --
> 2.7.1.250.gff4ea60
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov May 17, 2016, 12:52 p.m. UTC | #2
Merged,
Maxim.

On 05/16/16 23:53, Bill Fischofer wrote:
> For this series:
>
> Reviewed-by: Bill Fischofer <bll.fischofer@linaro.org 
> <mailto:bll.fischofer@linaro.org>:
>
> On Mon, May 16, 2016 at 1:51 PM, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> wrote:
>
>     odp_shm_reserve() relays on huge page size to round up
>     requested size. If 1 Gb pages present than parser takes
>     it first as first alphabetical file name in sysfs. That
>     lead to issue where all allocations wants 1 GB HP. This
>     patch takes system default huge pages which are usually 2Mb,
>     and has to be enough for existence odp example apps and
>     validation tests.
>
>     Reported-by: B.Nousilal <bnousilal@gmail.com
>     <mailto:bnousilal@gmail.com>>
>     Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org
>     <mailto:maxim.uvarov@linaro.org>>
>     ---
>      platform/linux-generic/odp_system_info.c | 43
>     +++++++++++---------------------
>      1 file changed, 15 insertions(+), 28 deletions(-)
>
>     diff --git a/platform/linux-generic/odp_system_info.c
>     b/platform/linux-generic/odp_system_info.c
>     index 0f1f3c7..8e95e05 100644
>     --- a/platform/linux-generic/odp_system_info.c
>     +++ b/platform/linux-generic/odp_system_info.c
>     @@ -24,12 +24,9 @@
>      #include <sys/types.h>
>      #include <dirent.h>
>
>     -
>      #define CACHE_LNSZ_FILE \
>     "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
>
>     -#define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages"
>     -
>      /*
>       * Report the number of logical CPUs detected at boot time
>       */
>     @@ -77,37 +74,27 @@ static int systemcpu_cache_line_size(void)
>      #endif
>
>
>     -static int huge_page_size(void)
>     +static uint64_t default_huge_page_size(void)
>      {
>     -       DIR *dir;
>     -       struct dirent *dirent;
>     -       int size = 0;
>     +       char str[1024];
>     +       unsigned long sz;
>     +       FILE *file;
>
>     -       dir = opendir(HUGE_PAGE_DIR);
>     -       if (dir == NULL) {
>     -               ODP_ERR("%s not found\n", HUGE_PAGE_DIR);
>     -               return 0;
>     -       }
>     -
>     -       while ((dirent = readdir(dir)) != NULL) {
>     -               int temp = 0;
>     -
>     -               if (sscanf(dirent->d_name, "hugepages-%i", &temp)
>     != 1)
>     -                       continue;
>     -
>     -               if (temp > size)
>     -                       size = temp;
>     -       }
>     +       file = fopen("/proc/meminfo", "rt");
>
>     -       if (closedir(dir)) {
>     -               ODP_ERR("closedir failed\n");
>     -               return 0;
>     +       while (fgets(str, sizeof(str), file) != NULL) {
>     +               if (sscanf(str, "Hugepagesize:   %8lu kB", &sz) ==
>     1) {
>     +                       ODP_DBG("defaut hp size is %" PRIu64 "
>     kB\n", sz);
>     +                       fclose(file);
>     +                       return (uint64_t)sz * 1024;
>     +               }
>             }
>
>     -       return size * 1024;
>     +       ODP_ERR("unable to get default hp size\n");
>     +       fclose(file);
>     +       return 0;
>      }
>
>     -
>      /*
>       * Analysis of /sys/devices/system/cpu/ files
>       */
>     @@ -137,7 +124,7 @@ static int systemcpu(odp_system_info_t *sysinfo)
>                     return -1;
>             }
>
>     -       sysinfo->huge_page_size = huge_page_size();
>     +       sysinfo->huge_page_size = default_huge_page_size();
>
>             return 0;
>      }
>     --
>     2.7.1.250.gff4ea60
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index 0f1f3c7..8e95e05 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -24,12 +24,9 @@ 
 #include <sys/types.h>
 #include <dirent.h>
 
-
 #define CACHE_LNSZ_FILE \
 	"/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
 
-#define HUGE_PAGE_DIR "/sys/kernel/mm/hugepages"
-
 /*
  * Report the number of logical CPUs detected at boot time
  */
@@ -77,37 +74,27 @@  static int systemcpu_cache_line_size(void)
 #endif
 
 
-static int huge_page_size(void)
+static uint64_t default_huge_page_size(void)
 {
-	DIR *dir;
-	struct dirent *dirent;
-	int size = 0;
+	char str[1024];
+	unsigned long sz;
+	FILE *file;
 
-	dir = opendir(HUGE_PAGE_DIR);
-	if (dir == NULL) {
-		ODP_ERR("%s not found\n", HUGE_PAGE_DIR);
-		return 0;
-	}
-
-	while ((dirent = readdir(dir)) != NULL) {
-		int temp = 0;
-
-		if (sscanf(dirent->d_name, "hugepages-%i", &temp) != 1)
-			continue;
-
-		if (temp > size)
-			size = temp;
-	}
+	file = fopen("/proc/meminfo", "rt");
 
-	if (closedir(dir)) {
-		ODP_ERR("closedir failed\n");
-		return 0;
+	while (fgets(str, sizeof(str), file) != NULL) {
+		if (sscanf(str, "Hugepagesize:   %8lu kB", &sz) == 1) {
+			ODP_DBG("defaut hp size is %" PRIu64 " kB\n", sz);
+			fclose(file);
+			return (uint64_t)sz * 1024;
+		}
 	}
 
-	return size * 1024;
+	ODP_ERR("unable to get default hp size\n");
+	fclose(file);
+	return 0;
 }
 
-
 /*
  * Analysis of /sys/devices/system/cpu/ files
  */
@@ -137,7 +124,7 @@  static int systemcpu(odp_system_info_t *sysinfo)
 		return -1;
 	}
 
-	sysinfo->huge_page_size = huge_page_size();
+	sysinfo->huge_page_size = default_huge_page_size();
 
 	return 0;
 }