Skip to content

Commit 2baba25

Browse files
Yehuda Sadehliewegas
authored andcommitted
ceph: writeback congestion control
Set bdi congestion bit when amount of write data in flight exceeds adjustable threshold. Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent dbd646a commit 2baba25

4 files changed

Lines changed: 105 additions & 2 deletions

File tree

‎fs/ceph/addr.c‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
* accounting is preserved.
4848
*/
4949

50+
#define CONGESTION_ON_THRESH(congestion_kb) (congestion_kb >> (PAGE_SHIFT-10))
51+
#define CONGESTION_OFF_THRESH(congestion_kb) \
52+
(CONGESTION_ON_THRESH(congestion_kb) - \
53+
(CONGESTION_ON_THRESH(congestion_kb) >> 2))
54+
55+
5056

5157
/*
5258
* Dirty a page. Optimistically adjust accounting, on the assumption
@@ -377,13 +383,15 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
377383
{
378384
struct inode *inode;
379385
struct ceph_inode_info *ci;
386+
struct ceph_client *client;
380387
struct ceph_osd_client *osdc;
381388
loff_t page_off = page->index << PAGE_CACHE_SHIFT;
382389
int len = PAGE_CACHE_SIZE;
383390
loff_t i_size;
384391
int err = 0;
385392
struct ceph_snap_context *snapc;
386393
u64 snap_size = 0;
394+
long writeback_stat;
387395

388396
dout("writepage %p idx %lu\n", page, page->index);
389397

@@ -393,7 +401,8 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
393401
}
394402
inode = page->mapping->host;
395403
ci = ceph_inode(inode);
396-
osdc = &ceph_inode_to_client(inode)->osdc;
404+
client = ceph_inode_to_client(inode);
405+
osdc = &client->osdc;
397406

398407
/* verify this is a writeable snap context */
399408
snapc = (void *)page->private;
@@ -420,6 +429,11 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc)
420429
dout("writepage %p page %p index %lu on %llu~%u\n",
421430
inode, page, page->index, page_off, len);
422431

432+
writeback_stat = atomic_long_inc_return(&client->writeback_count);
433+
if (writeback_stat >
434+
CONGESTION_ON_THRESH(client->mount_args->congestion_kb))
435+
set_bdi_congested(&client->backing_dev_info, BLK_RW_ASYNC);
436+
423437
set_page_writeback(page);
424438
err = ceph_osdc_writepages(osdc, ceph_vino(inode),
425439
&ci->i_layout, snapc,
@@ -499,6 +513,8 @@ static void writepages_finish(struct ceph_osd_request *req,
499513
struct writeback_control *wbc = req->r_wbc;
500514
__s32 rc = -EIO;
501515
u64 bytes = 0;
516+
struct ceph_client *client = ceph_inode_to_client(inode);
517+
long writeback_stat;
502518

503519
/* parse reply */
504520
replyhead = msg->front.iov_base;
@@ -524,6 +540,13 @@ static void writepages_finish(struct ceph_osd_request *req,
524540
BUG_ON(!page);
525541
WARN_ON(!PageUptodate(page));
526542

543+
writeback_stat =
544+
atomic_long_dec_return(&client->writeback_count);
545+
if (writeback_stat <
546+
CONGESTION_OFF_THRESH(client->mount_args->congestion_kb))
547+
clear_bdi_congested(&client->backing_dev_info,
548+
BLK_RW_ASYNC);
549+
527550
if (i >= wrote) {
528551
dout("inode %p skipping page %p\n", inode, page);
529552
wbc->pages_skipped++;
@@ -666,6 +689,7 @@ static int ceph_writepages_start(struct address_space *mapping,
666689
u64 offset, len;
667690
struct ceph_osd_request_head *reqhead;
668691
struct ceph_osd_op *op;
692+
long writeback_stat;
669693

670694
next = 0;
671695
locked_pages = 0;
@@ -773,6 +797,12 @@ static int ceph_writepages_start(struct address_space *mapping,
773797
first = i;
774798
dout("%p will write page %p idx %lu\n",
775799
inode, page, page->index);
800+
801+
writeback_stat = atomic_long_inc_return(&client->writeback_count);
802+
if (writeback_stat > CONGESTION_ON_THRESH(client->mount_args->congestion_kb)) {
803+
set_bdi_congested(&client->backing_dev_info, BLK_RW_ASYNC);
804+
}
805+
776806
set_page_writeback(page);
777807
req->r_pages[locked_pages] = page;
778808
locked_pages++;
@@ -998,7 +1028,8 @@ static int ceph_write_end(struct file *file, struct address_space *mapping,
9981028
struct page *page, void *fsdata)
9991029
{
10001030
struct inode *inode = file->f_dentry->d_inode;
1001-
struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc;
1031+
struct ceph_client *client = ceph_inode_to_client(inode);
1032+
struct ceph_mds_client *mdsc = &client->mdsc;
10021033
unsigned from = pos & (PAGE_CACHE_SIZE - 1);
10031034
int check_cap = 0;
10041035

‎fs/ceph/debugfs.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,30 @@ DEFINE_SHOW_FUNC(osdc_show)
320320
DEFINE_SHOW_FUNC(dentry_lru_show)
321321
DEFINE_SHOW_FUNC(caps_show)
322322

323+
static int congestion_kb_set(void *data, u64 val)
324+
{
325+
struct ceph_client *client = (struct ceph_client *)data;
326+
327+
if (client)
328+
client->mount_args->congestion_kb = (int)val;
329+
330+
return 0;
331+
}
332+
333+
static int congestion_kb_get(void *data, u64 *val)
334+
{
335+
struct ceph_client *client = (struct ceph_client *)data;
336+
337+
if (client)
338+
*val = (u64)client->mount_args->congestion_kb;
339+
340+
return 0;
341+
}
342+
343+
344+
DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
345+
congestion_kb_set, "%llu\n");
346+
323347
int __init ceph_debugfs_init(void)
324348
{
325349
ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
@@ -409,6 +433,14 @@ int ceph_debugfs_client_init(struct ceph_client *client)
409433
if (!client->debugfs_caps)
410434
goto out;
411435

436+
client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
437+
0600,
438+
client->debugfs_dir,
439+
client,
440+
&congestion_kb_fops);
441+
if (!client->debugfs_congestion_kb)
442+
goto out;
443+
412444
sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
413445
client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
414446
name);
@@ -431,6 +463,7 @@ void ceph_debugfs_client_cleanup(struct ceph_client *client)
431463
debugfs_remove(client->osdc.debugfs_file);
432464
debugfs_remove(client->mdsc.debugfs_file);
433465
debugfs_remove(client->monc.debugfs_file);
466+
debugfs_remove(client->debugfs_congestion_kb);
434467
debugfs_remove(client->debugfs_dir);
435468
}
436469

‎fs/ceph/super.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,35 @@ static void ceph_inode_init_once(void *foo)
150150
inode_init_once(&ci->vfs_inode);
151151
}
152152

153+
static int default_congestion_kb(void)
154+
{
155+
int congestion_kb;
156+
157+
/*
158+
* Copied from NFS
159+
*
160+
* congestion size, scale with available memory.
161+
*
162+
* 64MB: 8192k
163+
* 128MB: 11585k
164+
* 256MB: 16384k
165+
* 512MB: 23170k
166+
* 1GB: 32768k
167+
* 2GB: 46340k
168+
* 4GB: 65536k
169+
* 8GB: 92681k
170+
* 16GB: 131072k
171+
*
172+
* This allows larger machines to have larger/more transfers.
173+
* Limit the default to 256M
174+
*/
175+
congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
176+
if (congestion_kb > 256*1024)
177+
congestion_kb = 256*1024;
178+
179+
return congestion_kb;
180+
}
181+
153182
static int __init init_caches(void)
154183
{
155184
ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
@@ -267,6 +296,7 @@ enum {
267296
Opt_caps_wanted_delay_min,
268297
Opt_caps_wanted_delay_max,
269298
Opt_readdir_max_entries,
299+
Opt_congestion_kb,
270300
Opt_last_int,
271301
/* int args above */
272302
Opt_snapdirname,
@@ -295,6 +325,7 @@ static match_table_t arg_tokens = {
295325
{Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
296326
{Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
297327
{Opt_readdir_max_entries, "readdir_max_entries=%d"},
328+
{Opt_congestion_kb, "write_congestion_kb=%d"},
298329
/* int args above */
299330
{Opt_snapdirname, "snapdirname=%s"},
300331
{Opt_name, "name=%s"},
@@ -342,6 +373,7 @@ static struct ceph_mount_args *parse_mount_args(int flags, char *options,
342373
args->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
343374
args->cap_release_safety = CEPH_CAPS_PER_RELEASE * 4;
344375
args->max_readdir = 1024;
376+
args->congestion_kb = default_congestion_kb();
345377

346378
/* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */
347379
err = -EINVAL;
@@ -445,6 +477,9 @@ static struct ceph_mount_args *parse_mount_args(int flags, char *options,
445477
case Opt_readdir_max_entries:
446478
args->max_readdir = intval;
447479
break;
480+
case Opt_congestion_kb:
481+
args->congestion_kb = intval;
482+
break;
448483

449484
case Opt_noshare:
450485
args->flags |= CEPH_OPT_NOSHARE;
@@ -516,6 +551,7 @@ static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
516551
client->msgr = NULL;
517552

518553
client->mount_err = 0;
554+
atomic_long_set(&client->writeback_count, 0);
519555

520556
err = bdi_init(&client->backing_dev_info);
521557
if (err < 0)

‎fs/ceph/super.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct ceph_mount_args {
5959
int wsize;
6060
int rsize; /* max readahead */
6161
int max_readdir; /* max readdir size */
62+
int congestion_kb; /* max readdir size */
6263
int osd_timeout;
6364
char *snapdir_name; /* default ".snap" */
6465
char *name;
@@ -136,13 +137,15 @@ struct ceph_client {
136137
struct workqueue_struct *wb_wq;
137138
struct workqueue_struct *pg_inv_wq;
138139
struct workqueue_struct *trunc_wq;
140+
atomic_long_t writeback_count;
139141

140142
struct backing_dev_info backing_dev_info;
141143

142144
#ifdef CONFIG_DEBUG_FS
143145
struct dentry *debugfs_monmap;
144146
struct dentry *debugfs_mdsmap, *debugfs_osdmap;
145147
struct dentry *debugfs_dir, *debugfs_dentry_lru, *debugfs_caps;
148+
struct dentry *debugfs_congestion_kb;
146149
struct dentry *debugfs_bdi;
147150
#endif
148151
};

0 commit comments

Comments
 (0)