diff mbox series

[5/6] ceph: let ceph_trim_caps() return trimmed cap number

Message ID 20180728151540.11253-6-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
When we failed allocating new cap in ceph_reserve_caps(),
then try to trim existing caps from every session and try to
reserve caps again. However, if we do not return trimmed cap
number from ceph_trim_caps(), we cannot know how many caps
released by one session, so we have to wait until trimming
finish on all sessions. Sometimes, maybe a few of sessions
(not all) can release enough caps so that we can do reservation
more effectively.

This patch let ceph_trim_caps() return trimmed cap number,
so ceph_reserve_caps() can use this for optimization.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/ceph/mds_client.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index d01a262ba691..edccf2353912 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1611,20 +1611,22 @@  int ceph_trim_caps(struct ceph_mds_client *mdsc,
 		   int max_caps)
 {
 	int trim_caps = session->s_nr_caps - max_caps;
+	int trimmed_caps = 0;
 
 	dout("trim_caps mds%d start: %d / %d, trim %d\n",
 	     session->s_mds, session->s_nr_caps, max_caps, trim_caps);
 	if (trim_caps > 0) {
 		session->s_trim_caps = trim_caps;
 		iterate_session_caps(session, trim_caps_cb, session);
+		trimmed_caps = trim_caps - session->s_trim_caps;
 		dout("trim_caps mds%d done: %d / %d, trimmed %d\n",
 		     session->s_mds, session->s_nr_caps, max_caps,
-			trim_caps - session->s_trim_caps);
+			trimmed_caps);
 		session->s_trim_caps = 0;
 	}
 
 	ceph_send_cap_releases(mdsc, session);
-	return 0;
+	return trimmed_caps;
 }
 
 static int check_caps_flush(struct ceph_mds_client *mdsc,