Skip to content

Commit 85ccce4

Browse files
committed
ceph: clean up readdir caps reservation
Use a global counter for the minimum number of allocated caps instead of hard coding a check against readdir_max. This takes into account multiple client instances, and avoids examining the superblock mount options when a cap is dropped. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 5ce6e9d commit 85ccce4

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎fs/ceph/caps.c‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static int caps_total_count; /* total caps allocated */
128128
static int caps_use_count; /* in use */
129129
static int caps_reserve_count; /* unused, reserved */
130130
static int caps_avail_count; /* unused, unreserved */
131+
static int caps_min_count; /* keep at least this many (unreserved) */
131132

132133
void __init ceph_caps_init(void)
133134
{
@@ -149,6 +150,15 @@ void ceph_caps_finalize(void)
149150
caps_avail_count = 0;
150151
caps_use_count = 0;
151152
caps_reserve_count = 0;
153+
caps_min_count = 0;
154+
spin_unlock(&caps_list_lock);
155+
}
156+
157+
void ceph_adjust_min_caps(int delta)
158+
{
159+
spin_lock(&caps_list_lock);
160+
caps_min_count += delta;
161+
BUG_ON(caps_min_count < 0);
152162
spin_unlock(&caps_list_lock);
153163
}
154164

@@ -265,12 +275,10 @@ static void put_cap(struct ceph_cap *cap,
265275
caps_reserve_count, caps_avail_count);
266276
caps_use_count--;
267277
/*
268-
* Keep some preallocated caps around, at least enough to do a
269-
* readdir (which needs to preallocate lots of them), to avoid
270-
* lots of free/alloc churn.
278+
* Keep some preallocated caps around (ceph_min_count), to
279+
* avoid lots of free/alloc churn.
271280
*/
272-
if (caps_avail_count >= caps_reserve_count +
273-
ceph_client(cap->ci->vfs_inode.i_sb)->mount_args->max_readdir) {
281+
if (caps_avail_count >= caps_reserve_count + caps_min_count) {
274282
caps_total_count--;
275283
kmem_cache_free(ceph_cap_cachep, cap);
276284
} else {
@@ -289,7 +297,8 @@ static void put_cap(struct ceph_cap *cap,
289297
}
290298

291299
void ceph_reservation_status(struct ceph_client *client,
292-
int *total, int *avail, int *used, int *reserved)
300+
int *total, int *avail, int *used, int *reserved,
301+
int *min)
293302
{
294303
if (total)
295304
*total = caps_total_count;
@@ -299,6 +308,8 @@ void ceph_reservation_status(struct ceph_client *client,
299308
*used = caps_use_count;
300309
if (reserved)
301310
*reserved = caps_reserve_count;
311+
if (min)
312+
*min = caps_min_count;
302313
}
303314

304315
/*

‎fs/ceph/debugfs.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ static int osdc_show(struct seq_file *s, void *pp)
255255
static int caps_show(struct seq_file *s, void *p)
256256
{
257257
struct ceph_client *client = p;
258-
int total, avail, used, reserved;
258+
int total, avail, used, reserved, min;
259259

260-
ceph_reservation_status(client, &total, &avail, &used, &reserved);
260+
ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
261261
seq_printf(s, "total\t\t%d\n"
262-
"avail\t\t%d\n"
263-
"used\t\t%d\n"
264-
"reserved\t%d\n",
265-
total, avail, used, reserved);
262+
"avail\t\t%d\n"
263+
"used\t\t%d\n"
264+
"reserved\t%d\n"
265+
"min\t%d\n",
266+
total, avail, used, reserved, min);
266267
return 0;
267268
}
268269

‎fs/ceph/super.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
578578
if (!client->wb_pagevec_pool)
579579
goto fail_trunc_wq;
580580

581+
/* caps */
582+
client->min_caps = args->max_readdir;
583+
ceph_adjust_min_caps(client->min_caps);
581584

582585
/* subsystems */
583586
err = ceph_monc_init(&client->monc, client);
@@ -619,6 +622,8 @@ static void ceph_destroy_client(struct ceph_client *client)
619622
ceph_monc_stop(&client->monc);
620623
ceph_osdc_stop(&client->osdc);
621624

625+
ceph_adjust_min_caps(-client->min_caps);
626+
622627
ceph_debugfs_client_cleanup(client);
623628
destroy_workqueue(client->wb_wq);
624629
destroy_workqueue(client->pg_inv_wq);

‎fs/ceph/super.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ struct ceph_client {
129129

130130
int auth_err;
131131

132+
int min_caps; /* min caps i added */
133+
132134
struct ceph_messenger *msgr; /* messenger instance */
133135
struct ceph_mon_client monc;
134136
struct ceph_mds_client mdsc;
@@ -557,11 +559,12 @@ extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci);
557559

558560
extern void ceph_caps_init(void);
559561
extern void ceph_caps_finalize(void);
562+
extern void ceph_adjust_min_caps(int delta);
560563
extern int ceph_reserve_caps(struct ceph_cap_reservation *ctx, int need);
561564
extern int ceph_unreserve_caps(struct ceph_cap_reservation *ctx);
562565
extern void ceph_reservation_status(struct ceph_client *client,
563566
int *total, int *avail, int *used,
564-
int *reserved);
567+
int *reserved, int *min);
565568

566569
static inline struct ceph_client *ceph_inode_to_client(struct inode *inode)
567570
{

0 commit comments

Comments
 (0)