@@ -318,9 +318,10 @@ static struct lru_entry *lru_evict(struct lru *lru, le_predicate pred, void *con
318318 */
319319enum data_mode {
320320 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
324325};
325326
326327struct dm_buffer {
@@ -1062,6 +1063,7 @@ static unsigned long dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES;
10621063
10631064static unsigned long dm_bufio_peak_allocated ;
10641065static unsigned long dm_bufio_allocated_kmem_cache ;
1066+ static unsigned long dm_bufio_allocated_kmalloc ;
10651067static unsigned long dm_bufio_allocated_get_free_pages ;
10661068static unsigned long dm_bufio_allocated_vmalloc ;
10671069static unsigned long dm_bufio_current_allocated ;
@@ -1104,6 +1106,7 @@ static void adjust_total_allocated(struct dm_buffer *b, bool unlink)
11041106
11051107 static unsigned long * const class_ptr [DATA_MODE_LIMIT ] = {
11061108 & dm_bufio_allocated_kmem_cache ,
1109+ & dm_bufio_allocated_kmalloc ,
11071110 & dm_bufio_allocated_get_free_pages ,
11081111 & dm_bufio_allocated_vmalloc ,
11091112 };
@@ -1181,6 +1184,11 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
11811184 return kmem_cache_alloc (c -> slab_cache , gfp_mask );
11821185 }
11831186
1187+ if (unlikely (c -> block_size < PAGE_SIZE )) {
1188+ * data_mode = DATA_MODE_KMALLOC ;
1189+ return kmalloc (c -> block_size , gfp_mask | __GFP_RECLAIMABLE );
1190+ }
1191+
11841192 if (c -> block_size <= KMALLOC_MAX_SIZE &&
11851193 gfp_mask & __GFP_NORETRY ) {
11861194 * data_mode = DATA_MODE_GET_FREE_PAGES ;
@@ -1204,6 +1212,10 @@ static void free_buffer_data(struct dm_bufio_client *c,
12041212 kmem_cache_free (c -> slab_cache , data );
12051213 break ;
12061214
1215+ case DATA_MODE_KMALLOC :
1216+ kfree (data );
1217+ break ;
1218+
12071219 case DATA_MODE_GET_FREE_PAGES :
12081220 free_pages ((unsigned long )data ,
12091221 c -> sectors_per_block_bits - (PAGE_SHIFT - SECTOR_SHIFT ));
@@ -2519,8 +2531,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
25192531 goto bad_dm_io ;
25202532 }
25212533
2522- if (block_size <= KMALLOC_MAX_SIZE &&
2523- (block_size < PAGE_SIZE || !is_power_of_2 (block_size ))) {
2534+ if (block_size <= KMALLOC_MAX_SIZE && !is_power_of_2 (block_size )) {
25242535 unsigned int align = min (1U << __ffs (block_size ), (unsigned int )PAGE_SIZE );
25252536
25262537 snprintf (slab_name , sizeof (slab_name ), "dm_bufio_cache-%u-%u" ,
@@ -2902,6 +2913,7 @@ static int __init dm_bufio_init(void)
29022913 __u64 mem ;
29032914
29042915 dm_bufio_allocated_kmem_cache = 0 ;
2916+ dm_bufio_allocated_kmalloc = 0 ;
29052917 dm_bufio_allocated_get_free_pages = 0 ;
29062918 dm_bufio_allocated_vmalloc = 0 ;
29072919 dm_bufio_current_allocated = 0 ;
@@ -2990,6 +3002,9 @@ MODULE_PARM_DESC(peak_allocated_bytes, "Tracks the maximum allocated memory");
29903002module_param_named (allocated_kmem_cache_bytes , dm_bufio_allocated_kmem_cache , ulong , 0444 );
29913003MODULE_PARM_DESC (allocated_kmem_cache_bytes , "Memory allocated with kmem_cache_alloc" );
29923004
3005+ module_param_named (allocated_kmalloc_bytes , dm_bufio_allocated_kmalloc , ulong , 0444 );
3006+ MODULE_PARM_DESC (allocated_kmalloc_bytes , "Memory allocated with kmalloc_alloc" );
3007+
29933008module_param_named (allocated_get_free_pages_bytes , dm_bufio_allocated_get_free_pages , ulong , 0444 );
29943009MODULE_PARM_DESC (allocated_get_free_pages_bytes , "Memory allocated with get_free_pages" );
29953010
0 commit comments