@@ -739,12 +739,15 @@ void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
739
739
}
740
740
741
741
int hugetlb_setup_ok ;
742
+ #define SYSFS_FMT_NR_HUGE_PAGES "/sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages"
742
743
#define GET_NR_HUGE_PAGES 10
743
744
void setup_hugetlbfs (void )
744
745
{
745
746
int err ;
746
747
int fd ;
747
- char buf [] = "123" ;
748
+ char buf [256 ];
749
+ long hpagesz_kb ;
750
+ long hpagesz_mb ;
748
751
749
752
if (geteuid () != 0 ) {
750
753
fprintf (stderr , "WARNING: not run as root, can not do hugetlb test\n" );
@@ -755,25 +758,31 @@ void setup_hugetlbfs(void)
755
758
756
759
/*
757
760
* Now go make sure that we got the pages and that they
758
- * are 2M pages. Someone might have made 1G the default.
761
+ * are PMD-level pages. Someone might have made PUD-level
762
+ * pages the default.
759
763
*/
760
- fd = open ("/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" , O_RDONLY );
764
+ hpagesz_kb = HPAGE_SIZE / 1024 ;
765
+ hpagesz_mb = hpagesz_kb / 1024 ;
766
+ sprintf (buf , SYSFS_FMT_NR_HUGE_PAGES , hpagesz_kb );
767
+ fd = open (buf , O_RDONLY );
761
768
if (fd < 0 ) {
762
- perror ("opening sysfs 2M hugetlb config" );
769
+ fprintf (stderr , "opening sysfs %ldM hugetlb config: %s\n" ,
770
+ hpagesz_mb , strerror (errno ));
763
771
return ;
764
772
}
765
773
766
774
/* -1 to guarantee leaving the trailing \0 */
767
775
err = read (fd , buf , sizeof (buf )- 1 );
768
776
close (fd );
769
777
if (err <= 0 ) {
770
- perror ("reading sysfs 2M hugetlb config" );
778
+ fprintf (stderr , "reading sysfs %ldM hugetlb config: %s\n" ,
779
+ hpagesz_mb , strerror (errno ));
771
780
return ;
772
781
}
773
782
774
783
if (atoi (buf ) != GET_NR_HUGE_PAGES ) {
775
- fprintf (stderr , "could not confirm 2M pages, got: '%s' expected %d\n" ,
776
- buf , GET_NR_HUGE_PAGES );
784
+ fprintf (stderr , "could not confirm %ldM pages, got: '%s' expected %d\n" ,
785
+ hpagesz_mb , buf , GET_NR_HUGE_PAGES );
777
786
return ;
778
787
}
779
788
0 commit comments