[PATCH 6/6] ceph: minor optimization for cap reservation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If trimmed caps are enough for need, then we will stop
trimming and try to reserve again.

Signed-off-by: Chengguang Xu <cgxu519@xxxxxxx>
---
 fs/ceph/caps.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 976d283a6a4e..feba3ceda492 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -199,7 +199,9 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
 	int alloc = 0;
 	int max_caps;
 	int err = 0;
-	bool trimmed = false;
+	int trimmed_caps;
+	int trim_start = 0;
+	bool trimmed_all = false;
 	struct ceph_mds_session *s;
 	LIST_HEAD(newcaps);
 
@@ -227,8 +229,9 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
 			continue;
 		}
 
-		if (!trimmed) {
-			for (j = 0; j < mdsc->max_sessions; j++) {
+		if (!trimmed_all) {
+			trimmed_caps = 0;
+			for (j = trim_start; j < mdsc->max_sessions; j++) {
 				s = __ceph_lookup_mds_session(mdsc, j);
 				if (!s)
 					continue;
@@ -236,13 +239,20 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc,
 
 				mutex_lock(&s->s_mutex);
 				max_caps = s->s_nr_caps - (need - i);
-				ceph_trim_caps(mdsc, s, max_caps);
+				trimmed_caps += ceph_trim_caps(mdsc, s,
+								max_caps);
 				mutex_unlock(&s->s_mutex);
 
 				ceph_put_mds_session(s);
 				mutex_lock(&mdsc->mutex);
+				if (trimmed_caps >= need - i) {
+					trim_start = j + 1;
+					break;
+				}
 			}
-			trimmed = true;
+
+			if (j == mdsc->max_sessions)
+				trimmed_all = true;
 
 			spin_lock(&mdsc->caps_list_lock);
 			if (mdsc->caps_avail_count) {
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [CEPH Users]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux