Make the shared memory segment size configurable

This is useful only on systems where memory overcommit is not available
or disabled.
This commit is contained in:
Lennart Poettering 2008-10-01 01:14:36 +02:00
parent a84b72bf96
commit 79ad4e63f6
23 changed files with 99 additions and 37 deletions

View file

@ -680,8 +680,9 @@ static void memblock_replace_import(pa_memblock *b) {
pa_mutex_unlock(seg->import->mutex);
}
pa_mempool* pa_mempool_new(pa_bool_t shared) {
pa_mempool* pa_mempool_new(pa_bool_t shared, size_t size) {
pa_mempool *p;
char t1[64], t2[64];
p = pa_xnew(pa_mempool, 1);
@ -692,13 +693,26 @@ pa_mempool* pa_mempool_new(pa_bool_t shared) {
if (p->block_size < PA_PAGE_SIZE)
p->block_size = PA_PAGE_SIZE;
p->n_blocks = PA_MEMPOOL_SLOTS_MAX;
if (size <= 0)
p->n_blocks = PA_MEMPOOL_SLOTS_MAX;
else {
p->n_blocks = (unsigned) (size / p->block_size);
if (p->n_blocks < 2)
p->n_blocks = 2;
}
if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) {
pa_xfree(p);
return NULL;
}
pa_log_debug("Using %s memory pool with %u slots of size %s each, total size is %s",
p->memory.shared ? "shared" : "private",
p->n_blocks,
pa_bytes_snprint(t1, sizeof(t1), (unsigned) p->block_size),
pa_bytes_snprint(t2, sizeof(t2), (unsigned) (p->n_blocks * p->block_size)));
memset(&p->stat, 0, sizeof(p->stat));
pa_atomic_store(&p->n_init, 0);