Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1091095ybt; Wed, 17 Jun 2020 23:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr7Jc/JQhXPNGRq4ZMFrak5EBKFUbkZ1rXBfTS1HvhH2k/s5GuHjH4mhOAHayxUR+n9ZoK X-Received: by 2002:a05:6402:1714:: with SMTP id y20mr2670491edu.81.1592462456666; Wed, 17 Jun 2020 23:40:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592462456; cv=none; d=google.com; s=arc-20160816; b=CU2iRa+wj1QjkBYxK1klndp6qo3xCAuOLSQUQuKo4UA4n0t+sKjXqqKclRZ16y0/ii uVcZFXG/lHzlrwsXp8bQv5jIWKA08GJ1GWP0DVxCtizHwhfkNoc7ZEf0nI1P76WoHSgJ vRWENxg6JjE8PKi+0ONOjSQJHTa+5/crb5gd9H+2IIHEvW10SqOAsMepPDYaEJAY8TDL v3kfKUcWbI+7+oiIO3momfw8+1z5NlgdY9wnnXgIBR0PxZYvxZEwayOersfujxXhF5ha 0l3yBO1ALNAHNzRpSB3o1lxoh2wGjesyIqFGvYIaFtexUYiWsQwwD8gLzt1qRxisRKo/ KkeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=+rJhrzVoa2NUbXAlMKXRCjfNHDF12wFZUXH5ckydcNQ=; b=sd8ujFqIKqSdWZ0eJJN5wHWbqZDfh7IrTnV2MfyFToSKoJ4JIxikA4Z/y7BZwGG1JF LaGwCc+M/zBPwSu/71YH1sKGUyeWwgeZ1Zp87+4FXOFbMHD0p2QudHsccpWXKIMTvZLT A6MaZ1esbYVV1o5dgapOqaM6LicEXuG4aUTta0iO49srS0RkQ9TcKaFd93Y5edLUOjvm a52qAZifKUOEjR/7WcajumXQB4vGBpqwX5p9dY7y/TimCazDE8wGC0IBh4vdZuPz5Hft 3uTdj5MYwNeZoKv4KaoKopQqUfuCuEK9j9/3EBQ+09r/ZWJCZuC6a9x/8adMU17JoWc+ JqQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k3si1380889ejx.122.2020.06.17.23.40.31; Wed, 17 Jun 2020 23:40:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgFRGg7 (ORCPT + 99 others); Thu, 18 Jun 2020 02:36:59 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6360 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726952AbgFRGg7 (ORCPT ); Thu, 18 Jun 2020 02:36:59 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7EA343DA2EC6CFCA4384; Thu, 18 Jun 2020 14:36:40 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Thu, 18 Jun 2020 14:36:32 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 3/5] f2fs: shrink node_write lock coverage Date: Thu, 18 Jun 2020 14:36:23 +0800 Message-ID: <20200618063625.110273-3-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 In-Reply-To: <20200618063625.110273-1-yuchao0@huawei.com> References: <20200618063625.110273-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - to avoid race between checkpoint and quota file writeback, it just needs to hold read lock of node_write in writeback path. - node_write lock has covered all LFS data write paths, it's not necessary, we only need to hold node_write lock at write path of quota file. Signed-off-by: Chao Yu --- fs/f2fs/compress.c | 18 +++++++++++++++--- fs/f2fs/data.c | 12 ++++++++++++ fs/f2fs/segment.c | 11 ----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 36b51795b0c3..3ff6c0305ec6 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1096,8 +1096,16 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, loff_t psize; int i, err; - if (!IS_NOQUOTA(inode) && !f2fs_trylock_op(sbi)) + if (IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + down_read(&sbi->node_write); + } else if (!f2fs_trylock_op(sbi)) { return -EAGAIN; + } set_new_dnode(&dn, cc->inode, NULL, NULL, 0); @@ -1203,7 +1211,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN); f2fs_put_dnode(&dn); - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); spin_lock(&fi->i_size_lock); @@ -1230,7 +1240,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, out_put_dnode: f2fs_put_dnode(&dn); out_unlock_op: - if (!IS_NOQUOTA(inode)) + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + else f2fs_unlock_op(sbi); return -EAGAIN; } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c78ce08f6400..cbdf062d3562 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2719,8 +2719,20 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, /* Dentry/quota blocks are controlled by checkpoint */ if (S_ISDIR(inode->i_mode) || IS_NOQUOTA(inode)) { + /* + * We need to wait for node_write to avoid block allocation during + * checkpoint. This can only happen to quota writes which can cause + * the below discard race condition. + */ + if (IS_NOQUOTA(inode)) + down_read(&sbi->node_write); + fio.need_lock = LOCK_DONE; err = f2fs_do_write_data_page(&fio); + + if (IS_NOQUOTA(inode)) + up_read(&sbi->node_write); + goto done; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 5b2a6f865a6d..cb861ed98ee3 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3107,14 +3107,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, type = CURSEG_COLD_DATA; } - /* - * We need to wait for node_write to avoid block allocation during - * checkpoint. This can only happen to quota writes which can cause - * the below discard race condition. - */ - if (IS_DATASEG(type)) - down_write(&sbi->node_write); - down_read(&SM_I(sbi)->curseg_lock); mutex_lock(&curseg->curseg_mutex); @@ -3180,9 +3172,6 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, up_read(&SM_I(sbi)->curseg_lock); - if (IS_DATASEG(type)) - up_write(&sbi->node_write); - if (put_pin_sem) up_read(&sbi->pin_sem); } -- 2.18.0.rc1