[pulseaudio-commits] r2431 - in /branches/glitch-free/src/pulsecore: memblock.c memblock.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 15 13:39:47 PDT 2008


Author: lennart
Date: Thu May 15 22:39:46 2008
New Revision: 2431

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2431&root=pulseaudio&view=rev
Log:
increase default mempool size, make mempool_slot an abstract struct because the only fields it defined where actually unused

Modified:
    branches/glitch-free/src/pulsecore/memblock.c
    branches/glitch-free/src/pulsecore/memblock.h

Modified: branches/glitch-free/src/pulsecore/memblock.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/memblock.c?rev=2431&root=pulseaudio&r1=2430&r2=2431&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/memblock.c (original)
+++ branches/glitch-free/src/pulsecore/memblock.c Thu May 15 22:39:46 2008
@@ -46,8 +46,12 @@
 
 #include "memblock.h"
 
-#define PA_MEMPOOL_SLOTS_MAX 512
-#define PA_MEMPOOL_SLOT_SIZE (32*1024)
+/* We can allocate 64*1024*1024 bytes at maximum. That's 64MB. Please
+ * note that the footprint is usually much smaller, since the data is
+ * stored in SHM and our OS does not commit the memory before we use
+ * it for the first time. */
+#define PA_MEMPOOL_SLOTS_MAX 1024
+#define PA_MEMPOOL_SLOT_SIZE (64*1024)
 
 #define PA_MEMEXPORT_SLOTS_MAX 128
 
@@ -127,11 +131,6 @@
     PA_LLIST_FIELDS(pa_memexport);
 };
 
-struct mempool_slot {
-    PA_LLIST_FIELDS(struct mempool_slot);
-    /* the actual data follows immediately hereafter */
-};
-
 struct pa_mempool {
     pa_semaphore *semaphore;
     pa_mutex *mutex;
@@ -204,9 +203,7 @@
     pa_memblock *b;
 
     pa_assert(p);
-
-    if (length <= 0)
-        length = pa_mempool_block_size_max(p);
+    pa_assert(length);
 
     if (!(b = pa_memblock_new_pool(p, length)))
         b = memblock_new_appended(p, length);
@@ -219,12 +216,12 @@
     pa_memblock *b;
 
     pa_assert(p);
-    pa_assert(length > 0);
+    pa_assert(length);
 
     /* If -1 is passed as length we choose the size for the caller. */
 
     if (length == (size_t) -1)
-        length = p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) - PA_ALIGN(sizeof(pa_memblock));
+        length = p->block_size - PA_ALIGN(sizeof(pa_memblock));
 
     b = pa_xmalloc(PA_ALIGN(sizeof(pa_memblock)) + length);
     PA_REFCNT_INIT(b);
@@ -265,11 +262,9 @@
     return slot;
 }
 
-/* No lock necessary */
-static void* mempool_slot_data(struct mempool_slot *slot) {
-    pa_assert(slot);
-
-    return (uint8_t*) slot + PA_ALIGN(sizeof(struct mempool_slot));
+/* No lock necessary, totally redundant anyway */
+static inline void* mempool_slot_data(struct mempool_slot *slot) {
+    return slot;
 }
 
 /* No lock necessary */
@@ -298,7 +293,7 @@
     struct mempool_slot *slot;
 
     pa_assert(p);
-    pa_assert(length > 0);
+    pa_assert(length);
 
     /* If -1 is passed as length we choose the size for the caller: we
      * take the largest size that fits in one of our slots. */
@@ -306,7 +301,7 @@
     if (length == (size_t) -1)
         length = pa_mempool_block_size_max(p);
 
-    if (p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) >= PA_ALIGN(sizeof(pa_memblock)) + length) {
+    if (p->block_size >= PA_ALIGN(sizeof(pa_memblock)) + length) {
 
         if (!(slot = mempool_allocate_slot(p)))
             return NULL;
@@ -315,7 +310,7 @@
         b->type = PA_MEMBLOCK_POOL;
         pa_atomic_ptr_store(&b->data, (uint8_t*) b + PA_ALIGN(sizeof(pa_memblock)));
 
-    } else if (p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) >= length) {
+    } else if (p->block_size >= length) {
 
         if (!(slot = mempool_allocate_slot(p)))
             return NULL;
@@ -327,7 +322,7 @@
         pa_atomic_ptr_store(&b->data, mempool_slot_data(slot));
 
     } else {
-        pa_log_debug("Memory block too large for pool: %lu > %lu", (unsigned long) length, (unsigned long) (p->block_size - PA_ALIGN(sizeof(struct mempool_slot))));
+        pa_log_debug("Memory block too large for pool: %lu > %lu", (unsigned long) length, (unsigned long) p->block_size);
         pa_atomic_inc(&p->stat.n_too_large_for_pool);
         return NULL;
     }
@@ -350,7 +345,7 @@
     pa_assert(p);
     pa_assert(d);
     pa_assert(length != (size_t) -1);
-    pa_assert(length > 0);
+    pa_assert(length);
 
     if (!(b = pa_flist_pop(PA_STATIC_FLIST_GET(unused_memblocks))))
         b = pa_xnew(pa_memblock, 1);
@@ -374,7 +369,7 @@
 
     pa_assert(p);
     pa_assert(d);
-    pa_assert(length > 0);
+    pa_assert(length);
     pa_assert(length != (size_t) -1);
     pa_assert(free_cb);
 
@@ -423,7 +418,6 @@
 /* No lock necessary */
 pa_bool_t pa_memblock_ref_is_one(pa_memblock *b) {
     int r;
-
     pa_assert(b);
 
     pa_assert_se((r = PA_REFCNT_VALUE(b)) > 0);
@@ -588,7 +582,7 @@
 
     pa_atomic_dec(&b->pool->stat.n_allocated_by_type[b->type]);
 
-    if (b->length <= b->pool->block_size - PA_ALIGN(sizeof(struct mempool_slot))) {
+    if (b->length <= b->pool->block_size) {
         struct mempool_slot *slot;
 
         if ((slot = mempool_allocate_slot(b->pool))) {
@@ -676,7 +670,7 @@
         pa_mutex_unlock(seg->import->mutex);
 }
 
-pa_mempool* pa_mempool_new(int shared) {
+pa_mempool* pa_mempool_new(pa_bool_t shared) {
     pa_mempool *p;
 
     p = pa_xnew(pa_mempool, 1);
@@ -690,8 +684,6 @@
 
     p->n_blocks = PA_MEMPOOL_SLOTS_MAX;
 
-    pa_assert(p->block_size > PA_ALIGN(sizeof(struct mempool_slot)));
-
     if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) {
         pa_xfree(p);
         return NULL;
@@ -747,7 +739,7 @@
 size_t pa_mempool_block_size_max(pa_mempool *p) {
     pa_assert(p);
 
-    return p->block_size - PA_ALIGN(sizeof(struct mempool_slot)) - PA_ALIGN(sizeof(pa_memblock));
+    return p->block_size - PA_ALIGN(sizeof(pa_memblock));
 }
 
 /* No lock necessary */
@@ -764,9 +756,7 @@
             ;
 
     while ((slot = pa_flist_pop(list))) {
-        pa_shm_punch(&p->memory,
-                     (uint8_t*) slot - (uint8_t*) p->memory.ptr + PA_ALIGN(sizeof(struct mempool_slot)),
-                     p->block_size - PA_ALIGN(sizeof(struct mempool_slot)));
+        pa_shm_punch(&p->memory, (uint8_t*) slot - (uint8_t*) p->memory.ptr, p->block_size);
 
         while (pa_flist_push(p->free_slots, slot))
             ;

Modified: branches/glitch-free/src/pulsecore/memblock.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/memblock.h?rev=2431&root=pulseaudio&r1=2430&r2=2431&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/memblock.h (original)
+++ branches/glitch-free/src/pulsecore/memblock.h Thu May 15 22:39:46 2008
@@ -119,7 +119,7 @@
 pa_memblock *pa_memblock_will_need(pa_memblock *b);
 
 /* The memory block manager */
-pa_mempool* pa_mempool_new(int shared);
+pa_mempool* pa_mempool_new(pa_bool_t shared);
 void pa_mempool_free(pa_mempool *p);
 const pa_mempool_stat* pa_mempool_get_stat(pa_mempool *p);
 void pa_mempool_vacuum(pa_mempool *p);




More information about the pulseaudio-commits mailing list