Back to index

numactl  2.0.8~rc4
Functions | Variables
shm.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void dump_shm (void)
void dump_shm_nodes (void)
void attach_shared (char *, char *)
void attach_sysvshm (char *, char *)
void verify_shm (int policy, struct bitmask *)

Variables

int shmfd
long shmid
char * shmptr
unsigned long long shmlen
mode_t shmmode
unsigned long long shmoffset
int shmflags
int exitcode

Function Documentation

void attach_shared ( char *  ,
char *   
)

Definition at line 133 of file shm.c.

{
       struct stat64 st;

       shmfd = open(name, O_RDONLY);
       if (shmfd < 0) {
              errno = 0;
              if (shmlen == 0)
                      complain("need a --length to create a shared file");
              shmfd = open(name, O_RDWR|O_CREAT, shmmode);
              if (shmfd < 0)
                     nerror("cannot create file %s", name);
       }
       if (fstat64(shmfd, &st) < 0)
              err("shm stat");
       if (shmlen > st.st_size) {
              if (ftruncate64(shmfd, shmlen) < 0) {
                     /* XXX: we could do it by hand, but it would it
                        would be impossible to apply policy then.
                        need to fix that in the kernel. */
                     perror("ftruncate");
              }
       }

       shm_pagesize = st.st_blksize;

       check_region(opt);
       
       /* RED-PEN For shmlen > address space may need to map in pieces.
          Left for some poor 32bit soul. */
       shmptr = mmap64(NULL, shmlen, PROT_READ, MAP_SHARED, shmfd, shmoffset);
       if (shmptr == (char*)-1)
              err("shm mmap");                   

}

Here is the call graph for this function:

Here is the caller graph for this function:

void attach_sysvshm ( char *  ,
char *   
)

Definition at line 98 of file shm.c.

{
       struct shmid_ds s;
       key_t key = sysvkey(name);
       
       shmfd = shmget(key, shmlen, shmflags);
       if (shmfd < 0 && errno == ENOENT) {
              if (shmlen == 0)
                     complain(
                     "need a --length to create a sysv shared memory segment");
              fprintf(stderr,
         "numactl: Creating shared memory segment %s id %ld mode %04o length %.fMB\n",
                     name, shmid, shmmode, ((double)shmlen) / (1024*1024) );
              shmfd = shmget(key, shmlen, IPC_CREAT|shmmode|shmflags);
              if (shmfd < 0)
                     nerror("cannot create shared memory segment");
       }

       if (shmlen == 0) {
              if (shmctl(shmfd, IPC_STAT, &s) < 0)
                     err("shmctl IPC_STAT");
              shmlen = s.shm_segsz;
       }

       shmptr = shmat(shmfd, NULL, SHM_RDONLY);
       if (shmptr == (void*)-1)
              err("shmat");
       shmptr += shmoffset;

       shm_pagesize = (shmflags & SHM_HUGETLB) ? huge_page_size() : getpagesize();

       check_region(opt);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_shm ( void  )

Definition at line 182 of file shm.c.

{
       struct bitmask *nodes, *prevnodes;
       int prevpol = -1, pol;
       unsigned long long c, start;

       start = 0;
       if (shmlen == 0) {
              printf("nothing to dump\n");
              return;
       }

       nodes = numa_allocate_nodemask();
       prevnodes = numa_allocate_nodemask();

       for (c = 0; c < shmlen; c += shm_pagesize) {
              if (get_mempolicy(&pol, nodes->maskp, nodes->size, c+shmptr,
                                          MPOL_F_ADDR) < 0)
                     err("get_mempolicy on shm");
              if (pol == prevpol)
                     continue;
              if (prevpol != -1)
                     dumppol(start, c, prevpol, prevnodes);
              prevnodes = nodes;
              prevpol = pol;
              start = c;
       }
       dumppol(start, c, prevpol, prevnodes);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_shm_nodes ( void  )

Definition at line 218 of file shm.c.

{
       int prevnode = -1, node;
       unsigned long long c, start;

       start = 0;
       if (shmlen == 0) {
              printf("nothing to dump\n");
              return;
       }

       for (c = 0; c < shmlen; c += shm_pagesize) {
              if (get_mempolicy(&node, NULL, 0, c+shmptr,
                                          MPOL_F_ADDR|MPOL_F_NODE) < 0)
                     err("get_mempolicy on shm");
              if (node == prevnode)
                     continue;
              if (prevnode != -1)
                     dumpnode(start, c, prevnode);
              prevnode = node;
              start = c;
       }
       dumpnode(start, c, prevnode);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void verify_shm ( int  policy,
struct bitmask  
)

Definition at line 266 of file shm.c.

{
       char *p;
       int ilnode, node;
       int pol2;
       struct bitmask *nodes2;

       nodes2 = numa_allocate_nodemask();
       
       if (policy == MPOL_INTERLEAVE) {
              if (get_mempolicy(&ilnode, NULL, 0, shmptr,
                                   MPOL_F_ADDR|MPOL_F_NODE)
                  < 0)
                     err("get_mempolicy");
       }
       
       for (p = shmptr; p - (char *)shmptr < shmlen; p += shm_pagesize) {
              if (get_mempolicy(&pol2, nodes2->maskp, nodes2->size, p,
                                                 MPOL_F_ADDR) < 0)
                     err("get_mempolicy");
              if (pol2 != policy) {
                     vwarn(p, "wrong policy %s, expected %s\n",
                           policy_name(pol2), policy_name(policy));
                     return;
              }
              if (memcmp(nodes2, nodes, numa_bitmask_nbytes(nodes))) {
                     vwarn(p, "mismatched node mask\n");
                     printmask("expected", nodes);
                     printmask("real", nodes2);
              }

              if (get_mempolicy(&node, NULL, 0, p, MPOL_F_ADDR|MPOL_F_NODE) < 0)
                     err("get_mempolicy");

              switch (policy) {
              case MPOL_INTERLEAVE:
                     if (node < 0 || !numa_bitmask_isbitset(nodes2, node))
                            vwarn(p, "interleave node out of range %d\n", node);
                     if (node != ilnode) {
                            vwarn(p, "expected interleave node %d, got %d\n",
                                 ilnode,node);
                            return;
                     }
                     ilnode = interleave_next(ilnode, nodes2);
                     break;
              case MPOL_PREFERRED:
              case MPOL_BIND:
                     if (!numa_bitmask_isbitset(nodes2, node)) {
                            vwarn(p, "unexpected node %d\n", node);
                            printmask("expected", nodes2);
                     }      
                     break;

              case MPOL_DEFAULT:
                     break;
                     
              }
       }
              
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int exitcode

Definition at line 32 of file numactl.c.

int shmfd

Definition at line 38 of file shm.c.

int shmflags

Definition at line 44 of file shm.c.

long shmid

Definition at line 39 of file shm.c.

unsigned long long shmlen

Definition at line 41 of file shm.c.

mode_t shmmode

Definition at line 42 of file shm.c.

unsigned long long shmoffset

Definition at line 43 of file shm.c.

char* shmptr

Definition at line 40 of file shm.c.