linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kmalloc_index optimization(code size & runtime stable)
@ 2020-04-17  2:03 Bernard Zhao
  2020-04-17  3:23 ` Matthew Wilcox
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bernard Zhao @ 2020-04-17  2:03 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, linux-mm, linux-kernel
  Cc: kernel, Bernard Zhao

kmalloc_index inline function code size optimization and runtime
performance stability optimization. After optimization, the function
kmalloc_index is more stable, the size will never affecte the function`s
execution efficiency.
And follow test data shows that the performance of new optimization
exceeds the original algorithm when applying for more than 512 Bytes
(include 512B).And new optimization runtime is more stable than before.
Test platform:install vmware ubuntu 16.04, ram 2G, cpu 1, i5-8500 3.00GHz
Compiler: gcc -O2 optimization, gcc version 5.4.0.
Just test diff code part.
Follow is detailed test data:
            size        time/Per 100 million times
                        old fun		new fun with optimise
		8	203777		241934
		16	245611		409278
		32	236384		408419
		64	275499		447732
		128	354909		416439
		256	360472		406598
		512	431072		409168
		1024	463822		407401
        2 * 1024	548519		407710
        4 * 1024	623378		422326
        8 * 1024	655932		407457
       16 * 1024	744673		417574
       32 * 1024	824889		415316
       64 * 1024	854374		408577
      128 * 1024	968079		433582
      256 * 1024	985527		412080
      512 * 1024	1196877		448199
     1024 * 1024	1310315		448969
2  * 1024 * 1024	1367441		513117
4  * 1024 * 1024	1264623		415019
8  * 1024 * 1024	1255727		417197
16 * 1024 * 1024	1401431		411087
32 * 1024 * 1024	1440415		416616
64 * 1024 * 1024	1428122		417459

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 include/linux/slab.h | 61 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 6d45488..6ccee7a 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -301,6 +301,22 @@ static inline void __check_heap_object(const void *ptr, unsigned long n,
 #define SLAB_OBJ_MIN_SIZE      (KMALLOC_MIN_SIZE < 16 ? \
                                (KMALLOC_MIN_SIZE) : 16)
 
+#ifndef CONFIG_SLOB
+/*
+ * This used to show the relation between size`s last (most-significant)
+ * bit set & index of kmalloc_info[]
+ * If size%2 ==0, then fls - 1, else fls(round up)
+ * size  8(b 1000)-(b 1xxx)-16(b 10000)-(b 1xxxx)-32(b 100000)-(b 1xxxxx)
+ *       |            |          |           |            |           |
+ * index 3            4          4           5            5           6
+ *       64(b 1000000)-(b 1xxxxxx)-128(b 10000000)-(b 1xxxxxxx)-256....
+ *          |           |              |            |            |
+ *          6           7              7            8            8...
+ */
+#define KMALLOC_SIZE_POW_2_SHIFT_BIT (2)
+#define KMALLOC_SIZE_POW_2_INDEX_BIT (1)
+#endif
+
 /*
  * Whenever changing this, take care of that kmalloc_type() and
  * create_kmalloc_caches() still work as intended.
@@ -358,30 +374,27 @@ static __always_inline unsigned int kmalloc_index(size_t size)
 		return 1;
 	if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
 		return 2;
-	if (size <=          8) return 3;
-	if (size <=         16) return 4;
-	if (size <=         32) return 5;
-	if (size <=         64) return 6;
-	if (size <=        128) return 7;
-	if (size <=        256) return 8;
-	if (size <=        512) return 9;
-	if (size <=       1024) return 10;
-	if (size <=   2 * 1024) return 11;
-	if (size <=   4 * 1024) return 12;
-	if (size <=   8 * 1024) return 13;
-	if (size <=  16 * 1024) return 14;
-	if (size <=  32 * 1024) return 15;
-	if (size <=  64 * 1024) return 16;
-	if (size <= 128 * 1024) return 17;
-	if (size <= 256 * 1024) return 18;
-	if (size <= 512 * 1024) return 19;
-	if (size <= 1024 * 1024) return 20;
-	if (size <=  2 * 1024 * 1024) return 21;
-	if (size <=  4 * 1024 * 1024) return 22;
-	if (size <=  8 * 1024 * 1024) return 23;
-	if (size <=  16 * 1024 * 1024) return 24;
-	if (size <=  32 * 1024 * 1024) return 25;
-	if (size <=  64 * 1024 * 1024) return 26;
+
+	if (size <= 8)
+		return 3;
+
+	/* size over KMALLOC_MAX_SIZE should trigger BUG */
+	if (size <= KMALLOC_MAX_SIZE) {
+		/*
+		 * kmalloc_info[index]
+		 * size  8----16----32----64----128---256---512---1024---2048.
+		 *       |  |  |  |  |  |  |  |  |  |  |  |  |  |   |  |   |
+		 * index 3  4  4  5  5  6  6  7  7  8  8  9  9  10  10 11  11
+		 */
+
+		high_bit = fls((int)size);
+
+		if (size == (2 << (high_bit - KMALLOC_SIZE_POW_2_SHIFT_BIT)))
+			return (high_bit - KMALLOC_SIZE_POW_2_INDEX_BIT);
+
+		return high_bit;
+	}
+
 	BUG();
 
 	/* Will never be reached. Needed because the compiler may complain */
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] kmalloc_index optimization(code size & runtime stable)
  2020-04-17  2:03 [PATCH] kmalloc_index optimization(code size & runtime stable) Bernard Zhao
@ 2020-04-17  3:23 ` Matthew Wilcox
  2020-04-17  4:55   ` 赵军奎
  2020-04-20  5:33 ` kbuild test robot
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2020-04-17  3:23 UTC (permalink / raw)
  To: Bernard Zhao
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, linux-mm, linux-kernel, kernel

On Thu, Apr 16, 2020 at 07:03:30PM -0700, Bernard Zhao wrote:
> kmalloc_index inline function code size optimization and runtime
> performance stability optimization. After optimization, the function
> kmalloc_index is more stable, the size will never affecte the function`s
> execution efficiency.
> And follow test data shows that the performance of new optimization
> exceeds the original algorithm when applying for more than 512 Bytes
> (include 512B).And new optimization runtime is more stable than before.

That's all very well and good, but the vast majority of allocations
are less than 512 bytes in size!  Your numbers show that on average,
this patch makes the kernel slower!

>             size        time/Per 100 million times
>                         old fun		new fun with optimise
> 		8	203777		241934
> 		16	245611		409278
> 		32	236384		408419
> 		64	275499		447732
> 		128	354909		416439
> 		256	360472		406598
> 		512	431072		409168
> 		1024	463822		407401



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re:Re: [PATCH] kmalloc_index optimization(code size & runtime stable)
  2020-04-17  3:23 ` Matthew Wilcox
@ 2020-04-17  4:55   ` 赵军奎
  0 siblings, 0 replies; 6+ messages in thread
From: 赵军奎 @ 2020-04-17  4:55 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, linux-mm, linux-kernel, kernel

[-- Attachment #1: Type: text/plain, Size: 1676 bytes --]



From: Matthew Wilcox <willy@infradead.org>

Date: 2020-04-17 11:23:54
To:  Bernard Zhao <bernard@vivo.com>
Cc:  Christoph Lameter <cl@linux.com>,Pekka Enberg <penberg@kernel.org>,David Rientjes <rientjes@google.com>,Joonsoo Kim <iamjoonsoo.kim@lge.com>,Andrew Morton <akpm@linux-foundation.org>,linux-mm@kvack.org,linux-kernel@vger.kernel.org,kernel@vivo.com
Subject: Re: [PATCH] kmalloc_index optimization(code size & runtime stable)>On Thu, Apr 16, 2020 at 07:03:30PM -0700, Bernard Zhao wrote:
>> kmalloc_index inline function code size optimization and runtime
>> performance stability optimization. After optimization, the function
>> kmalloc_index is more stable, the size will never affecte the function`s
>> execution efficiency.
>> And follow test data shows that the performance of new optimization
>> exceeds the original algorithm when applying for more than 512 Bytes
>> (include 512B).And new optimization runtime is more stable than before.
>
>That's all very well and good, but the vast majority of allocations
>are less than 512 bytes in size!  Your numbers show that on average,
>this patch makes the kernel slower!
>


    This is indeed the case, the new algorithm is stable at a time level, but 
there is a certain performance loss for relatively small memory(little than 512).
I will continue to pay attention to this part later.  Thanks.


>>             size        time/Per 100 million times.us
>>                         old fun		new fun with optimise
>> 		8	203777		241934
>> 		16	245611		409278
>> 		32	236384		408419
>> 		64	275499		447732
>> 		128	354909		416439
>> 		256	360472		406598
>> 		512	431072		409168
>> 		1024	463822		407401
>





[-- Attachment #2: Type: text/html, Size: 2180 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kmalloc_index optimization(code size & runtime stable)
  2020-04-17  2:03 [PATCH] kmalloc_index optimization(code size & runtime stable) Bernard Zhao
  2020-04-17  3:23 ` Matthew Wilcox
@ 2020-04-20  5:33 ` kbuild test robot
  2020-04-20 11:41 ` kbuild test robot
  2020-04-20 13:20 ` kbuild test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2020-04-20  5:33 UTC (permalink / raw)
  To: Bernard Zhao, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton, linux-mm, linux-kernel, kernel
  Cc: kbuild-all, clang-built-linux, Linux Memory Management List, kernel

[-- Attachment #1: Type: text/plain, Size: 9100 bytes --]

Hi Bernard,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc1 next-20200416]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Bernard-Zhao/kmalloc_index-optimization-code-size-runtime-stable/20200417-100445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2fcd80144b93ff90836a44f2054b4d82133d3a85
config: powerpc-defconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 40d139c620f83509fe18acbff5ec358298e99def)
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:15:
   In file included from include/linux/socket.h:8:
   In file included from include/linux/uio.h:10:
   In file included from include/crypto/hash.h:11:
   In file included from include/linux/crypto.h:19:
>> include/linux/slab.h:390:3: error: use of undeclared identifier 'high_bit'
                   high_bit = fls((int)size);
                   ^
   include/linux/slab.h:392:22: error: use of undeclared identifier 'high_bit'
                   if (size == (2 << (high_bit - KMALLOC_SIZE_POW_2_SHIFT_BIT)))
                                      ^
   include/linux/slab.h:393:12: error: use of undeclared identifier 'high_bit'
                           return (high_bit - KMALLOC_SIZE_POW_2_INDEX_BIT);
                                   ^
   include/linux/slab.h:395:10: error: use of undeclared identifier 'high_bit'
                   return high_bit;
                          ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:87:11: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds]
                   return (set->sig[3] | set->sig[2] |
                           ^        ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:87:25: warning: array index 2 is past the end of the array (which contains 1 element) [-Warray-bounds]
                   return (set->sig[3] | set->sig[2] |
                                         ^        ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:88:4: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
                           set->sig[1] | set->sig[0]) == 0;
                           ^        ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:90:11: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
                   return (set->sig[1] | set->sig[0]) == 0;
                           ^        ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:103:11: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds]
                   return  (set1->sig[3] == set2->sig[3]) &&
                            ^         ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:103:27: warning: array index 3 is past the end of the array (which contains 1 element) [-Warray-bounds]
                   return  (set1->sig[3] == set2->sig[3]) &&
                                            ^         ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:
   In file included from include/linux/sched/signal.h:6:
   include/linux/signal.h:104:5: warning: array index 2 is past the end of the array (which contains 1 element) [-Warray-bounds]
                           (set1->sig[2] == set2->sig[2]) &&
                            ^         ~
   arch/powerpc/include/uapi/asm/signal.h:18:2: note: array 'sig' declared here
           unsigned long sig[_NSIG_WORDS];
           ^
   In file included from arch/powerpc/kernel/asm-offsets.c:14:
   In file included from include/linux/compat.h:17:
   In file included from include/linux/fs.h:34:
   In file included from include/linux/percpu-rwsem.h:7:
   In file included from include/linux/rcuwait.h:6:

vim +/high_bit +390 include/linux/slab.h

   356	
   357	/*
   358	 * Figure out which kmalloc slab an allocation of a certain size
   359	 * belongs to.
   360	 * 0 = zero alloc
   361	 * 1 =  65 .. 96 bytes
   362	 * 2 = 129 .. 192 bytes
   363	 * n = 2^(n-1)+1 .. 2^n
   364	 */
   365	static __always_inline unsigned int kmalloc_index(size_t size)
   366	{
   367		if (!size)
   368			return 0;
   369	
   370		if (size <= KMALLOC_MIN_SIZE)
   371			return KMALLOC_SHIFT_LOW;
   372	
   373		if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
   374			return 1;
   375		if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
   376			return 2;
   377	
   378		if (size <= 8)
   379			return 3;
   380	
   381		/* size over KMALLOC_MAX_SIZE should trigger BUG */
   382		if (size <= KMALLOC_MAX_SIZE) {
   383			/*
   384			 * kmalloc_info[index]
   385			 * size  8----16----32----64----128---256---512---1024---2048.
   386			 *       |  |  |  |  |  |  |  |  |  |  |  |  |  |   |  |   |
   387			 * index 3  4  4  5  5  6  6  7  7  8  8  9  9  10  10 11  11
   388			 */
   389	
 > 390			high_bit = fls((int)size);
   391	
   392			if (size == (2 << (high_bit - KMALLOC_SIZE_POW_2_SHIFT_BIT)))
   393				return (high_bit - KMALLOC_SIZE_POW_2_INDEX_BIT);
   394	
   395			return high_bit;
   396		}
   397	
   398		BUG();
   399	
   400		/* Will never be reached. Needed because the compiler may complain */
   401		return -1;
   402	}
   403	#endif /* !CONFIG_SLOB */
   404	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 26134 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kmalloc_index optimization(code size & runtime stable)
  2020-04-17  2:03 [PATCH] kmalloc_index optimization(code size & runtime stable) Bernard Zhao
  2020-04-17  3:23 ` Matthew Wilcox
  2020-04-20  5:33 ` kbuild test robot
@ 2020-04-20 11:41 ` kbuild test robot
  2020-04-20 13:20 ` kbuild test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2020-04-20 11:41 UTC (permalink / raw)
  To: Bernard Zhao, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton, linux-mm, linux-kernel, kernel
  Cc: kbuild-all, Linux Memory Management List, kernel

[-- Attachment #1: Type: text/plain, Size: 3601 bytes --]

Hi Bernard,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc2 next-20200420]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Bernard-Zhao/kmalloc_index-optimization-code-size-runtime-stable/20200417-100445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2fcd80144b93ff90836a44f2054b4d82133d3a85
config: s390-zfcpdump_defconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=s390 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from include/linux/kvm_host.h:18,
                    from arch/s390/kernel/asm-offsets.c:11:
   include/linux/slab.h: In function 'kmalloc_index':
>> include/linux/slab.h:390:3: error: 'high_bit' undeclared (first use in this function); did you mean 'assign_bit'?
     390 |   high_bit = fls((int)size);
         |   ^~~~~~~~
         |   assign_bit
   include/linux/slab.h:390:3: note: each undeclared identifier is reported only once for each function it appears in
   make[2]: *** [scripts/Makefile.build:100: arch/s390/kernel/asm-offsets.s] Error 1
   make[2]: Target '__build' not remade because of errors.
   make[1]: *** [Makefile:1141: prepare0] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:180: sub-make] Error 2
   40 real  5 user  12 sys  44.33% cpu 	make prepare

vim +390 include/linux/slab.h

   356	
   357	/*
   358	 * Figure out which kmalloc slab an allocation of a certain size
   359	 * belongs to.
   360	 * 0 = zero alloc
   361	 * 1 =  65 .. 96 bytes
   362	 * 2 = 129 .. 192 bytes
   363	 * n = 2^(n-1)+1 .. 2^n
   364	 */
   365	static __always_inline unsigned int kmalloc_index(size_t size)
   366	{
   367		if (!size)
   368			return 0;
   369	
   370		if (size <= KMALLOC_MIN_SIZE)
   371			return KMALLOC_SHIFT_LOW;
   372	
   373		if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
   374			return 1;
   375		if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
   376			return 2;
   377	
   378		if (size <= 8)
   379			return 3;
   380	
   381		/* size over KMALLOC_MAX_SIZE should trigger BUG */
   382		if (size <= KMALLOC_MAX_SIZE) {
   383			/*
   384			 * kmalloc_info[index]
   385			 * size  8----16----32----64----128---256---512---1024---2048.
   386			 *       |  |  |  |  |  |  |  |  |  |  |  |  |  |   |  |   |
   387			 * index 3  4  4  5  5  6  6  7  7  8  8  9  9  10  10 11  11
   388			 */
   389	
 > 390			high_bit = fls((int)size);
   391	
   392			if (size == (2 << (high_bit - KMALLOC_SIZE_POW_2_SHIFT_BIT)))
   393				return (high_bit - KMALLOC_SIZE_POW_2_INDEX_BIT);
   394	
   395			return high_bit;
   396		}
   397	
   398		BUG();
   399	
   400		/* Will never be reached. Needed because the compiler may complain */
   401		return -1;
   402	}
   403	#endif /* !CONFIG_SLOB */
   404	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 8007 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kmalloc_index optimization(code size & runtime stable)
  2020-04-17  2:03 [PATCH] kmalloc_index optimization(code size & runtime stable) Bernard Zhao
                   ` (2 preceding siblings ...)
  2020-04-20 11:41 ` kbuild test robot
@ 2020-04-20 13:20 ` kbuild test robot
  3 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2020-04-20 13:20 UTC (permalink / raw)
  To: Bernard Zhao, Christoph Lameter, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton, linux-mm, linux-kernel, kernel
  Cc: kbuild-all, Linux Memory Management List, kernel

[-- Attachment #1: Type: text/plain, Size: 4981 bytes --]

Hi Bernard,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc2 next-20200416]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Bernard-Zhao/kmalloc_index-optimization-code-size-runtime-stable/20200417-100445
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2fcd80144b93ff90836a44f2054b4d82133d3a85
config: ia64-allmodconfig (attached as .config)
compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=ia64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   WARNING: unmet direct dependencies detected for FRAME_POINTER
   Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
   Selected by
   - FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86
   scripts/Makefile.build:59: 'arch/ia64/kernel/palinfo.ko' 'arch/ia64/kernel/mca_recovery.ko' 'arch/ia64/kernel/err_inject.ko' will not be built even though obj-m is specified.
   scripts/Makefile.build:60: You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.
   In file included from include/linux/irq.h:21,
   from arch/ia64/include/asm/hardirq.h:19,
   from include/linux/hardirq.h:9,
   from include/linux/interrupt.h:11,
   from arch/ia64/include/asm/mca.h:17,
   from arch/ia64/kernel/asm-offsets.c:18:
   include/linux/slab.h: In function 'kmalloc_index':
>> include/linux/slab.h:390:3: error: 'high_bit' undeclared (first use in this function); did you mean
   390 | high_bit = fls((int)size);
   | ^~~~~~~~
   | assign_bit
   include/linux/slab.h:390:3: note: each undeclared identifier is reported only once for each function it appears in
   Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [scripts/Makefile.build:100: arch/ia64/kernel/asm-offsets.s] Error 1
   Target '__build' not remade because of errors.
   Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [Makefile:1141: prepare0] Error 2
   Target 'prepare' not remade because of errors.
   make: Makefile Module.symvers System.map arch block certs crypto drivers fs include init ipc kernel lib mm modules.builtin modules.builtin.modinfo modules.order net scripts security sound source usr virt vmlinux vmlinux.bin vmlinux.gz vmlinux.o [Makefile:180: sub-make] Error 2
   13 real 5 user 8 sys 99.31% cpu make prepare

vim +/high_bit +390 include/linux/slab.h

   356	
   357	/*
   358	 * Figure out which kmalloc slab an allocation of a certain size
   359	 * belongs to.
   360	 * 0 = zero alloc
   361	 * 1 =  65 .. 96 bytes
   362	 * 2 = 129 .. 192 bytes
   363	 * n = 2^(n-1)+1 .. 2^n
   364	 */
   365	static __always_inline unsigned int kmalloc_index(size_t size)
   366	{
   367		if (!size)
   368			return 0;
   369	
   370		if (size <= KMALLOC_MIN_SIZE)
   371			return KMALLOC_SHIFT_LOW;
   372	
   373		if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
   374			return 1;
   375		if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
   376			return 2;
   377	
   378		if (size <= 8)
   379			return 3;
   380	
   381		/* size over KMALLOC_MAX_SIZE should trigger BUG */
   382		if (size <= KMALLOC_MAX_SIZE) {
   383			/*
   384			 * kmalloc_info[index]
   385			 * size  8----16----32----64----128---256---512---1024---2048.
   386			 *       |  |  |  |  |  |  |  |  |  |  |  |  |  |   |  |   |
   387			 * index 3  4  4  5  5  6  6  7  7  8  8  9  9  10  10 11  11
   388			 */
   389	
 > 390			high_bit = fls((int)size);
   391	
   392			if (size == (2 << (high_bit - KMALLOC_SIZE_POW_2_SHIFT_BIT)))
   393				return (high_bit - KMALLOC_SIZE_POW_2_INDEX_BIT);
   394	
   395			return high_bit;
   396		}
   397	
   398		BUG();
   399	
   400		/* Will never be reached. Needed because the compiler may complain */
   401		return -1;
   402	}
   403	#endif /* !CONFIG_SLOB */
   404	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 57815 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-20 13:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-17  2:03 [PATCH] kmalloc_index optimization(code size & runtime stable) Bernard Zhao
2020-04-17  3:23 ` Matthew Wilcox
2020-04-17  4:55   ` 赵军奎
2020-04-20  5:33 ` kbuild test robot
2020-04-20 11:41 ` kbuild test robot
2020-04-20 13:20 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).