Mempool: default as global
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 9 Mar 2024 03:16:21 +0000 (22:16 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 9 Mar 2024 03:16:21 +0000 (22:16 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I1a2c44188404e1703a9996a83495086d2b0e3ca3

include/rseq/mempool.h
src/rseq-mempool.c

index 1813a164d8ab76d167c58dc4d1b04cafb35b9c1b..78ff06db62d41ce794b62fe8dae5b6251b5013c4 100644 (file)
 #include <sys/mman.h>
 
 /*
- * rseq/mempool.h: rseq CPU-Local Storage (CLS) memory allocator.
+ * rseq/mempool.h: rseq memory pool allocator.
+ *
+ * The rseq memory pool allocator can be configured as either a global
+ * allocator (default) or a per-CPU memory allocator.
+ *
+ * The rseq global memory allocator allows the application to request
+ * memory pools of global memory each of containing objects of a
+ * given size (rounded to next power of 2), reserving a given virtual
+ * address size of the requested stride.
  *
  * The rseq per-CPU memory allocator allows the application the request
  * memory pools of CPU-Local memory each of containing objects of a
  * The per-CPU memory allocator is analogous to TLS (Thread-Local
  * Storage) memory: TLS is Thread-Local Storage, whereas the per-CPU
  * memory allocator provides CPU-Local Storage.
+ *
+ * Memory pool sets can be created by adding one or more pools into
+ * them. They can be used to perform allocation of variable length
+ * objects.
  */
 
 #ifdef __cplusplus
@@ -64,7 +76,7 @@ struct rseq_mempool;
  * The @attr pointer used to specify the pool attributes. If NULL, use a
  * default attribute values. The @attr can be destroyed immediately
  * after rseq_mempool_create() returns. The caller keeps ownership
- * of @attr. Default attributes select a per-cpu mempool type.
+ * of @attr. Default attributes select a global mempool type.
  *
  * The argument @pool_name can be used to given a name to the pool for
  * debugging purposes. It can be NULL if no name is given.
@@ -95,6 +107,7 @@ struct rseq_mempool *rseq_mempool_create(const char *pool_name,
  * Argument @pool is a pointer to the per-cpu pool to destroy.
  *
  * Return values: 0 on success, -1 on error, with errno set accordingly:
+ *
  *   ENOENT: Trying to free a pool which was not allocated.
  *
  * If the munmap_func callback fails, -1 is returned and errno is
@@ -410,7 +423,7 @@ int rseq_mempool_attr_set_robust(struct rseq_mempool_attr *attr);
 /*
  * rseq_mempool_attr_set_percpu: Set pool type as percpu.
  *
- * A pool created with this type is a per-cpu memory pool.  The reserved
+ * A pool created with this type is a per-cpu memory pool. The reserved
  * allocation size is @stride, and the maximum CPU value expected
  * is (@max_nr_cpus - 1). A @stride of 0 uses the default
  * RSEQ_MEMPOOL_STRIDE.
@@ -423,7 +436,7 @@ int rseq_mempool_attr_set_percpu(struct rseq_mempool_attr *attr,
 /*
  * rseq_mempool_attr_set_global: Set pool type as global.
  *
- * A pool created with this type is a global memory pool.  The reserved
+ * A pool created with this type is a global memory pool. The reserved
  * allocation size is @stride. A @stride of 0 uses the default
  * RSEQ_MEMPOOL_STRIDE.
  *
index cc30d18b08ac99f5c8c088d9cccbea3fad0fa7f1..798c0e803dbc4a883e94740bbceeb3eb56b44ad6 100644 (file)
@@ -65,8 +65,8 @@ struct free_list_node {
 };
 
 enum mempool_type {
-       MEMPOOL_TYPE_PERCPU = 0,        /* Default */
-       MEMPOOL_TYPE_GLOBAL = 1,
+       MEMPOOL_TYPE_GLOBAL = 0,        /* Default */
+       MEMPOOL_TYPE_PERCPU = 1,
 };
 
 struct rseq_mempool_attr {
@@ -546,6 +546,8 @@ struct rseq_mempool *rseq_mempool_create(const char *pool_name,
                }
                break;
        case MEMPOOL_TYPE_GLOBAL:
+               /* Use a 1-cpu pool for global mempool type. */
+               attr.max_nr_cpus = 1;
                break;
        }
        if (!attr.stride)
@@ -854,6 +856,6 @@ int rseq_mempool_attr_set_global(struct rseq_mempool_attr *attr,
        }
        attr->type = MEMPOOL_TYPE_GLOBAL;
        attr->stride = stride;
-       attr->max_nr_cpus = 1;
+       attr->max_nr_cpus = 0;
        return 0;
 }
This page took 0.034777 seconds and 4 git commands to generate.