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
0 commit comments