Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dm-bufio: use kmalloc to allocate power-of-two sized buffers

Vlastimil Babka said [1] that kmalloc will return a power-of-two-aligned
buffer if it was called with a power-of-two size. So, we can use kmalloc
instead of our own slab cache in dm-bufio. Note that the code for the
slab cache was not removed because dm-bufio supports non-power-of-two
buffer sizes.

Link: https://lore.kernel.org/linux-mm/e7fca292-7c79-4f97-a90c-d68178d8ca59@suse.cz/ [1]

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

+20 -5
+20 -5
drivers/md/dm-bufio.c
··· 318 318 */ 319 319 enum data_mode { 320 320 DATA_MODE_SLAB = 0, 321 - DATA_MODE_GET_FREE_PAGES = 1, 322 - DATA_MODE_VMALLOC = 2, 323 - DATA_MODE_LIMIT = 3 321 + DATA_MODE_KMALLOC = 1, 322 + DATA_MODE_GET_FREE_PAGES = 2, 323 + DATA_MODE_VMALLOC = 3, 324 + DATA_MODE_LIMIT = 4 324 325 }; 325 326 326 327 struct dm_buffer { ··· 1063 1062 1064 1063 static unsigned long dm_bufio_peak_allocated; 1065 1064 static unsigned long dm_bufio_allocated_kmem_cache; 1065 + static unsigned long dm_bufio_allocated_kmalloc; 1066 1066 static unsigned long dm_bufio_allocated_get_free_pages; 1067 1067 static unsigned long dm_bufio_allocated_vmalloc; 1068 1068 static unsigned long dm_bufio_current_allocated; ··· 1106 1104 1107 1105 static unsigned long * const class_ptr[DATA_MODE_LIMIT] = { 1108 1106 &dm_bufio_allocated_kmem_cache, 1107 + &dm_bufio_allocated_kmalloc, 1109 1108 &dm_bufio_allocated_get_free_pages, 1110 1109 &dm_bufio_allocated_vmalloc, 1111 1110 }; ··· 1184 1181 return kmem_cache_alloc(c->slab_cache, gfp_mask); 1185 1182 } 1186 1183 1184 + if (unlikely(c->block_size < PAGE_SIZE)) { 1185 + *data_mode = DATA_MODE_KMALLOC; 1186 + return kmalloc(c->block_size, gfp_mask | __GFP_RECLAIMABLE); 1187 + } 1188 + 1187 1189 if (c->block_size <= KMALLOC_MAX_SIZE && 1188 1190 gfp_mask & __GFP_NORETRY) { 1189 1191 *data_mode = DATA_MODE_GET_FREE_PAGES; ··· 1210 1202 switch (data_mode) { 1211 1203 case DATA_MODE_SLAB: 1212 1204 kmem_cache_free(c->slab_cache, data); 1205 + break; 1206 + 1207 + case DATA_MODE_KMALLOC: 1208 + kfree(data); 1213 1209 break; 1214 1210 1215 1211 case DATA_MODE_GET_FREE_PAGES: ··· 2531 2519 goto bad_dm_io; 2532 2520 } 2533 2521 2534 - if (block_size <= KMALLOC_MAX_SIZE && 2535 - (block_size < PAGE_SIZE || !is_power_of_2(block_size))) { 2522 + if (block_size <= KMALLOC_MAX_SIZE && !is_power_of_2(block_size)) { 2536 2523 unsigned int align = min(1U << __ffs(block_size), (unsigned int)PAGE_SIZE); 2537 2524 2538 2525 snprintf(slab_name, sizeof(slab_name), "dm_bufio_cache-%u-%u", ··· 2913 2902 __u64 mem; 2914 2903 2915 2904 dm_bufio_allocated_kmem_cache = 0; 2905 + dm_bufio_allocated_kmalloc = 0; 2916 2906 dm_bufio_allocated_get_free_pages = 0; 2917 2907 dm_bufio_allocated_vmalloc = 0; 2918 2908 dm_bufio_current_allocated = 0; ··· 3001 2989 3002 2990 module_param_named(allocated_kmem_cache_bytes, dm_bufio_allocated_kmem_cache, ulong, 0444); 3003 2991 MODULE_PARM_DESC(allocated_kmem_cache_bytes, "Memory allocated with kmem_cache_alloc"); 2992 + 2993 + module_param_named(allocated_kmalloc_bytes, dm_bufio_allocated_kmalloc, ulong, 0444); 2994 + MODULE_PARM_DESC(allocated_kmalloc_bytes, "Memory allocated with kmalloc_alloc"); 3004 2995 3005 2996 module_param_named(allocated_get_free_pages_bytes, dm_bufio_allocated_get_free_pages, ulong, 0444); 3006 2997 MODULE_PARM_DESC(allocated_get_free_pages_bytes, "Memory allocated with get_free_pages");