]> xenbits.xensource.com Git - osstest/rumprun.git/commitdiff
memalloc: avoid list ping-pong when allocating from core
authorAntti Kantee <pooka@iki.fi>
Tue, 3 Nov 2015 21:44:51 +0000 (21:44 +0000)
committerAntti Kantee <pooka@iki.fi>
Tue, 3 Nov 2015 21:44:51 +0000 (21:44 +0000)
lib/libbmk_core/memalloc.c

index 00b4a2eec675cd7b8cd73b809d1fcd25672b8577..77a658c678a646ac30601d35d38149a8bc5b4a13 100644 (file)
@@ -89,7 +89,38 @@ static unsigned nmalloc[NBUCKETS];
 #define malloc_lock()
 #define malloc_unlock()
 
-static void morecore(int);
+static struct memalloc_freeblk *
+morecore(int bucket)
+{
+       struct memalloc_freeblk *frb;
+       unsigned long sz;               /* size of desired block */
+       unsigned long amt;              /* amount to allocate */
+       unsigned long nblks;            /* how many blocks we get */
+
+       if (bucket < pagebucket) {
+               amt = 0;
+               nblks = BMK_PCPU_PAGE_SIZE / (1<<(bucket + MINSHIFT));
+               sz = BMK_PCPU_PAGE_SIZE / nblks;
+       } else {
+               amt = bucket - pagebucket;
+               nblks = 1;
+               sz = 0; /* dummy */
+       }
+
+       if ((frb = bmk_pgalloc(amt)) == NULL)
+               return NULL;
+
+       /*
+        * Add new memory allocated to that on
+        * free list for this hash bucket.  Return one block.
+        */
+       while (--nblks) {
+               LIST_INSERT_HEAD(&freebuckets[bucket], frb, entries);
+               frb = (struct memalloc_freeblk *)
+                   (void *)((char *)frb+(unsigned long)sz);
+       }
+       return frb;
+}
 
 void
 bmk_memalloc_init(void)
@@ -157,13 +188,13 @@ bmk_memalloc(unsigned long nbytes, unsigned long align, enum bmk_memwho who)
         * request more memory from the system.
         */
        if ((frb = LIST_FIRST(&freebuckets[bucket])) == NULL) {
-               morecore(bucket);
-               if ((frb = LIST_FIRST(&freebuckets[bucket])) == NULL) {
+               if ((frb = morecore(bucket)) == NULL) {
                        malloc_unlock();
                        return (NULL);
                }
+       } else {
+               LIST_REMOVE(frb, entries);
        }
-       LIST_REMOVE(frb, entries);
        hdr = (void *)frb;
 
        /* align op before returned memory */
@@ -213,42 +244,6 @@ bmk_memcalloc(unsigned long n, unsigned long size, enum bmk_memwho who)
        return v;
 }
 
-/*
- * Allocate more memory to the indicated bucket.
- */
-static void
-morecore(int bucket)
-{
-       struct memalloc_freeblk *frb;
-       unsigned long sz;               /* size of desired block */
-       unsigned long amt;              /* amount to allocate */
-       unsigned long nblks;            /* how many blocks we get */
-
-       if (bucket < pagebucket) {
-               amt = 0;
-               nblks = BMK_PCPU_PAGE_SIZE / (1<<(bucket + MINSHIFT));
-               sz = BMK_PCPU_PAGE_SIZE / nblks;
-       } else {
-               amt = bucket - pagebucket;
-               nblks = 1;
-               sz = 0; /* dummy */
-       }
-
-       if ((frb = bmk_pgalloc(amt)) == NULL)
-               return;
-
-       /*
-        * Add new memory allocated to that on
-        * free list for this hash bucket.
-        */
-
-       do {
-               LIST_INSERT_HEAD(&freebuckets[bucket], frb, entries);
-               frb = (struct memalloc_freeblk *)
-                   (void *)((char *)frb+(unsigned long)sz);
-       } while (--nblks);
-}
-
 void
 bmk_memfree(void *cp, enum bmk_memwho who)
 {