From patchwork Thu Nov 9 19:30:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10051729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86063601EA for ; Thu, 9 Nov 2017 19:31:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7723B298E1 for ; Thu, 9 Nov 2017 19:31:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BF0E2B092; Thu, 9 Nov 2017 19:31:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE60B298E1 for ; Thu, 9 Nov 2017 19:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754763AbdKITbO (ORCPT ); Thu, 9 Nov 2017 14:31:14 -0500 Received: from mail-qk0-f180.google.com ([209.85.220.180]:44171 "EHLO mail-qk0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754712AbdKITbH (ORCPT ); Thu, 9 Nov 2017 14:31:07 -0500 Received: by mail-qk0-f180.google.com with SMTP id v137so9153680qkb.1 for ; Thu, 09 Nov 2017 11:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wZplEq4anafr8FtnclqPD4ykD7xdoNrI6pwWeuLRx9g=; b=Ja+G/YuP1gYnBXiBvnvT4v2IlQzmxcKi7oFuyPmBYIfBv96T6gUzEXeB99QgTPpERu A9DO7gpHoJV5QwOGDg85PsB3OWlXR0R5A9XL4+v+4/h7FYjByEia3TdjxaLEV1dLgeKE 7CQncfmQEM40TgdUPxmLNOnnSgS1Qe6Xp0G4dykxei7GaDN6g/0S58LMoVhcRl4TxEUF NL5NXWVo0f+xT+I2NrhNnxfUCEanIWR6XXRpWob9gIUsbHYZ91hV5BGvg7Oy7bdfRE3p gie68Z8GObFfdkHHNkPeylSp/VxFjW9/mtMGS3HZNjD18LK9ULSGVU/LNU1psIa2P1s8 8Y3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wZplEq4anafr8FtnclqPD4ykD7xdoNrI6pwWeuLRx9g=; b=Q8BF3oSAjicYEz/XLoUP85coi8yslGS1jO1gfsPaNUgOI51S4ngk24huazmFTymoGM f30QD2xl+ersPVM1/0RgLAH1jV+Rpz6uP1SsS+fskQ81j+v+p+piKj5ghap1pIS0jrRF 39ZVX9RuL6bFbzB3d+qT9KVOpHdsndLKBswypXYnmqClbVYML4aBzcJizVezPGgPlNf2 IGNioJLEfSIqnb0kh45ejfHQ4dAU9tYBbcTyDY7xTPt6Nlowu7i6cAx/cdipKIKbfHJs wdHQaOeNksO6bLHaSrnmD9gjfginOGTF3ILLWUEEX8/su0GHYL/Q9ZVbavStFxxCCH12 7woQ== X-Gm-Message-State: AJaThX6+oKytqoDr/smcBBoHNkoQw7x1G47SjzbLqFRswY7RlZHdVTK2 FDwikEibmdwLcbm9hMtkTy50kw== X-Google-Smtp-Source: AGs4zMZWsCsD1jVjkvvuL3NbjXZtx/wRrdBgQIvmQlyfmfPoIW0L+3Dj3Tkog2viKg7gYoyCL566Bw== X-Received: by 10.55.118.193 with SMTP id r184mr2612010qkc.348.1510255866014; Thu, 09 Nov 2017 11:31:06 -0800 (PST) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id d5sm5031164qkf.44.2017.11.09.11.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 11:31:05 -0800 (PST) From: Josef Bacik To: hannes@cmpxchg.org, linux-mm@kvack.org, akpm@linux-foundation.org, jack@suse.cz, linux-fsdevel@vger.kernel.org, kernel-team@fb.com, linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 3/6] writeback: introduce super_operations->write_metadata Date: Thu, 9 Nov 2017 14:30:58 -0500 Message-Id: <1510255861-8020-3-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1510255861-8020-1-git-send-email-josef@toxicpanda.com> References: <1510255861-8020-1-git-send-email-josef@toxicpanda.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik Now that we have metadata counters in the VM, we need to provide a way to kick writeback on dirty metadata. Introduce super_operations->write_metadata. This allows file systems to deal with writing back any dirty metadata we need based on the writeback needs of the system. Since there is no inode to key off of we need a list in the bdi for dirty super blocks to be added. From there we can find any dirty sb's on the bdi we are currently doing writeback on and call into their ->write_metadata callback. Signed-off-by: Josef Bacik --- fs/fs-writeback.c | 58 +++++++++++++++++++++++++++++++++++++--- fs/super.c | 6 +++++ include/linux/backing-dev-defs.h | 2 ++ include/linux/fs.h | 4 +++ mm/backing-dev.c | 2 ++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index c5374a4fb982..0a8e225a4757 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1630,11 +1630,36 @@ static long writeback_sb_inodes(struct super_block *sb, return wrote; } +static long writeback_sb_metadata(struct super_block *sb, + struct bdi_writeback *wb, + struct wb_writeback_work *work) +{ + struct writeback_control wbc = { + .sync_mode = work->sync_mode, + .tagged_writepages = work->tagged_writepages, + .for_kupdate = work->for_kupdate, + .for_background = work->for_background, + .for_sync = work->for_sync, + .range_cyclic = work->range_cyclic, + .range_start = 0, + .range_end = LLONG_MAX, + }; + long write_chunk; + + write_chunk = writeback_chunk_size(wb, work); + wbc.nr_to_write = write_chunk; + sb->s_op->write_metadata(sb, &wbc); + work->nr_pages -= write_chunk - wbc.nr_to_write; + + return write_chunk - wbc.nr_to_write; +} + static long __writeback_inodes_wb(struct bdi_writeback *wb, struct wb_writeback_work *work) { unsigned long start_time = jiffies; long wrote = 0; + bool done = false; while (!list_empty(&wb->b_io)) { struct inode *inode = wb_inode(wb->b_io.prev); @@ -1654,11 +1679,38 @@ static long __writeback_inodes_wb(struct bdi_writeback *wb, /* refer to the same tests at the end of writeback_sb_inodes */ if (wrote) { - if (time_is_before_jiffies(start_time + HZ / 10UL)) - break; - if (work->nr_pages <= 0) + if (time_is_before_jiffies(start_time + HZ / 10UL) || + work->nr_pages <= 0) { + done = true; break; + } + } + } + + if (!done && wb_stat(wb, WB_METADATA_DIRTY)) { + LIST_HEAD(list); + + spin_unlock(&wb->list_lock); + spin_lock(&wb->bdi->sb_list_lock); + list_splice_init(&wb->bdi->dirty_sb_list, &list); + while (!list_empty(&list)) { + struct super_block *sb; + + sb = list_first_entry(&list, struct super_block, + s_bdi_list); + list_move_tail(&sb->s_bdi_list, + &wb->bdi->dirty_sb_list); + if (!sb->s_op->write_metadata) + continue; + if (!trylock_super(sb)) + continue; + spin_unlock(&wb->bdi->sb_list_lock); + wrote += writeback_sb_metadata(sb, wb, work); + spin_lock(&wb->bdi->sb_list_lock); + up_read(&sb->s_umount); } + spin_unlock(&wb->bdi->sb_list_lock); + spin_lock(&wb->list_lock); } /* Leave any unwritten inodes on b_io */ return wrote; diff --git a/fs/super.c b/fs/super.c index 166c4ee0d0ed..66b369956c5e 100644 --- a/fs/super.c +++ b/fs/super.c @@ -214,6 +214,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, spin_lock_init(&s->s_inode_list_lock); INIT_LIST_HEAD(&s->s_inodes_wb); spin_lock_init(&s->s_inode_wblist_lock); + INIT_LIST_HEAD(&s->s_bdi_list); if (list_lru_init_memcg(&s->s_dentry_lru)) goto fail; @@ -446,6 +447,11 @@ void generic_shutdown_super(struct super_block *sb) spin_unlock(&sb_lock); up_write(&sb->s_umount); if (sb->s_bdi != &noop_backing_dev_info) { + if (!list_empty(&sb->s_bdi_list)) { + spin_lock(&sb->s_bdi->sb_list_lock); + list_del_init(&sb->s_bdi_list); + spin_unlock(&sb->s_bdi->sb_list_lock); + } bdi_put(sb->s_bdi); sb->s_bdi = &noop_backing_dev_info; } diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h index 013e764d4b30..e75623ab0278 100644 --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -175,6 +175,8 @@ struct backing_dev_info { struct timer_list laptop_mode_wb_timer; + spinlock_t sb_list_lock; + struct list_head dirty_sb_list; #ifdef CONFIG_DEBUG_FS struct dentry *debug_dir; struct dentry *debug_stats; diff --git a/include/linux/fs.h b/include/linux/fs.h index 339e73742e73..562c79b3dbe0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1440,6 +1440,8 @@ struct super_block { spinlock_t s_inode_wblist_lock; struct list_head s_inodes_wb; /* writeback inodes */ + + struct list_head s_bdi_list; } __randomize_layout; /* Helper functions so that in most cases filesystems will @@ -1830,6 +1832,8 @@ struct super_operations { struct shrink_control *); long (*free_cached_objects)(struct super_block *, struct shrink_control *); + void (*write_metadata)(struct super_block *sb, + struct writeback_control *wbc); }; /* diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 57f1dbc41f7e..99a352f943ea 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -834,8 +834,10 @@ static int bdi_init(struct backing_dev_info *bdi) bdi->min_ratio = 0; bdi->max_ratio = 100; bdi->max_prop_frac = FPROP_FRAC_BASE; + spin_lock_init(&bdi->sb_list_lock); INIT_LIST_HEAD(&bdi->bdi_list); INIT_LIST_HEAD(&bdi->wb_list); + INIT_LIST_HEAD(&bdi->dirty_sb_list); init_waitqueue_head(&bdi->wb_waitq); ret = cgwb_bdi_init(bdi);