diff mbox series

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

Message ID 20180728151540.11253-7-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show
Series code cleanup and minor optimization for cap reservation | expand

Commit Message

Chengguang Xu July 28, 2018, 3:15 p.m. UTC
If trimmed caps are enough for need, then we will stop
trimming and try to reserve again.

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

Patch

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) {