Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp169735ybl; Wed, 4 Dec 2019 00:17:41 -0800 (PST) X-Google-Smtp-Source: APXvYqxx+UVqVI+sr/JDKTmKpNaRhaDqqWqwKtCJhPkuuI8Kgq5SQJhJp3BG1IYeZ0fzxBl4MwO2 X-Received: by 2002:a9d:5388:: with SMTP id w8mr1496300otg.368.1575447461881; Wed, 04 Dec 2019 00:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575447461; cv=none; d=google.com; s=arc-20160816; b=qiS4pTKu4CGdoKGKgX/wwXW3cAaN+xVUZ/OEngB/hRXqXL+bQ1f2B5gFIVHoNgKGPI JOfyKxIiYDEteZbr4bcdFg2+r7dzPM+KXttr7hC1FnWLTSMOlkDjTlgZuAHbk2qYXEG3 gsX0M/gCx/RjQ5KCzZl1lV7aWLLsb2mHC7cMDgxlpeRe7PP+zz8LZJmP4HlN/Gmzn+mA BHprsoxd5pNzK07bimDEafJyrhbjiFPifuIwz41WWJqpuTrfIkrf8uRZ9pROU0e+VDjF 1CsCKxVOpMKeq92kFoztzucrU1xUlMdXDKgTiSmFzE22VOMeYk6a8d3bODsccoQ15/cx ocMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=A3EjttU8t1DCaxtv3QmwTcUqJUdcBQEbi7gg5HzyUUg=; b=XbvVeAIMwumglqkB+Bpzo0I/pYllrmXIPd4tiOckV3v2JB2NQKJqrEZ5rKIOpTwPAS hBolIub/JcMPVeaDHc5DcaW2Mul58fRfYQUe1yNPFwcQgtCNcfXLJ2rY5GuxKwV3WMr0 LALxEPAc2ex1/LQngu93Mt2F3l+yGZGQm9cV23/LNM+Nz6lJfpI8sW9W2E5gM+TGdLOs 9mNNnpupKgULIrMzU1+qteVX2CJhhv+VKgOayioI1kO1jMTZBZIjpydalMNDsn8+sgyA 2fHkeml9VAGMrnO3N/DB+iK/KqhL7ZDac8xikHXbkVnOEZBdDuC66je2Gg0dEnNbqw0d 0BKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=XC4SD8Nm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g25si2628862otk.240.2019.12.04.00.17.28; Wed, 04 Dec 2019 00:17:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=XC4SD8Nm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbfLDIQr (ORCPT + 99 others); Wed, 4 Dec 2019 03:16:47 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39883 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725951AbfLDIQr (ORCPT ); Wed, 4 Dec 2019 03:16:47 -0500 Received: by mail-wr1-f67.google.com with SMTP id y11so7357945wrt.6 for ; Wed, 04 Dec 2019 00:16:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=A3EjttU8t1DCaxtv3QmwTcUqJUdcBQEbi7gg5HzyUUg=; b=XC4SD8Nm/CJsVX2cNdH7LMWWN1jdVbSSfwd5CoVNQMApFZ+METGkcdcOx2Hm/HnLn7 p5o53EPcTISnscB7YQ3Y9dglaKVNaQnve9q4h2ZwxJQR/MdFfdC7o6AjnJqXsi6eElZb ejtUwfloOEdNVnXzKDxOgjYzLHhO7l8WMX0SUBahb/mhtCnl7eci/+AVJn47kzjbCiU1 0fQJ7xnwFY8h0qKjFkKbjGbtsPtZdZVX/M6S6QuBjuls6n7ouePAkdN4MP43579p06dk 9gEW0OmWqbL+XeR8HcAhI4UJJo3BdbQW3STwibFTMTinesHQFa0m1amtrRRmaOOo2Cs5 LJgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=A3EjttU8t1DCaxtv3QmwTcUqJUdcBQEbi7gg5HzyUUg=; b=XZ4Y/1gB4dSqnZc4IkqF/2fjN1Pi6SZl6T4w+ei53+gBU7DnP6zbKcol8lvgsUMEa6 SIBA8o57E6hZwQ54+YyqjTgb+eGfmdt52nlNb1cga1Dn0SvV12dWef6LvhaTVHvE1yAu 2mTOWWRz0SmOZP7CSq7wHRUAiXfEsEgwyZ1ALBSnegKepeCyIewBjteXRECxHgYtIk2H aovEpN8DCGkashj7smCHv9KFOC98mapFuRNmR/PIE0pV1vb+Pq0AkH8qAYnMNiMUeFNM UQNM0Wue6z28fYVAZLRbDTH9YIHoo1evvywl+hLXQ3WB19Ce0/YFxmjglXaohwDzgh1y bH0A== X-Gm-Message-State: APjAAAWomubcJj1EkDlk/KF5ZR/82LH/su+LLc4rC1MfGuMD4Jg/IPLX 3sPTGO49dedA7jGORi5TxMWJQg== X-Received: by 2002:adf:dd46:: with SMTP id u6mr2599078wrm.13.1575447404312; Wed, 04 Dec 2019 00:16:44 -0800 (PST) Received: from localhost ([194.62.217.57]) by smtp.gmail.com with ESMTPSA id g21sm8286034wrb.48.2019.12.04.00.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 00:16:43 -0800 (PST) Date: Wed, 4 Dec 2019 09:16:42 +0100 From: Javier Gonzalez To: Jaegeuk Kim Cc: Damien Le Moal , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , linux-fsdevel@vger.kernel.org, Shinichiro Kawasaki Subject: Re: [PATCH v2] f2fs: Fix direct IO handling Message-ID: <20191204081642.gnd55byogedrhfoz@MacBook-Pro.gnusmas> References: <20191126075719.1046485-1-damien.lemoal@wdc.com> <20191126234428.GB20652@jaegeuk-macbookpro.roam.corp.google.com> <20191203173308.GA41093@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191203173308.GA41093@jaegeuk-macbookpro.roam.corp.google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03.12.2019 09:33, Jaegeuk Kim wrote: >Thank you for checking the patch. >I found some regressions in xfstests, so want to follow the Damien's one >like below. > >Thanks, > >=== >From 9df6f09e3a09ed804aba4b56ff7cd9524c002e69 Mon Sep 17 00:00:00 2001 >From: Jaegeuk Kim >Date: Tue, 26 Nov 2019 15:01:42 -0800 >Subject: [PATCH] f2fs: preallocate DIO blocks when forcing buffered_io > >The previous preallocation and DIO decision like below. > > allow_outplace_dio !allow_outplace_dio >f2fs_force_buffered_io (*) No_Prealloc / Buffered_IO Prealloc / Buffered_IO >!f2fs_force_buffered_io No_Prealloc / DIO Prealloc / DIO > >But, Javier reported Case (*) where zoned device bypassed preallocation but >fell back to buffered writes in f2fs_direct_IO(), resulting in stale data >being read. > >In order to fix the issue, actually we need to preallocate blocks whenever >we fall back to buffered IO like this. No change is made in the other cases. > > allow_outplace_dio !allow_outplace_dio >f2fs_force_buffered_io (*) Prealloc / Buffered_IO Prealloc / Buffered_IO >!f2fs_force_buffered_io No_Prealloc / DIO Prealloc / DIO > >Reported-and-tested-by: Javier Gonzalez >Signed-off-by: Damien Le Moal >Tested-by: Shin'ichiro Kawasaki >Signed-off-by: Jaegeuk Kim >--- > fs/f2fs/data.c | 13 ------------- > fs/f2fs/file.c | 43 +++++++++++++++++++++++++++++++++---------- > 2 files changed, 33 insertions(+), 23 deletions(-) > >diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >index a034cd0ce021..fc40a72f7827 100644 >--- a/fs/f2fs/data.c >+++ b/fs/f2fs/data.c >@@ -1180,19 +1180,6 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) > int err = 0; > bool direct_io = iocb->ki_flags & IOCB_DIRECT; > >- /* convert inline data for Direct I/O*/ >- if (direct_io) { >- err = f2fs_convert_inline_inode(inode); >- if (err) >- return err; >- } >- >- if (direct_io && allow_outplace_dio(inode, iocb, from)) >- return 0; >- >- if (is_inode_flag_set(inode, FI_NO_PREALLOC)) >- return 0; >- > map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); > map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); > if (map.m_len > map.m_lblk) >diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >index c0560d62dbee..0e1b12a4a4d6 100644 >--- a/fs/f2fs/file.c >+++ b/fs/f2fs/file.c >@@ -3386,18 +3386,41 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) > ret = -EAGAIN; > goto out; > } >- } else { >- preallocated = true; >- target_size = iocb->ki_pos + iov_iter_count(from); >+ goto write; >+ } > >- err = f2fs_preallocate_blocks(iocb, from); >- if (err) { >- clear_inode_flag(inode, FI_NO_PREALLOC); >- inode_unlock(inode); >- ret = err; >- goto out; >- } >+ if (is_inode_flag_set(inode, FI_NO_PREALLOC)) >+ goto write; >+ >+ if (iocb->ki_flags & IOCB_DIRECT) { >+ /* >+ * Convert inline data for Direct I/O before entering >+ * f2fs_direct_IO(). >+ */ >+ err = f2fs_convert_inline_inode(inode); >+ if (err) >+ goto out_err; >+ /* >+ * 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) && >+ allow_outplace_dio(inode, iocb, from)) >+ goto write; >+ } >+ preallocated = true; >+ target_size = iocb->ki_pos + iov_iter_count(from); >+ >+ err = f2fs_preallocate_blocks(iocb, from); >+ if (err) { >+out_err: >+ clear_inode_flag(inode, FI_NO_PREALLOC); >+ inode_unlock(inode); >+ ret = err; >+ goto out; > } >+write: > ret = __generic_file_write_iter(iocb, from); > clear_inode_flag(inode, FI_NO_PREALLOC); > >-- >2.19.0.605.g01d371f741-goog > > Looks good to me. It also fixes the problem we see in our end. Reviewed-by: Javier González