(NUMA) set_mempolicy returning EINVAL - why?

44 Views Asked by At

A call to set_mempolicy seems to return EINVAL when I set policy to MPOL_BIND to any other node than 0.

The following code:

int main( int argc, char** argv )
{
    unsigned int        curCpu;
    unsigned int        curNode;
    int                 rc;
    unsigned long       nodeMask;
    unsigned long       maxNode;
    long                rc2;

    printf( "I have %d NUMA nodes\n", numa_num_configured_nodes() );
    rc = getcpu( &curCpu, &curNode );
    if( rc )
    {
        printf( "Failed to get current CPU\n" );
        exit( 0 );
    }
    printf( "Current CPU is %d, current node is %d\n", curCpu, curNode );

    for( int node = 0; node < numa_num_configured_nodes() ; node++ )
    {
        nodeMask = 1 << node;
        rc2 = set_mempolicy( MPOL_BIND | MPOL_F_STATIC_NODES, &nodeMask, numa_num_configured_nodes() );
        printf( "Setting nodeMask to %08lx returned %ld (errno=%d)\n", nodeMask, rc2, errno );
    }

    return( 0 );
}

Gives output:

I have 2 NUMA nodes
Current CPU is 29, current node is 1
Setting nodeMask to 00000001 returned 0 (errno=0)
Setting nodeMask to 00000002 returned -1 (errno=22)

I'm not clear on why the second call is failing?

(Ubuntu 22.04 LTS, 5.15.0-84-generic, 40-core machine with 2 nodes)

0

There are 0 best solutions below