- /* Calculate the shm allocation layout */
- shmsize = sizeof(struct shm_header);
- shmsize += sizeof(struct channel);
-
- /* Per-cpu buffer size: control (prior to backend) */
- bufshmsize = sizeof(struct lib_ring_buffer);
- shmsize += bufshmsize * num_possible_cpus();
-
- /* Per-cpu buffer size: backend */
- /* num_subbuf + 1 is the worse case */
- num_subbuf_alloc = num_subbuf + 1;
- bufshmsize = sizeof(struct lib_ring_buffer_backend_pages *) * num_subbuf_alloc;
- bufshmsize += subbuf_size * (num_subbuf_alloc);
- bufshmsize += (sizeof(struct lib_ring_buffer_backend_pages) + subbuf_size) * num_subbuf_alloc;
- bufshmsize += sizeof(struct lib_ring_buffer_backend_subbuffer) * num_subbuf;
- shmsize += bufshmsize * num_possible_cpus();
-
- /* Per-cpu buffer size: control (after backend) */
- bufshmsize += sizeof(struct commit_counters_hot) * num_subbuf;
- bufshmsize += sizeof(struct commit_counters_cold) * num_subbuf;
-
- /* Allocate shm */
- *shmid = shmget(getpid(), shmsize, IPC_CREAT | IPC_EXCL | 0700);
- if (*shmid < 0) {
- if (errno == EINVAL)
- ERR("shmget() returned EINVAL; maybe /proc/sys/kernel/shmmax should be increased.");
- else
- PERROR("shmget");