~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/mm/hugepage-shm.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/mm/hugepage-shm.c (Architecture ppc) and /tools/testing/selftests/mm/hugepage-shm.c (Architecture mips)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * hugepage-shm:                                    3  * hugepage-shm:
  4  *                                                  4  *
  5  * Example of using huge page memory in a user      5  * Example of using huge page memory in a user application using Sys V shared
  6  * memory system calls.  In this example the a      6  * memory system calls.  In this example the app is requesting 256MB of
  7  * memory that is backed by huge pages.  The a      7  * memory that is backed by huge pages.  The application uses the flag
  8  * SHM_HUGETLB in the shmget system call to in      8  * SHM_HUGETLB in the shmget system call to inform the kernel that it is
  9  * requesting huge pages.                           9  * requesting huge pages.
 10  *                                                 10  *
 11  * Note: The default shared memory limit is qu     11  * Note: The default shared memory limit is quite low on many kernels,
 12  * you may need to increase it via:                12  * you may need to increase it via:
 13  *                                                 13  *
 14  * echo 268435456 > /proc/sys/kernel/shmmax        14  * echo 268435456 > /proc/sys/kernel/shmmax
 15  *                                                 15  *
 16  * This will increase the maximum size per sha     16  * This will increase the maximum size per shared memory segment to 256MB.
 17  * The other limit that you will hit eventuall     17  * The other limit that you will hit eventually is shmall which is the
 18  * total amount of shared memory in pages. To      18  * total amount of shared memory in pages. To set it to 16GB on a system
 19  * with a 4kB pagesize do:                         19  * with a 4kB pagesize do:
 20  *                                                 20  *
 21  * echo 4194304 > /proc/sys/kernel/shmall          21  * echo 4194304 > /proc/sys/kernel/shmall
 22  */                                                22  */
 23                                                    23 
 24 #include <stdlib.h>                                24 #include <stdlib.h>
 25 #include <stdio.h>                                 25 #include <stdio.h>
 26 #include <sys/types.h>                             26 #include <sys/types.h>
 27 #include <sys/ipc.h>                               27 #include <sys/ipc.h>
 28 #include <sys/shm.h>                               28 #include <sys/shm.h>
 29 #include <sys/mman.h>                              29 #include <sys/mman.h>
 30                                                    30 
 31 #define LENGTH (256UL*1024*1024)                   31 #define LENGTH (256UL*1024*1024)
 32                                                    32 
 33 #define dprintf(x)  printf(x)                      33 #define dprintf(x)  printf(x)
 34                                                    34 
 35 int main(void)                                     35 int main(void)
 36 {                                                  36 {
 37         int shmid;                                 37         int shmid;
 38         unsigned long i;                           38         unsigned long i;
 39         char *shmaddr;                             39         char *shmaddr;
 40                                                    40 
 41         shmid = shmget(2, LENGTH, SHM_HUGETLB      41         shmid = shmget(2, LENGTH, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W);
 42         if (shmid < 0) {                           42         if (shmid < 0) {
 43                 perror("shmget");                  43                 perror("shmget");
 44                 exit(1);                           44                 exit(1);
 45         }                                          45         }
 46         printf("shmid: 0x%x\n", shmid);            46         printf("shmid: 0x%x\n", shmid);
 47                                                    47 
 48         shmaddr = shmat(shmid, NULL, 0);           48         shmaddr = shmat(shmid, NULL, 0);
 49         if (shmaddr == (char *)-1) {               49         if (shmaddr == (char *)-1) {
 50                 perror("Shared memory attach f     50                 perror("Shared memory attach failure");
 51                 shmctl(shmid, IPC_RMID, NULL);     51                 shmctl(shmid, IPC_RMID, NULL);
 52                 exit(2);                           52                 exit(2);
 53         }                                          53         }
 54         printf("shmaddr: %p\n", shmaddr);          54         printf("shmaddr: %p\n", shmaddr);
 55                                                    55 
 56         dprintf("Starting the writes:\n");         56         dprintf("Starting the writes:\n");
 57         for (i = 0; i < LENGTH; i++) {             57         for (i = 0; i < LENGTH; i++) {
 58                 shmaddr[i] = (char)(i);            58                 shmaddr[i] = (char)(i);
 59                 if (!(i % (1024 * 1024)))          59                 if (!(i % (1024 * 1024)))
 60                         dprintf(".");              60                         dprintf(".");
 61         }                                          61         }
 62         dprintf("\n");                             62         dprintf("\n");
 63                                                    63 
 64         dprintf("Starting the Check...");          64         dprintf("Starting the Check...");
 65         for (i = 0; i < LENGTH; i++)               65         for (i = 0; i < LENGTH; i++)
 66                 if (shmaddr[i] != (char)i) {       66                 if (shmaddr[i] != (char)i) {
 67                         printf("\nIndex %lu mi     67                         printf("\nIndex %lu mismatched\n", i);
 68                         exit(3);                   68                         exit(3);
 69                 }                                  69                 }
 70         dprintf("Done.\n");                        70         dprintf("Done.\n");
 71                                                    71 
 72         if (shmdt((const void *)shmaddr) != 0)     72         if (shmdt((const void *)shmaddr) != 0) {
 73                 perror("Detach failure");          73                 perror("Detach failure");
 74                 shmctl(shmid, IPC_RMID, NULL);     74                 shmctl(shmid, IPC_RMID, NULL);
 75                 exit(4);                           75                 exit(4);
 76         }                                          76         }
 77                                                    77 
 78         shmctl(shmid, IPC_RMID, NULL);             78         shmctl(shmid, IPC_RMID, NULL);
 79                                                    79 
 80         return 0;                                  80         return 0;
 81 }                                                  81 }
 82                                                    82 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php