ceph: optimizing cap allocation
authorChengguang Xu <cgxu519@icloud.com>
Sat, 24 Feb 2018 10:35:29 +0000 (18:35 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 2 Apr 2018 08:12:46 +0000 (10:12 +0200)
When setting high volume of caps_min_count or having many
unreserved caps, unused caps may always keep in the ->caps_list
even can't get new cap from kmem_cache_alloc because lack of
maximum limitation of caps_avail_count. Hence reuse caps in
->caps_list if available, it's maybe better than setting max
limitation of caps_avail_count and releasing unused caps when
reaching the limit.

Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/caps.c

index 1d02648788e38e7e9906da5354baef4c5d39815e..421cdce71fb0910f4a47c771fec457835bf81629 100644 (file)
@@ -285,7 +285,23 @@ struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc,
                        mdsc->caps_use_count++;
                        mdsc->caps_total_count++;
                        spin_unlock(&mdsc->caps_list_lock);
+               } else {
+                       spin_lock(&mdsc->caps_list_lock);
+                       if (mdsc->caps_avail_count) {
+                               BUG_ON(list_empty(&mdsc->caps_list));
+
+                               mdsc->caps_avail_count--;
+                               mdsc->caps_use_count++;
+                               cap = list_first_entry(&mdsc->caps_list,
+                                               struct ceph_cap, caps_item);
+                               list_del(&cap->caps_item);
+
+                               BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
+                                      mdsc->caps_reserve_count + mdsc->caps_avail_count);
+                       }
+                       spin_unlock(&mdsc->caps_list_lock);
                }
+
                return cap;
        }