Get the available page sizes
#include <sys/mman.h> int getpagesizes( size_t pagesize[], int nelem ); int getpagesizes64( uint64_t pagesize[], int nelem );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getpagesizes() and getpagesizes64() functions get the available page sizes and store up to nelem of them in the pagesize array. Software that wants to optimize its usage of large pages can use these functions to determine what sizes are available.
If you use getpagesizes64(), some page sizes will have the _SYS_GETPAGESIZES_HIGHUSAGE bit (defined in <sys/sysmsg.h>) set to indicate that they're available only when mapping objects marked with the SHMCTL_HIGHUSAGE flag. These page sizes aren't included in the list provided by getpagesizes().
If you pass NULL for pagesize and 0 for nelem, the functions return the number of available page sizes.
The number of entries filled in the array, or -1 if an error occurred (errno is set).
#include <stdio.h> #include <stdlib.h> #include <sys/mman.h> int main ( void ) { size_t *pagesizes; int i, num_found; num_found = getpagesizes( NULL, 0 ); if (num_found <= 0) { printf ("num_found is %d\n", num_found); return EXIT_FAILURE; } pagesizes = (size_t *) malloc ( num_found * sizeof (size_t)); if (pagesizes == NULL) { perror ("malloc()"); return EXIT_FAILURE; } num_found = getpagesizes( pagesizes, NUM_SIZES ); printf ("Found %d sizes:\n", num_found); for (i=0; i < num_found; i++) { printf (" %d\n", pagesizes[i]); } return EXIT_SUCCESS; }
getpagesizes() is Unix; getpagesizes64() is QNX Neutrino
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |