Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

memalloc_attr(3) [osf1 man page]

memalloc_attr(3)					     Library Functions Manual						  memalloc_attr(3)

NAME
memalloc_attr - Query the memory allocation policy and attributes (libnuma library) SYNOPSIS
#include <numa.h> int memalloc_attr( vm_offset_t va, memalloc_attr_t *attr ); PARAMETERS
The user virtual address for which the memory allocation policy is requested. Points to a buffer to receive the memory allocation policy and attributes for the page containing the specified virtual address. DESCRIPTION
The memalloc_attr() function returns the current memory allocation policy and associated attributes in the buffer pointed to by attr for the address specified by va. If radset information about the memory allocation policy is desired, a radset must be allocated through the radsetcreate() function, and the mattr_radset element of the attr argument must point to that radset. Otherwise, a 0 must be specified for the mattr_radset. EXAMPLE
#include <numa.h> main() { vm_offset_t va; memalloc_attr_t attr; int id; int flags = SET_CURSOR_CONSUME; rad_cursor_t cursor = SET_CURSOR_INIT; radsetcreate(&attr.mattr_radset); va = (vm_offset_t)&attr; /* no policy in effect - return zeroes */ if (memalloc_attr(va, &attr) == -1) { perror("memalloc_attr"); radsetdestroy(&attr.mattr_radset); return 0; } printf("mattr_policy = 0x%lx ", attr.mattr_policy); printf("mattr_rad = 0x%lx ", attr.mattr_rad); printf("mattr_stride = 0x%lx ", attr.mattr_stride); printf("mattr_distance = 0x%lx ", attr.mattr_distance); printf("mattr_pagesz = 0x%lx ", attr.mattr_pagesz); /* set policy */ attr.mattr_policy = MPOL_DIRECTED; attr.mattr_rad = 0; if (nmadvise((void *)va, sizeof(memalloc_attr_t), 0, &attr) == -1) { perror("nmadvise"); radsetdestroy(&attr.mattr_radset); return 0; } if (memalloc_attr(va, &attr) == -1) { perror("memalloc_attr"); radsetdestroy(&attr.mattr_radset); return 0; } printf("mattr_policy = 0x%lx ", attr.mattr_policy); printf("mattr_rad = 0x%lx ", attr.mattr_rad); printf("mattr_stride = 0x%lx ", attr.mattr_stride); printf("mattr_distance = 0x%lx ", attr.mattr_distance); printf("mattr_pagesz = 0x%lx ", attr.mattr_pagesz); /* enumerate the mattr_radset */ printf(" Enumerating radset members: "); while ((id = rad_foreach(attr.mattr_radset, flags, &cursor)) != RAD_NONE) { if ((id % 8) == 0) printf(" "); printf("%3d, ", id); } printf(" "); } RETURN VALUES
Success. In this case, the function stores the requested memory allocation policy and attributes in the buffer pointed to by attr. If no memory allocation policy has been set for the specified virtual address (e.g., madvise() or nmadvise()) not called for that address), a zeroed attr structure is returned. Failure. In this case, the function sets errno to indicate the error. ERRORS
If the memalloc_attr() function fails, it sets errno to one of the following values: The address pointed to by va, attr, or mattr_radset is invalid. The mattr_radset element of the attr argument points to an invalid RAD set, possibly one that has not been created by a rad- setcreate() call. SEE ALSO
Functions: numa_intro(3) Files: numa_types(4) memalloc_attr(3)

Check Out this Related Man Page

PTHREAD_GETATTR_DEFAULT_NP(3)				     Linux Programmer's Manual				     PTHREAD_GETATTR_DEFAULT_NP(3)

NAME
pthread_getattr_default_np, pthread_setattr_default_np, - get or set default thread-creation attributes SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <pthread.h> int pthread_getattr_default_np(pthread_attr_t *attr); int pthread_setattr_default_np(pthread_attr_t *attr); Compile and link with -pthread. DESCRIPTION
The pthread_setattr_default_np() function sets the default attributes used for creation of a new thread--that is, the attributes that are used when pthread_create(3) is called with a second argument that is NULL. The default attributes are set using the attributes supplied in *attr, a previously initialized thread attributes object. Note the following details about the supplied attributes object: * The attribute settings in the object must be valid. * The stack address attribute must not be set in the object. * Setting the stack size attribute to zero means leave the default stack size unchanged. The pthread_getattr_default_np() function initializes the thread attributes object referred to by attr so that it contains the default attributes used for thread creation. ERRORS
EINVAL (pthread_setattr_default_np()) One of the attribute settings in attr is invalid, or the stack address attribute is set in attr. ENOMEM (pthread_setattr_default_np()) Insufficient memory. VERSIONS
These functions are available in glibc since version 2.18. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +-------------------------------+---------------+---------+ |Interface | Attribute | Value | +-------------------------------+---------------+---------+ |pthread_getattr_default_np(), | Thread safety | MT-Safe | |pthread_setattr_default_np() | | | +-------------------------------+---------------+---------+ CONFORMING TO
These functions are nonstandard GNU extensions; hence the suffix "_np" (nonportable) in their names. EXAMPLE
The program below uses pthread_getattr_default_np() to fetch the default thread-creation attributes and then displays various settings from the returned thread attributes object. When running the program, we see the following output: $ ./a.out Stack size: 8388608 Guard size: 4096 Scheduling policy: SCHED_OTHER Scheduling priority: 0 Detach state: JOINABLE Inherit scheduler: INHERIT Program source #define _GNU_SOURCE #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #define errExitEN(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void display_pthread_attr(pthread_attr_t *attr) { int s; size_t stacksize; size_t guardsize; int policy; struct sched_param schedparam; int detachstate; int inheritsched; s = pthread_attr_getstacksize(attr, &stacksize); if (s != 0) errExitEN(s, "pthread_attr_getstacksize"); printf("Stack size: %zd ", stacksize); s = pthread_attr_getguardsize(attr, &guardsize); if (s != 0) errExitEN(s, "pthread_attr_getguardsize"); printf("Guard size: %zd ", guardsize); s = pthread_attr_getschedpolicy(attr, &policy); if (s != 0) errExitEN(s, "pthread_attr_getschedpolicy"); printf("Scheduling policy: %s ", (policy == SCHED_FIFO) ? "SCHED_FIFO" : (policy == SCHED_RR) ? "SCHED_RR" : (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]"); s = pthread_attr_getschedparam(attr, &schedparam); if (s != 0) errExitEN(s, "pthread_attr_getschedparam"); printf("Scheduling priority: %d ", schedparam.sched_priority); s = pthread_attr_getdetachstate(attr, &detachstate); if (s != 0) errExitEN(s, "pthread_attr_getdetachstate"); printf("Detach state: %s ", (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" : (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" : "???"); s = pthread_attr_getinheritsched(attr, &inheritsched); if (s != 0) errExitEN(s, "pthread_attr_getinheritsched"); printf("Inherit scheduler: %s ", (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" : (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" : "???"); } int main(int argc, char *argv[]) { int s; pthread_attr_t attr; s = pthread_getattr_default_np(&attr); if (s != 0) errExitEN(s, "pthread_getattr_default_np"); display_pthread_attr(&attr); exit(EXIT_SUCCESS); } SEE ALSO
pthread_attr_getaffinity_np(3), pthread_attr_getdetachstate(3), pthread_attr_getguardsize(3), pthread_attr_getinheritsched(3), pthread_attr_getschedparam(3), pthread_attr_getschedpolicy(3), pthread_attr_getscope(3), pthread_attr_getstack(3), pthread_attr_getstackaddr(3), pthread_attr_getstacksize(3), pthread_attr_init(3), pthread_create(3), pthreads(7) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 PTHREAD_GETATTR_DEFAULT_NP(3)
Man Page