From patchwork Tue Jul 21 08:37:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Dongsheng X-Patchwork-Id: 6833401 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7F86C9F358 for ; Tue, 21 Jul 2015 08:46:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D1CF20693 for ; Tue, 21 Jul 2015 08:46:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68F2020690 for ; Tue, 21 Jul 2015 08:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753635AbbGUInw (ORCPT ); Tue, 21 Jul 2015 04:43:52 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7296 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754000AbbGUInu (ORCPT ); Tue, 21 Jul 2015 04:43:50 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="98671210" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Jul 2015 16:47:23 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6L8fqU0005031; Tue, 21 Jul 2015 16:41:52 +0800 Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 21 Jul 2015 16:43:39 +0800 From: Dongsheng Yang To: , , CC: , , Dongsheng Yang Subject: [PATCH 13/25] ubifs: introduce a field named as budgeted to ubifs_inode Date: Tue, 21 Jul 2015 16:37:44 +0800 Message-ID: <1437467876-22106-14-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a long-term pain in ubifs, we have to introduce a ui_mutex in ubifs_inode to solve two problems below: 1: make some process atomic, such as ubifs_rename. 2: make sure we budget space for inode before dirting it. About 1, it's true and we have to do it. About 2, we can do it better. There is a ubifs_assert(mutex_is_locked(&ui->mutex)) in ubifs_dirty_inode(). But there is probably some processes are very long, and we can not make all of it into a pair of lock/unlock ui->mutex. E.g: dquot_disable(). It would mark the quota files as dirty and write the inode back. We can do a budget before this function, but we can not make the whole dquot_disable() into mutex_lock/mutex_unlock. Because we need to lock the ui_mutex in dquot_disable(). So, this commit introduce a ui->budgeted to allow us to make budgeting and dirting in two different lock windows. Result: ubifs_budget_space() mutex_lock(); ui->budgeted = 1; mutex_unlock(); ... dquot_disable(); Signed-off-by: Dongsheng Yang --- fs/ubifs/file.c | 7 +++++++ fs/ubifs/ioctl.c | 1 + fs/ubifs/super.c | 14 +++++++++++++- fs/ubifs/ubifs.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index dc8bf0b..113c3a6 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -307,6 +307,7 @@ static int write_begin_slow(struct address_space *mapping, * budget we allocated. */ ubifs_release_dirty_inode_budget(c, ui); + ui->budgeted = 1; } *pagep = page; @@ -357,6 +358,7 @@ static int allocate_budget(struct ubifs_info *c, struct page *page, * we need to budget the inode change. */ req.dirtied_ino = 1; + ui->budgeted = 1; } else { if (PageChecked(page)) /* @@ -384,6 +386,7 @@ static int allocate_budget(struct ubifs_info *c, struct page *page, * needs a budget. */ req.dirtied_ino = 1; + ui->budgeted = 1; } } @@ -1237,6 +1240,7 @@ static int do_setattr(struct ubifs_info *c, struct inode *inode, do_attr_changes(inode, attr); release = ui->dirty; + ui->budgeted = 1; if (attr->ia_valid & ATTR_SIZE) /* * Inode length changed, so we have to make sure @@ -1397,6 +1401,7 @@ static int ubifs_update_time(struct inode *inode, struct timespec *time, iflags |= I_DIRTY_SYNC; release = ui->dirty; + ui->budgeted = 1; __mark_inode_dirty(inode, iflags); mutex_unlock(&ui->ui_mutex); if (release) @@ -1430,6 +1435,7 @@ static int update_mctime(struct inode *inode) mutex_lock(&ui->ui_mutex); inode->i_mtime = inode->i_ctime = ubifs_current_time(inode); release = ui->dirty; + ui->budgeted = 1; mark_inode_dirty_sync(inode); mutex_unlock(&ui->ui_mutex); if (release) @@ -1556,6 +1562,7 @@ static int ubifs_vm_page_mkwrite(struct vm_area_struct *vma, mutex_lock(&ui->ui_mutex); inode->i_mtime = inode->i_ctime = ubifs_current_time(inode); release = ui->dirty; + ui->budgeted = 1; mark_inode_dirty_sync(inode); mutex_unlock(&ui->ui_mutex); if (release) diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index 3c7b29d..f015b81 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -128,6 +128,7 @@ static int setflags(struct inode *inode, int flags) ubifs_set_inode_flags(inode); inode->i_ctime = ubifs_current_time(inode); release = ui->dirty; + ui->budgeted = 1; mark_inode_dirty_sync(inode); mutex_unlock(&ui->ui_mutex); diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 2491fff..5fa21d6 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -331,6 +331,7 @@ static int ubifs_write_inode(struct inode *inode, struct writeback_control *wbc) } ui->dirty = 0; + ui->budgeted = 0; mutex_unlock(&ui->ui_mutex); ubifs_release_dirty_inode_budget(c, ui); return err; @@ -386,12 +387,23 @@ done: static void ubifs_dirty_inode(struct inode *inode, int flags) { struct ubifs_inode *ui = ubifs_inode(inode); + int need_unlock = 0; - ubifs_assert(mutex_is_locked(&ui->ui_mutex)); + if (unlikely(!mutex_is_locked(&ui->ui_mutex))) { + /* We need to lock ui_mutex to access ui->budgeted */ + mutex_lock(&ui->ui_mutex); + need_unlock = 1; + } + + /* Check the budget for this inode */ + ubifs_assert(ui->budgeted); if (!ui->dirty) { ui->dirty = 1; dbg_gen("inode %lu", inode->i_ino); } + + if (need_unlock) + mutex_unlock(&ui->ui_mutex); } static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf) diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 9754bb6..28392a6 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -410,6 +410,7 @@ struct ubifs_inode { unsigned int xattr_cnt; unsigned int xattr_names; unsigned int dirty:1; + unsigned int budgeted:1; unsigned int xattr:1; unsigned int bulk_read:1; unsigned int compr_type:2;