#include "common/macros.h"
#include "common/ust-fd.h"
-#include "mmap.h"
+#include "common/compat/mmap.h"
/*
* Ensure we have the required amount of space available by writing 0
return ret;
}
-struct shm_object_table *shm_object_table_create(size_t max_nb_obj)
+struct shm_object_table *shm_object_table_create(size_t max_nb_obj, bool populate)
{
struct shm_object_table *table;
- table = zmalloc(sizeof(struct shm_object_table) +
- max_nb_obj * sizeof(table->objects[0]));
+ table = zmalloc_populate(sizeof(struct shm_object_table) +
+ max_nb_obj * sizeof(table->objects[0]), populate);
if (!table)
return NULL;
table->size = max_nb_obj;
static
struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
size_t memory_map_size,
- int stream_fd)
+ int stream_fd,
+ bool populate)
{
int shmfd, waitfd[2], ret, i;
+ int flags = MAP_SHARED;
struct shm_object *obj;
char *memory_map;
obj = &table->objects[table->allocated_len];
/* wait_fd: create pipe */
- ret = pipe(waitfd);
+ ret = pipe2(waitfd, O_CLOEXEC);
if (ret < 0) {
PERROR("pipe");
goto error_pipe;
}
- for (i = 0; i < 2; i++) {
- ret = fcntl(waitfd[i], F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- PERROR("fcntl");
- goto error_fcntl;
- }
- }
/* The write end of the pipe needs to be non-blocking */
ret = fcntl(waitfd[1], F_SETFL, O_NONBLOCK);
if (ret < 0) {
obj->shm_fd_ownership = 0;
obj->shm_fd = shmfd;
+ if (populate)
+ flags |= LTTNG_MAP_POPULATE;
/* memory_map: mmap */
memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
- MAP_SHARED | LTTNG_MAP_POPULATE, shmfd, 0);
+ flags, shmfd, 0);
if (memory_map == MAP_FAILED) {
PERROR("mmap");
goto error_mmap;
static
struct shm_object *_shm_object_table_alloc_mem(struct shm_object_table *table,
- size_t memory_map_size)
+ size_t memory_map_size, bool populate)
{
struct shm_object *obj;
void *memory_map;
return NULL;
obj = &table->objects[table->allocated_len];
- memory_map = zmalloc(memory_map_size);
+ memory_map = zmalloc_populate(memory_map_size, populate);
if (!memory_map)
goto alloc_error;
/* wait_fd: create pipe */
- ret = pipe(waitfd);
+ ret = pipe2(waitfd, O_CLOEXEC);
if (ret < 0) {
PERROR("pipe");
goto error_pipe;
}
- for (i = 0; i < 2; i++) {
- ret = fcntl(waitfd[i], F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- PERROR("fcntl");
- goto error_fcntl;
- }
- }
/* The write end of the pipe needs to be non-blocking */
ret = fcntl(waitfd[1], F_SETFL, O_NONBLOCK);
if (ret < 0) {
}
#endif
+#ifdef HAVE_LIBNUMA
+struct shm_object *shm_object_table_alloc(struct shm_object_table *table,
+ size_t memory_map_size,
+ enum shm_object_type type,
+ int stream_fd,
+ int cpu,
+ bool populate)
+#else
struct shm_object *shm_object_table_alloc(struct shm_object_table *table,
size_t memory_map_size,
enum shm_object_type type,
int stream_fd,
- int cpu)
+ int cpu __attribute__((unused)),
+ bool populate)
+#endif
{
struct shm_object *shm_object;
#ifdef HAVE_LIBNUMA
switch (type) {
case SHM_OBJECT_SHM:
shm_object = _shm_object_table_alloc_shm(table, memory_map_size,
- stream_fd);
+ stream_fd, populate);
break;
case SHM_OBJECT_MEM:
- shm_object = _shm_object_table_alloc_mem(table, memory_map_size);
+ shm_object = _shm_object_table_alloc_mem(table, memory_map_size,
+ populate);
break;
default:
assert(0);
struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
int shm_fd, int wakeup_fd, uint32_t stream_nr,
- size_t memory_map_size)
+ size_t memory_map_size, bool populate)
{
+ int flags = MAP_SHARED;
struct shm_object *obj;
char *memory_map;
int ret;
goto error_fcntl;
}
+ if (populate)
+ flags |= LTTNG_MAP_POPULATE;
/* memory_map: mmap */
memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
- MAP_SHARED | LTTNG_MAP_POPULATE, shm_fd, 0);
+ flags, shm_fd, 0);
if (memory_map == MAP_FAILED) {
PERROR("mmap");
goto error_mmap;
obj->shm_fd = -1;
obj->shm_fd_ownership = 0;
- ret = fcntl(obj->wait_fd[1], F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- PERROR("fcntl");
- goto error_fcntl;
- }
/* The write end of the pipe needs to be non-blocking */
ret = fcntl(obj->wait_fd[1], F_SETFL, O_NONBLOCK);
if (ret < 0) {