From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D42CC4338F for ; Sun, 25 Jul 2021 10:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DCDD60295 for ; Sun, 25 Jul 2021 10:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230195AbhGYKKY (ORCPT ); Sun, 25 Jul 2021 06:10:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:52728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbhGYKKY (ORCPT ); Sun, 25 Jul 2021 06:10:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B169260E09; Sun, 25 Jul 2021 10:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627210254; bh=yQbrkcDM1yJmK+PftQjYegtYQ1gnnfPgYmC1lw0cjwo=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=pN7HlkVX4xMxq6PYGr86ouHgYPN4BM2tSJa5oUD15kkgc1b+9w8Y2sEy6SEHKzr81 +uZkRPeeqTE8Z+QH7n9Ty/zswhUrPB46PhIpL0nA+bczwBPF+m62Z9bj+oAscjeUGd KY7YQfzXlPBozAkQh6fhM/IP7HhTUJDEpADa3XbKr1hxLdG5cOmimsafF7eQYe+YqY VHxvo3u5L0SOsrJjdG0ozEX3uQtxqFG5bAUtHHzgBvCPmXZw7vd2RDUQDfbJYcXtHu TzhkWQv8pNLZvbj+xmyFcvqAqMt+eicbMHJPPeFqL+CqOxodBVe7E5MWtRXiJP7HML 0+9q4Z73B0gWg== Subject: Re: [PATCH 3/9] f2fs: rework write preallocations To: Eric Biggers , linux-f2fs-devel@lists.sourceforge.net, Jaegeuk Kim Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, Satya Tangirala , Changheun Lee , Matthew Bobrowski References: <20210716143919.44373-1-ebiggers@kernel.org> <20210716143919.44373-4-ebiggers@kernel.org> From: Chao Yu Message-ID: <14782036-f6a5-878a-d21f-e7dd7008a285@kernel.org> Date: Sun, 25 Jul 2021 18:50:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210716143919.44373-4-ebiggers@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On 2021/7/16 22:39, Eric Biggers wrote: > From: Eric Biggers > > f2fs_write_begin() assumes that all blocks were preallocated by > default unless FI_NO_PREALLOC is explicitly set. This invites data > corruption, as there are cases in which not all blocks are preallocated. > Commit 47501f87c61a ("f2fs: preallocate DIO blocks when forcing > buffered_io") fixed one case, but there are others remaining. Could you please explain which cases we missed to handle previously? then I can check those related logic before and after the rework. > - /* > - * If force_buffere_io() is true, we have to allocate > - * blocks all the time, since f2fs_direct_IO will fall > - * back to buffered IO. > - */ > - if (!f2fs_force_buffered_io(inode, iocb, from) && > - f2fs_lfs_mode(F2FS_I_SB(inode))) We should keep this OPU DIO logic, otherwise, in lfs mode, write dio will always allocate two block addresses for each 4k append IO. I jsut test based on codes of last f2fs dev-test branch. rm /mnt/f2fs/dio dd if=/dev/zero of=/mnt/f2fs/dio bs=4k count=4 oflag=direct <...>-763176 [001] ...1 177258.793370: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 0, start blkaddr = 0xe1a2e, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 <...>-763176 [001] ...1 177258.793462: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 0, start blkaddr = 0xe1a2f, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793575: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 1, start blkaddr = 0xe1a30, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793599: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 1, start blkaddr = 0xe1a31, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793735: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 2, start blkaddr = 0xe1a32, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793769: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 2, start blkaddr = 0xe1a33, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793859: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 3, start blkaddr = 0xe1a34, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793885: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 3, start blkaddr = 0xe1a35, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 Thanks, From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB89FC4338F for ; Sun, 25 Jul 2021 10:51:14 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82D3A6024A; Sun, 25 Jul 2021 10:51:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 82D3A6024A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.92.3) (envelope-from ) id 1m7bix-0004jA-7I; Sun, 25 Jul 2021 10:51:11 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1m7biw-0004j4-GD for linux-f2fs-devel@lists.sourceforge.net; Sun, 25 Jul 2021 10:51:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OV5Ba5LMV+6i6zFX3oSWaoYj75pw0AA1iPldqqmgNK0=; b=KPlZ4Qp6NopCHmc3swloun0eMQ 8BwY/bXdiSHMj+N8/cbyJm3xEe9UgI/xlmS6u4bYxEVcYhoNdfufd/kyS2HstZHCxNYEhjGi3RWjd gtQvEsNPSTAFQ748qFC3v09VyC3VQ+ax6e0qqTuib1NJP2KCGOuF2plUmcrqNXhkCsqQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:References:Cc:To:Subject:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=OV5Ba5LMV+6i6zFX3oSWaoYj75pw0AA1iPldqqmgNK0=; b=FVCwyRPvt5Sr7PzbFYFL9ZlJp2 LKxl9uVaXhdbq6cjBmkMzhlmNH5kQiQR2cFv9tTzFfijM86vH0uaFZ8k31LlMTxibBvxM05UL7Cg6 qqMJAHET8FhywU7fTcGhm9eWQwLwxeCeFQ/tuzD7uB7snsWRvUiPPRLJHkZ3lmUPG1OY=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1m7bil-00020K-NF for linux-f2fs-devel@lists.sourceforge.net; Sun, 25 Jul 2021 10:51:10 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B169260E09; Sun, 25 Jul 2021 10:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627210254; bh=yQbrkcDM1yJmK+PftQjYegtYQ1gnnfPgYmC1lw0cjwo=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=pN7HlkVX4xMxq6PYGr86ouHgYPN4BM2tSJa5oUD15kkgc1b+9w8Y2sEy6SEHKzr81 +uZkRPeeqTE8Z+QH7n9Ty/zswhUrPB46PhIpL0nA+bczwBPF+m62Z9bj+oAscjeUGd KY7YQfzXlPBozAkQh6fhM/IP7HhTUJDEpADa3XbKr1hxLdG5cOmimsafF7eQYe+YqY VHxvo3u5L0SOsrJjdG0ozEX3uQtxqFG5bAUtHHzgBvCPmXZw7vd2RDUQDfbJYcXtHu TzhkWQv8pNLZvbj+xmyFcvqAqMt+eicbMHJPPeFqL+CqOxodBVe7E5MWtRXiJP7HML 0+9q4Z73B0gWg== To: Eric Biggers , linux-f2fs-devel@lists.sourceforge.net, Jaegeuk Kim References: <20210716143919.44373-1-ebiggers@kernel.org> <20210716143919.44373-4-ebiggers@kernel.org> From: Chao Yu Message-ID: <14782036-f6a5-878a-d21f-e7dd7008a285@kernel.org> Date: Sun, 25 Jul 2021 18:50:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210716143919.44373-4-ebiggers@kernel.org> Content-Language: en-US X-Headers-End: 1m7bil-00020K-NF Subject: Re: [f2fs-dev] [PATCH 3/9] f2fs: rework write preallocations X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, Matthew Bobrowski , Satya Tangirala , Changheun Lee Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2021/7/16 22:39, Eric Biggers wrote: > From: Eric Biggers > > f2fs_write_begin() assumes that all blocks were preallocated by > default unless FI_NO_PREALLOC is explicitly set. This invites data > corruption, as there are cases in which not all blocks are preallocated. > Commit 47501f87c61a ("f2fs: preallocate DIO blocks when forcing > buffered_io") fixed one case, but there are others remaining. Could you please explain which cases we missed to handle previously? then I can check those related logic before and after the rework. > - /* > - * If force_buffere_io() is true, we have to allocate > - * blocks all the time, since f2fs_direct_IO will fall > - * back to buffered IO. > - */ > - if (!f2fs_force_buffered_io(inode, iocb, from) && > - f2fs_lfs_mode(F2FS_I_SB(inode))) We should keep this OPU DIO logic, otherwise, in lfs mode, write dio will always allocate two block addresses for each 4k append IO. I jsut test based on codes of last f2fs dev-test branch. rm /mnt/f2fs/dio dd if=/dev/zero of=/mnt/f2fs/dio bs=4k count=4 oflag=direct <...>-763176 [001] ...1 177258.793370: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 0, start blkaddr = 0xe1a2e, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 <...>-763176 [001] ...1 177258.793462: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 0, start blkaddr = 0xe1a2f, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793575: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 1, start blkaddr = 0xe1a30, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793599: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 1, start blkaddr = 0xe1a31, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793735: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 2, start blkaddr = 0xe1a32, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793769: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 2, start blkaddr = 0xe1a33, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793859: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 3, start blkaddr = 0xe1a34, len = 0x1, flags = 48,seg_type = 1, may_create = 1, err = 0 dd-763176 [001] ...1 177258.793885: f2fs_map_blocks: dev = (259,1), ino = 6, file offset = 3, start blkaddr = 0xe1a35, len = 0x1, flags = 16,seg_type = 1, may_create = 1, err = 0 Thanks, _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel