2020-06-17 07:15:32

by Yi Wang

[permalink] [raw]
Subject: [PATCH] mm, slab: Use kmem_cache_zalloc() instead of kmem_cache_alloc() with flag GFP_ZERO.

From: Liao Pingfang <[email protected]>

Use kmem_cache_zalloc instead of manually calling kmem_cache_alloc
with flag GFP_ZERO.

Signed-off-by: Liao Pingfang <[email protected]>
---
include/linux/slab.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/slab.h b/include/linux/slab.h
index 6d45488..1fa62d9 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -656,7 +656,7 @@ extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
*/
static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
{
- return kmem_cache_alloc(k, flags | __GFP_ZERO);
+ return kmem_cache_zalloc(k, flags);
}

/**
--
2.9.5


2020-06-17 07:18:31

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [PATCH] mm, slab: Use kmem_cache_zalloc() instead of kmem_cache_alloc() with flag GFP_ZERO.

> static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
> {
> - return kmem_cache_alloc(k, flags | __GFP_ZERO);
> + return kmem_cache_zalloc(k, flags);
> }

That's a good one.

2020-06-17 10:48:08

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH] mm, slab: Use kmem_cache_zalloc() instead of kmem_cache_alloc() with flag GFP_ZERO.

On 6/17/20 9:15 AM, Yi Wang wrote:
> From: Liao Pingfang <[email protected]>
>
> Use kmem_cache_zalloc instead of manually calling kmem_cache_alloc
> with flag GFP_ZERO.
>
> Signed-off-by: Liao Pingfang <[email protected]>
> ---
> include/linux/slab.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 6d45488..1fa62d9 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -656,7 +656,7 @@ extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
> */
> static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
> {
> - return kmem_cache_alloc(k, flags | __GFP_ZERO);
> + return kmem_cache_zalloc(k, flags);

Did you test this patch?

> }
>
> /**
>

2020-06-17 11:23:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] mm, slab: Use kmem_cache_zalloc() instead of kmem_cache_alloc() with flag GFP_ZERO.

Hi Yi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mmotm/master]

url: https://github.com/0day-ci/linux/commits/Yi-Wang/mm-slab-Use-kmem_cache_zalloc-instead-of-kmem_cache_alloc-with-flag-GFP_ZERO/20200617-151513
base: git://git.cmpxchg.org/linux-mmotm.git master
config: nds32-defconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
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 COMPILER=gcc-9.3.0 make.cross ARCH=nds32

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/linux/irq.h:21,
from include/asm-generic/hardirq.h:13,
from ./arch/nds32/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:9,
from include/linux/highmem.h:10,
from include/linux/pagemap.h:11,
from fs//crypto/crypto.c:23:
include/linux/slab.h: In function 'kmem_cache_zalloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'fscrypt_get_ctx':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'fscrypt_initialize':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from include/linux/irq.h:21,
from include/asm-generic/hardirq.h:13,
from ./arch/nds32/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:9,
from include/linux/highmem.h:10,
from include/linux/pagemap.h:11,
from fs//ext4/page-io.c:13:
include/linux/slab.h: In function 'kmem_cache_zalloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'ext4_init_io_end':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from include/linux/genhd.h:16,
from include/linux/blkdev.h:11,
from include/linux/backing-dev.h:15,
from fs//fuse/fuse_i.h:23,
from fs//fuse/dev.c:9:
include/linux/slab.h: In function 'kmem_cache_zalloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function '__fuse_request_alloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from include/linux/irq.h:21,
from include/asm-generic/hardirq.h:13,
from ./arch/nds32/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:9,
from include/linux/highmem.h:10,
from include/linux/pagemap.h:11,
from include/linux/buffer_head.h:14,
from include/linux/jbd2.h:23,
from fs//jbd2/transaction.c:19:
include/linux/slab.h: In function 'kmem_cache_zalloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'start_this_handle':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'jbd2__journal_start':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from include/linux/irq.h:21,
from include/asm-generic/hardirq.h:13,
from ./arch/nds32/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:9,
from include/linux/highmem.h:10,
from include/linux/pagemap.h:11,
from include/linux/buffer_head.h:14,
from include/linux/jbd2.h:23,
from fs//jbd2/journal.c:25:
include/linux/slab.h: In function 'kmem_cache_zalloc':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/slab.h: In function 'jbd2_journal_add_journal_head':
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/slab.h:678:21: error: inlining failed in call to always_inline 'kmem_cache_zalloc': recursive inlining
678 | static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
| ^~~~~~~~~~~~~~~~~
include/linux/slab.h:680:9: note: called from here
680 | return kmem_cache_zalloc(k, flags);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/kmem_cache_zalloc +678 include/linux/slab.h

10cef602950291 Matt Mackall 2006-01-08 674
81cda6626178cd Christoph Lameter 2007-07-17 675 /*
81cda6626178cd Christoph Lameter 2007-07-17 676 * Shortcuts
81cda6626178cd Christoph Lameter 2007-07-17 677 */
81cda6626178cd Christoph Lameter 2007-07-17 @678 static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
81cda6626178cd Christoph Lameter 2007-07-17 679 {
3b0c169b666d29 Liao Pingfang 2020-06-17 680 return kmem_cache_zalloc(k, flags);
81cda6626178cd Christoph Lameter 2007-07-17 681 }
81cda6626178cd Christoph Lameter 2007-07-17 682

:::::: The code at line 678 was first introduced by commit
:::::: 81cda6626178cd55297831296ba8ecedbfd8b52d Slab allocators: Cleanup zeroing allocations

:::::: TO: Christoph Lameter <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (8.73 kB)
.config.gz (10.43 kB)
Download all attachments

2020-06-17 23:56:32

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] mm, slab: Use kmem_cache_zalloc() instead of kmem_cache_alloc() with flag GFP_ZERO.

Hi Yi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mmotm/master]

url: https://github.com/0day-ci/linux/commits/Yi-Wang/mm-slab-Use-kmem_cache_zalloc-instead-of-kmem_cache_alloc-with-flag-GFP_ZERO/20200617-151513
base: git://git.cmpxchg.org/linux-mmotm.git master
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce (this is a W=1 build):
# save the attached .config to linux build tree
make W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/mtd/ubi/attach.o: warning: objtool: ubi_add_to_av()+0x1c4: unreachable instruction
--
>> mm/slab_common.o: warning: objtool: create_kmalloc_caches()+0x44: unreachable instruction
--
>> fs/btrfs/free-space-cache.o: warning: objtool: btrfs_trim_block_group()+0x201: unreachable instruction
--
>> drivers/acpi/acpica/psutils.o: warning: objtool: acpi_ps_create_scope_op()+0x12: unreachable instruction
--
>> fs/fuse/dev.o: warning: objtool: fuse_force_forget()+0x42: unreachable instruction

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (1.31 kB)
.config.gz (46.49 kB)
Download all attachments