getpagesizes(), getpagesizes64()

Updated: April 19, 2023

Get the available page sizes

Synopsis:

#include <sys/mman.h>

int getpagesizes( size_t pagesize[],
                  int nelem );

int getpagesizes64( uint64_t pagesize[],
                    int nelem );

Arguments:

pagesize
NULL, or an array where the function can store the available page sizes.
nelem
The number of elements in the array.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

Returns:

The number of entries filled in the array, or -1 if an error occurred (errno is set).

Errors:

EINVAL
The value of the nelem argument is negative, or it's positive, but pagesize is NULL.

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>

int main ( void )
{
    size_t *pagesizes;
    int i, num_sizes, num_found;
    
    num_sizes = getpagesizes( NULL, 0 );
    if (num_sizes <= 0)
    {
       printf ("num_sizes is %d\n", num_sizes);
       return EXIT_FAILURE;
    }

    pagesizes = (size_t *) malloc ( num_sizes * 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;
}

Classification:

getpagesizes() is Unix; getpagesizes64() is QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes