]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bcache: remove unncessary code in bch_btree_keys_init()
authorColy Li <colyli@suse.de>
Fri, 28 Jun 2019 11:59:34 +0000 (19:59 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Jun 2019 13:39:15 +0000 (07:39 -0600)
Function bch_btree_keys_init() initializes b->set[].size and
b->set[].data to zero. As the code comments indicates, these code indeed
is unncessary, because both struct btree_keys and struct bset_tree are
nested embedded into struct btree, when struct btree is filled with 0
bits by kzalloc() in mca_bucket_alloc(), b->set[].size and
b->set[].data are initialized to 0 (a.k.a NULL) already.

This patch removes the redundant code, and add comments in
bch_btree_keys_init() and mca_bucket_alloc() to explain why it's safe.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/bset.c
drivers/md/bcache/btree.c

index e36a108d3648d8e1828a8600292c82b742280057..8af9509e78bd926f513e20c1532b299f8dbb1f71 100644 (file)
@@ -347,22 +347,19 @@ EXPORT_SYMBOL(bch_btree_keys_alloc);
 void bch_btree_keys_init(struct btree_keys *b, const struct btree_keys_ops *ops,
                         bool *expensive_debug_checks)
 {
-       unsigned int i;
-
        b->ops = ops;
        b->expensive_debug_checks = expensive_debug_checks;
        b->nsets = 0;
        b->last_set_unwritten = 0;
 
-       /* XXX: shouldn't be needed */
-       for (i = 0; i < MAX_BSETS; i++)
-               b->set[i].size = 0;
        /*
-        * Second loop starts at 1 because b->keys[0]->data is the memory we
-        * allocated
+        * struct btree_keys in embedded in struct btree, and struct
+        * bset_tree is embedded into struct btree_keys. They are all
+        * initialized as 0 by kzalloc() in mca_bucket_alloc(), and
+        * b->set[0].data is allocated in bch_btree_keys_alloc(), so we
+        * don't have to initiate b->set[].size and b->set[].data here
+        * any more.
         */
-       for (i = 1; i < MAX_BSETS; i++)
-               b->set[i].data = NULL;
 }
 EXPORT_SYMBOL(bch_btree_keys_init);
 
index 773f5fdad25fb4db72a132fa161dba76fde52129..cf38a1b031fa87a5aa8fcd759e04bcc74bb412be 100644 (file)
@@ -613,6 +613,10 @@ static void mca_data_alloc(struct btree *b, struct bkey *k, gfp_t gfp)
 static struct btree *mca_bucket_alloc(struct cache_set *c,
                                      struct bkey *k, gfp_t gfp)
 {
+       /*
+        * kzalloc() is necessary here for initialization,
+        * see code comments in bch_btree_keys_init().
+        */
        struct btree *b = kzalloc(sizeof(struct btree), gfp);
 
        if (!b)