浏览代码

btrfs: use generic slab for for btrfs_transaction

Observing the number of slab objects of btrfs_transaction, there's just
one active on an almost quiescent filesystem, and the number of objects
goes to about ten when sync is in progress. Then the nubmer goes down to
1.  This matches the expectations of the transaction lifetime.

For such use the separate slab cache is not justified, as we do not
reuse objects frequently. For the shortlived transaction, the generic
slab (size 512) should be ok. We can optimistically expect that the 512
slabs are not all used (fragmentation) and there are free slots to take
when we do the allocation, compared to potentially allocating a whole new
page for the separate slab.

We'll lose the stats about the object use, which could be added later if
we really need them.

Signed-off-by: David Sterba <dsterba@suse.com>
David Sterba 8 年之前
父节点
当前提交
4b5faeac46
共有 4 个文件被更改,包括 4 次插入18 次删除
  1. 0 1
      fs/btrfs/ctree.h
  2. 0 5
      fs/btrfs/disk-io.c
  3. 0 8
      fs/btrfs/inode.c
  4. 4 4
      fs/btrfs/transaction.c

+ 0 - 1
fs/btrfs/ctree.h

@@ -48,7 +48,6 @@ struct btrfs_trans_handle;
 struct btrfs_transaction;
 struct btrfs_transaction;
 struct btrfs_pending_snapshot;
 struct btrfs_pending_snapshot;
 extern struct kmem_cache *btrfs_trans_handle_cachep;
 extern struct kmem_cache *btrfs_trans_handle_cachep;
-extern struct kmem_cache *btrfs_transaction_cachep;
 extern struct kmem_cache *btrfs_bit_radix_cachep;
 extern struct kmem_cache *btrfs_bit_radix_cachep;
 extern struct kmem_cache *btrfs_path_cachep;
 extern struct kmem_cache *btrfs_path_cachep;
 extern struct kmem_cache *btrfs_free_space_cachep;
 extern struct kmem_cache *btrfs_free_space_cachep;

+ 0 - 5
fs/btrfs/disk-io.c

@@ -4624,11 +4624,6 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
 
 
 	cur_trans->state =TRANS_STATE_COMPLETED;
 	cur_trans->state =TRANS_STATE_COMPLETED;
 	wake_up(&cur_trans->commit_wait);
 	wake_up(&cur_trans->commit_wait);
-
-	/*
-	memset(cur_trans, 0, sizeof(*cur_trans));
-	kmem_cache_free(btrfs_transaction_cachep, cur_trans);
-	*/
 }
 }
 
 
 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)
 static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)

+ 0 - 8
fs/btrfs/inode.c

@@ -86,7 +86,6 @@ static const struct extent_io_ops btrfs_extent_io_ops;
 
 
 static struct kmem_cache *btrfs_inode_cachep;
 static struct kmem_cache *btrfs_inode_cachep;
 struct kmem_cache *btrfs_trans_handle_cachep;
 struct kmem_cache *btrfs_trans_handle_cachep;
-struct kmem_cache *btrfs_transaction_cachep;
 struct kmem_cache *btrfs_path_cachep;
 struct kmem_cache *btrfs_path_cachep;
 struct kmem_cache *btrfs_free_space_cachep;
 struct kmem_cache *btrfs_free_space_cachep;
 
 
@@ -9513,7 +9512,6 @@ void btrfs_destroy_cachep(void)
 	rcu_barrier();
 	rcu_barrier();
 	kmem_cache_destroy(btrfs_inode_cachep);
 	kmem_cache_destroy(btrfs_inode_cachep);
 	kmem_cache_destroy(btrfs_trans_handle_cachep);
 	kmem_cache_destroy(btrfs_trans_handle_cachep);
-	kmem_cache_destroy(btrfs_transaction_cachep);
 	kmem_cache_destroy(btrfs_path_cachep);
 	kmem_cache_destroy(btrfs_path_cachep);
 	kmem_cache_destroy(btrfs_free_space_cachep);
 	kmem_cache_destroy(btrfs_free_space_cachep);
 }
 }
@@ -9533,12 +9531,6 @@ int btrfs_init_cachep(void)
 	if (!btrfs_trans_handle_cachep)
 	if (!btrfs_trans_handle_cachep)
 		goto fail;
 		goto fail;
 
 
-	btrfs_transaction_cachep = kmem_cache_create("btrfs_transaction",
-			sizeof(struct btrfs_transaction), 0,
-			SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
-	if (!btrfs_transaction_cachep)
-		goto fail;
-
 	btrfs_path_cachep = kmem_cache_create("btrfs_path",
 	btrfs_path_cachep = kmem_cache_create("btrfs_path",
 			sizeof(struct btrfs_path), 0,
 			sizeof(struct btrfs_path), 0,
 			SLAB_MEM_SPREAD, NULL);
 			SLAB_MEM_SPREAD, NULL);

+ 4 - 4
fs/btrfs/transaction.c

@@ -93,7 +93,7 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
 			btrfs_put_block_group_trimming(cache);
 			btrfs_put_block_group_trimming(cache);
 			btrfs_put_block_group(cache);
 			btrfs_put_block_group(cache);
 		}
 		}
-		kmem_cache_free(btrfs_transaction_cachep, transaction);
+		kfree(transaction);
 	}
 	}
 }
 }
 
 
@@ -228,7 +228,7 @@ loop:
 	 */
 	 */
 	BUG_ON(type == TRANS_JOIN_NOLOCK);
 	BUG_ON(type == TRANS_JOIN_NOLOCK);
 
 
-	cur_trans = kmem_cache_alloc(btrfs_transaction_cachep, GFP_NOFS);
+	cur_trans = kmalloc(sizeof(*cur_trans), GFP_NOFS);
 	if (!cur_trans)
 	if (!cur_trans)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
@@ -238,11 +238,11 @@ loop:
 		 * someone started a transaction after we unlocked.  Make sure
 		 * someone started a transaction after we unlocked.  Make sure
 		 * to redo the checks above
 		 * to redo the checks above
 		 */
 		 */
-		kmem_cache_free(btrfs_transaction_cachep, cur_trans);
+		kfree(cur_trans);
 		goto loop;
 		goto loop;
 	} else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
 	} else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
 		spin_unlock(&fs_info->trans_lock);
 		spin_unlock(&fs_info->trans_lock);
-		kmem_cache_free(btrfs_transaction_cachep, cur_trans);
+		kfree(cur_trans);
 		return -EROFS;
 		return -EROFS;
 	}
 	}