]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
percpu: skip chunks if the alloc does not fit in the contig hint
authorDennis Zhou (Facebook) <dennisszhou@gmail.com>
Mon, 24 Jul 2017 23:02:14 +0000 (19:02 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 26 Jul 2017 21:41:05 +0000 (17:41 -0400)
This patch adds chunk->contig_bits_start to keep track of the contig
hint's offset and the check to skip the chunk if it does not fit. If
the chunk's contig hint starting offset cannot satisfy an allocation,
the allocator assumes there is enough memory pressure in this chunk to
either use a different chunk or create a new one. This accepts a less
tight packing for a smoother latency curve.

Signed-off-by: Dennis Zhou <dennisszhou@gmail.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
mm/percpu-internal.h
mm/percpu.c

index e60e04966d96fcb40d2cec0c55914cf86bfb816c..7065faf74b46b20e5f9647cd09d228ad307d711f 100644 (file)
@@ -29,6 +29,8 @@ struct pcpu_chunk {
        struct list_head        list;           /* linked to pcpu_slot lists */
        int                     free_bytes;     /* free bytes in the chunk */
        int                     contig_bits;    /* max contiguous size hint */
+       int                     contig_bits_start; /* contig_bits starting
+                                                     offset */
        void                    *base_addr;     /* base address of this chunk */
 
        unsigned long           *alloc_map;     /* allocation map */
index 83abb190ca5a3e4afafeb5299279fb9e37f4384d..734745a0c9b6c2b140a2b7ebb6449fe7a4006328 100644 (file)
@@ -400,12 +400,14 @@ static inline int pcpu_cnt_pop_pages(struct pcpu_chunk *chunk, int bit_off,
  * @bit_off: chunk offset
  * @bits: size of free area
  *
- * This updates the chunk's contig hint given a free area.
+ * This updates the chunk's contig hint and starting offset given a free area.
  */
 static void pcpu_chunk_update(struct pcpu_chunk *chunk, int bit_off, int bits)
 {
-       if (bits > chunk->contig_bits)
+       if (bits > chunk->contig_bits) {
+               chunk->contig_bits_start = bit_off;
                chunk->contig_bits = bits;
+       }
 }
 
 /**
@@ -416,6 +418,7 @@ static void pcpu_chunk_update(struct pcpu_chunk *chunk, int bit_off, int bits)
  *
  * Updates:
  *      chunk->contig_bits
+ *      chunk->contig_bits_start
  *      nr_empty_pop_pages
  */
 static void pcpu_chunk_refresh_hint(struct pcpu_chunk *chunk)
@@ -646,6 +649,17 @@ static int pcpu_find_block_fit(struct pcpu_chunk *chunk, int alloc_bits,
        int bit_off, bits;
        int re; /* region end */
 
+       /*
+        * Check to see if the allocation can fit in the chunk's contig hint.
+        * This is an optimization to prevent scanning by assuming if it
+        * cannot fit in the global hint, there is memory pressure and creating
+        * a new chunk would happen soon.
+        */
+       bit_off = ALIGN(chunk->contig_bits_start, align) -
+                 chunk->contig_bits_start;
+       if (bit_off + alloc_bits > chunk->contig_bits)
+               return -1;
+
        pcpu_for_each_unpop_region(chunk->alloc_map, bit_off, re,
                                   chunk->first_bit,
                                   pcpu_chunk_map_bits(chunk)) {