diff options
author | Gavin Guo <gavin.guo@canonical.com> | 2015-06-24 19:55:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-24 20:49:40 -0400 |
commit | 4066c33d0308f87e9a3b0c7fafb9141c0bfbfa77 (patch) | |
tree | a04cdc023db6cd938769617b44a398584219e2b0 | |
parent | 3693a84d3b8b2fd4db1f1b22f33793eb84a66420 (diff) |
mm/slab_common: support the slub_debug boot option on specific object size
The slub_debug=PU,kmalloc-xx cannot work because in the
create_kmalloc_caches() the s->name is created after the
create_kmalloc_cache() is called. The name is NULL in the
create_kmalloc_cache() so the kmem_cache_flags() would not set the
slub_debug flags to the s->flags. The fix here set up a kmalloc_names
string array for the initialization purpose and delete the dynamic name
creation of kmalloc_caches.
[akpm@linux-foundation.org: s/kmalloc_names/kmalloc_info/, tweak comment text]
Signed-off-by: Gavin Guo <gavin.guo@canonical.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/slab.h | 22 | ||||
-rw-r--r-- | mm/slab_common.c | 62 |
2 files changed, 61 insertions, 23 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index ffd24c830151..96f0ea506b5c 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -153,8 +153,30 @@ size_t ksize(const void *); | |||
153 | #define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN | 153 | #define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN |
154 | #define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN | 154 | #define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN |
155 | #define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN) | 155 | #define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN) |
156 | /* | ||
157 | * The KMALLOC_LOOP_LOW is the definition for the for loop index start number | ||
158 | * to create the kmalloc_caches object in create_kmalloc_caches(). The first | ||
159 | * and the second are 96 and 192. You can see that in the kmalloc_index(), if | ||
160 | * the KMALLOC_MIN_SIZE <= 32, then return 1 (96). If KMALLOC_MIN_SIZE <= 64, | ||
161 | * then return 2 (192). If the KMALLOC_MIN_SIZE is bigger than 64, we don't | ||
162 | * need to initialize 96 and 192. Go directly to start the KMALLOC_SHIFT_LOW. | ||
163 | */ | ||
164 | #if KMALLOC_MIN_SIZE <= 32 | ||
165 | #define KMALLOC_LOOP_LOW 1 | ||
166 | #elif KMALLOC_MIN_SIZE <= 64 | ||
167 | #define KMALLOC_LOOP_LOW 2 | ||
168 | #else | ||
169 | #define KMALLOC_LOOP_LOW KMALLOC_SHIFT_LOW | ||
170 | #endif | ||
171 | |||
156 | #else | 172 | #else |
157 | #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) | 173 | #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) |
174 | /* | ||
175 | * The KMALLOC_MIN_SIZE of slub/slab/slob is 2^3/2^5/2^3. So, even slab is used. | ||
176 | * The KMALLOC_MIN_SIZE <= 32. The kmalloc-96 and kmalloc-192 should also be | ||
177 | * initialized. | ||
178 | */ | ||
179 | #define KMALLOC_LOOP_LOW 1 | ||
158 | #endif | 180 | #endif |
159 | 181 | ||
160 | /* | 182 | /* |
diff --git a/mm/slab_common.c b/mm/slab_common.c index 999bb3424d44..84e14582a14c 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
@@ -784,6 +784,31 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags) | |||
784 | } | 784 | } |
785 | 785 | ||
786 | /* | 786 | /* |
787 | * kmalloc_info[] is to make slub_debug=,kmalloc-xx option work at boot time. | ||
788 | * kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is | ||
789 | * kmalloc-67108864. | ||
790 | */ | ||
791 | static struct { | ||
792 | const char *name; | ||
793 | unsigned long size; | ||
794 | } const kmalloc_info[] __initconst = { | ||
795 | {NULL, 0}, {"kmalloc-96", 96}, | ||
796 | {"kmalloc-192", 192}, {"kmalloc-8", 8}, | ||
797 | {"kmalloc-16", 16}, {"kmalloc-32", 32}, | ||
798 | {"kmalloc-64", 64}, {"kmalloc-128", 128}, | ||
799 | {"kmalloc-256", 256}, {"kmalloc-512", 512}, | ||
800 | {"kmalloc-1024", 1024}, {"kmalloc-2048", 2048}, | ||
801 | {"kmalloc-4096", 4096}, {"kmalloc-8192", 8192}, | ||
802 | {"kmalloc-16384", 16384}, {"kmalloc-32768", 32768}, | ||
803 | {"kmalloc-65536", 65536}, {"kmalloc-131072", 131072}, | ||
804 | {"kmalloc-262144", 262144}, {"kmalloc-524288", 524288}, | ||
805 | {"kmalloc-1048576", 1048576}, {"kmalloc-2097152", 2097152}, | ||
806 | {"kmalloc-4194304", 4194304}, {"kmalloc-8388608", 8388608}, | ||
807 | {"kmalloc-16777216", 16777216}, {"kmalloc-33554432", 33554432}, | ||
808 | {"kmalloc-67108864", 67108864} | ||
809 | }; | ||
810 | |||
811 | /* | ||
787 | * Create the kmalloc array. Some of the regular kmalloc arrays | 812 | * Create the kmalloc array. Some of the regular kmalloc arrays |
788 | * may already have been created because they were needed to | 813 | * may already have been created because they were needed to |
789 | * enable allocations for slab creation. | 814 | * enable allocations for slab creation. |
@@ -833,39 +858,30 @@ void __init create_kmalloc_caches(unsigned long flags) | |||
833 | for (i = 128 + 8; i <= 192; i += 8) | 858 | for (i = 128 + 8; i <= 192; i += 8) |
834 | size_index[size_index_elem(i)] = 8; | 859 | size_index[size_index_elem(i)] = 8; |
835 | } | 860 | } |
836 | for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) { | 861 | for (i = KMALLOC_LOOP_LOW; i <= KMALLOC_SHIFT_HIGH; i++) { |
837 | if (!kmalloc_caches[i]) { | 862 | if (!kmalloc_caches[i]) { |
838 | kmalloc_caches[i] = create_kmalloc_cache(NULL, | 863 | kmalloc_caches[i] = create_kmalloc_cache( |
839 | 1 << i, flags); | 864 | kmalloc_info[i].name, |
865 | kmalloc_info[i].size, | ||
866 | flags); | ||
840 | } | 867 | } |
841 | 868 | ||
842 | /* | 869 | /* |
843 | * Caches that are not of the two-to-the-power-of size. | 870 | * "i == 2" is the "kmalloc-192" case which is the last special |
844 | * These have to be created immediately after the | 871 | * case for initialization and it's the point to jump to |
845 | * earlier power of two caches | 872 | * allocate the minimize size of the object. In slab allocator, |
873 | * the KMALLOC_SHIFT_LOW = 5. So, it needs to skip 2^3 and 2^4 | ||
874 | * and go straight to allocate 2^5. If the ARCH_DMA_MINALIGN is | ||
875 | * defined, it may be larger than 2^5 and here is also the | ||
876 | * trick to skip the empty gap. | ||
846 | */ | 877 | */ |
847 | if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6) | 878 | if (i == 2) |
848 | kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags); | 879 | i = (KMALLOC_SHIFT_LOW - 1); |
849 | |||
850 | if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7) | ||
851 | kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags); | ||
852 | } | 880 | } |
853 | 881 | ||
854 | /* Kmalloc array is now usable */ | 882 | /* Kmalloc array is now usable */ |
855 | slab_state = UP; | 883 | slab_state = UP; |
856 | 884 | ||
857 | for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { | ||
858 | struct kmem_cache *s = kmalloc_caches[i]; | ||
859 | char *n; | ||
860 | |||
861 | if (s) { | ||
862 | n = kasprintf(GFP_NOWAIT, "kmalloc-%d", kmalloc_size(i)); | ||
863 | |||
864 | BUG_ON(!n); | ||
865 | s->name = n; | ||
866 | } | ||
867 | } | ||
868 | |||
869 | #ifdef CONFIG_ZONE_DMA | 885 | #ifdef CONFIG_ZONE_DMA |
870 | for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { | 886 | for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { |
871 | struct kmem_cache *s = kmalloc_caches[i]; | 887 | struct kmem_cache *s = kmalloc_caches[i]; |