Commit 79cd674a authored by Chengguang Xu's avatar Chengguang Xu Committed by Ilya Dryomov

ceph: optimizing cap reservation

When caps_avail_count is in a low level, most newly
trimmed caps will probably go into ->caps_list and
caps_avail_count will be increased. Hence after trimming,
should recheck caps_avail_count to effectly reuse
newly trimmed caps. Also, when releasing unnecessary
caps follow the same rule of ceph_put_cap.
Signed-off-by: default avatarChengguang Xu <cgxu519@icloud.com>
Reviewed-by: default avatar"Yan, Zheng" <zyan@redhat.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent b517c1d8
...@@ -184,10 +184,15 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, ...@@ -184,10 +184,15 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
mdsc->caps_avail_count); mdsc->caps_avail_count);
spin_unlock(&mdsc->caps_list_lock); spin_unlock(&mdsc->caps_list_lock);
for (i = have; i < need; i++) { for (i = have; i < need; ) {
retry:
cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS); cap = kmem_cache_alloc(ceph_cap_cachep, GFP_NOFS);
if (!cap) { if (cap) {
list_add(&cap->caps_item, &newcaps);
alloc++;
i++;
continue;
}
if (!trimmed) { if (!trimmed) {
for (j = 0; j < mdsc->max_sessions; j++) { for (j = 0; j < mdsc->max_sessions; j++) {
s = __ceph_lookup_mds_session(mdsc, j); s = __ceph_lookup_mds_session(mdsc, j);
...@@ -204,16 +209,29 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, ...@@ -204,16 +209,29 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
mutex_lock(&mdsc->mutex); mutex_lock(&mdsc->mutex);
} }
trimmed = true; trimmed = true;
goto retry;
} else { spin_lock(&mdsc->caps_list_lock);
pr_warn("reserve caps ctx=%p ENOMEM " if (mdsc->caps_avail_count) {
"need=%d got=%d\n", int more_have;
ctx, need, have + alloc); if (mdsc->caps_avail_count >= need - i)
goto out_nomem; more_have = need - i;
else
more_have = mdsc->caps_avail_count;
i += more_have;
have += more_have;
mdsc->caps_avail_count -= more_have;
mdsc->caps_reserve_count += more_have;
} }
spin_unlock(&mdsc->caps_list_lock);
continue;
} }
list_add(&cap->caps_item, &newcaps);
alloc++; pr_warn("reserve caps ctx=%p ENOMEM need=%d got=%d\n",
ctx, need, have + alloc);
goto out_nomem;
} }
BUG_ON(have + alloc != need); BUG_ON(have + alloc != need);
...@@ -234,16 +252,28 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, ...@@ -234,16 +252,28 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
return 0; return 0;
out_nomem: out_nomem:
spin_lock(&mdsc->caps_list_lock);
mdsc->caps_avail_count += have;
mdsc->caps_reserve_count -= have;
while (!list_empty(&newcaps)) { while (!list_empty(&newcaps)) {
cap = list_first_entry(&newcaps, cap = list_first_entry(&newcaps,
struct ceph_cap, caps_item); struct ceph_cap, caps_item);
list_del(&cap->caps_item); list_del(&cap->caps_item);
/* Keep some preallocated caps around (ceph_min_count), to
* avoid lots of free/alloc churn. */
if (mdsc->caps_avail_count >=
mdsc->caps_reserve_count + mdsc->caps_min_count) {
kmem_cache_free(ceph_cap_cachep, cap); kmem_cache_free(ceph_cap_cachep, cap);
} else {
mdsc->caps_avail_count++;
mdsc->caps_total_count++;
list_add(&cap->caps_item, &mdsc->caps_list);
}
} }
spin_lock(&mdsc->caps_list_lock);
mdsc->caps_avail_count += have;
mdsc->caps_reserve_count -= have;
BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count +
mdsc->caps_reserve_count + mdsc->caps_reserve_count +
mdsc->caps_avail_count); mdsc->caps_avail_count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment