* [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32
@ 2021-03-12 8:03 Jianqun Xu
2021-03-12 9:29 ` Christoph Hellwig
2021-03-12 13:20 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Jianqun Xu @ 2021-03-12 8:03 UTC (permalink / raw)
To: cl, penberg, rientjes, iamjoonsoo.kim, akpm
Cc: linux-mm, linux-kernel, linux-rockchip, Jianqun Xu
The flag GFP_DMA32 only effect in kmalloc_large currently.
This patch will create caches with GFP_DMA32 to support kmalloc with
size under KMALLOC_MAX_CACHE_SIZE.
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
---
include/linux/slab.h | 7 +++++++
mm/slab_common.c | 14 ++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index be4ba5867ac5..f4317663d148 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -307,6 +307,9 @@ enum kmalloc_cache_type {
KMALLOC_RECLAIM,
#ifdef CONFIG_ZONE_DMA
KMALLOC_DMA,
+#endif
+#ifdef CONFIG_ZONE_DMA32
+ KMALLOC_DMA32,
#endif
NR_KMALLOC_TYPES
};
@@ -331,6 +334,10 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
*/
return flags & __GFP_DMA ? KMALLOC_DMA : KMALLOC_RECLAIM;
#else
+#ifdef CONFIG_ZONE_DMA32
+ if (unlikely(flags & __GFP_DMA32))
+ return KMALLOC_DMA32;
+#endif
return flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : KMALLOC_NORMAL;
#endif
}
diff --git a/mm/slab_common.c b/mm/slab_common.c
index e981c80d216c..2a04736fe8f5 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -805,6 +805,20 @@ void __init create_kmalloc_caches(slab_flags_t flags)
}
}
#endif
+#ifdef CONFIG_ZONE_DMA32
+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
+ struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
+
+ if (s) {
+ unsigned int size = kmalloc_size(i);
+ const char *n = kmalloc_cache_name("dma32-kmalloc", size);
+
+ BUG_ON(!n);
+ kmalloc_caches[KMALLOC_DMA32][i] = create_kmalloc_cache(
+ n, size, SLAB_CACHE_DMA32 | flags, 0, 0);
+ }
+ }
+#endif
}
#endif /* !CONFIG_SLOB */
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32
2021-03-12 8:03 [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32 Jianqun Xu
@ 2021-03-12 9:29 ` Christoph Hellwig
2021-03-12 13:20 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-03-12 9:29 UTC (permalink / raw)
To: Jianqun Xu
Cc: cl, penberg, rientjes, iamjoonsoo.kim, akpm, linux-mm,
linux-kernel, linux-rockchip
On Fri, Mar 12, 2021 at 04:03:20PM +0800, Jianqun Xu wrote:
> The flag GFP_DMA32 only effect in kmalloc_large currently.
>
> This patch will create caches with GFP_DMA32 to support kmalloc with
> size under KMALLOC_MAX_CACHE_SIZE.
No. No new code should use GFP_DMA32, never mind through slab.
Please use the proper DMA APIs for your addressing needs.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32
2021-03-12 8:03 [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32 Jianqun Xu
2021-03-12 9:29 ` Christoph Hellwig
@ 2021-03-12 13:20 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2021-03-12 13:20 UTC (permalink / raw)
To: Jianqun Xu, cl, penberg, rientjes, iamjoonsoo.kim, akpm
Cc: kbuild-all, clang-built-linux, linux-mm, linux-kernel,
linux-rockchip, Jianqun Xu
[-- Attachment #1: Type: text/plain, Size: 4533 bytes --]
Hi Jianqun,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on hnaz-linux-mm/master]
url: https://github.com/0day-ci/linux/commits/Jianqun-Xu/mm-slab-kmalloc-with-GFP_DMA32-allocate-from-SLAB_CACHE_DMA32/20210312-160426
base: https://github.com/hnaz/linux-mm master
config: x86_64-randconfig-a006-20210312 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 7b153b43d3a14d76975039408c4b922beb576735)
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
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/93abfa9fa97332c9d5c1727fcf76b604b6da33de
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jianqun-Xu/mm-slab-kmalloc-with-GFP_DMA32-allocate-from-SLAB_CACHE_DMA32/20210312-160426
git checkout 93abfa9fa97332c9d5c1727fcf76b604b6da33de
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
All error/warnings (new ones prefixed by >>):
>> mm/slab_common.c:812:24: error: implicit declaration of function 'kmalloc_size' [-Werror,-Wimplicit-function-declaration]
unsigned int size = kmalloc_size(i);
^
>> mm/slab_common.c:813:20: error: implicit declaration of function 'kmalloc_cache_name' [-Werror,-Wimplicit-function-declaration]
const char *n = kmalloc_cache_name("dma32-kmalloc", size);
^
>> mm/slab_common.c:813:16: warning: incompatible integer to pointer conversion initializing 'const char *' with an expression of type 'int' [-Wint-conversion]
const char *n = kmalloc_cache_name("dma32-kmalloc", size);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 2 errors generated.
vim +/kmalloc_size +812 mm/slab_common.c
761
762 /*
763 * Create the kmalloc array. Some of the regular kmalloc arrays
764 * may already have been created because they were needed to
765 * enable allocations for slab creation.
766 */
767 void __init create_kmalloc_caches(slab_flags_t flags)
768 {
769 int i;
770 enum kmalloc_cache_type type;
771
772 for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) {
773 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
774 if (!kmalloc_caches[type][i])
775 new_kmalloc_cache(i, type, flags);
776
777 /*
778 * Caches that are not of the two-to-the-power-of size.
779 * These have to be created immediately after the
780 * earlier power of two caches
781 */
782 if (KMALLOC_MIN_SIZE <= 32 && i == 6 &&
783 !kmalloc_caches[type][1])
784 new_kmalloc_cache(1, type, flags);
785 if (KMALLOC_MIN_SIZE <= 64 && i == 7 &&
786 !kmalloc_caches[type][2])
787 new_kmalloc_cache(2, type, flags);
788 }
789 }
790
791 /* Kmalloc array is now usable */
792 slab_state = UP;
793
794 #ifdef CONFIG_ZONE_DMA
795 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
796 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
797
798 if (s) {
799 kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(
800 kmalloc_info[i].name[KMALLOC_DMA],
801 kmalloc_info[i].size,
802 SLAB_CACHE_DMA | flags, 0,
803 kmalloc_info[i].size);
804 }
805 }
806 #endif
807 #ifdef CONFIG_ZONE_DMA32
808 for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
809 struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i];
810
811 if (s) {
> 812 unsigned int size = kmalloc_size(i);
> 813 const char *n = kmalloc_cache_name("dma32-kmalloc", size);
814
815 BUG_ON(!n);
816 kmalloc_caches[KMALLOC_DMA32][i] = create_kmalloc_cache(
817 n, size, SLAB_CACHE_DMA32 | flags, 0, 0);
818 }
819 }
820 #endif
821 }
822 #endif /* !CONFIG_SLOB */
823
---
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: 36880 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-12 13:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 8:03 [PATCH] mm/slab: kmalloc with GFP_DMA32 allocate from SLAB_CACHE_DMA32 Jianqun Xu
2021-03-12 9:29 ` Christoph Hellwig
2021-03-12 13:20 ` kernel 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).