Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp758993ybt; Wed, 1 Jul 2020 09:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzn8wQwYuz2fS3FtAj0QfVVzcK8bho9teRMTMFKZaScP5kCR9upyIZKC6U38EFwWq5Iqwv X-Received: by 2002:a17:906:fac3:: with SMTP id lu3mr16197120ejb.374.1593620301163; Wed, 01 Jul 2020 09:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593620301; cv=none; d=google.com; s=arc-20160816; b=c6wI0lOjf5526UXRskds/F+7xtXhITbxlwh9un6aLornzLfEqn77hdoLR2K7w4F3gA H1qkhvke7lMDRX9LtqHOVHPAUFlq9ydTx6LUBpeHt2GHFcD55sAfO/zsYC9YnnuL9qba LVi8vTm3jDG6r0TuxgXAi34Zdb+UV1Lj7qAGaLJ8CWkMlx10SLfC9qwQy8oNv9sWB6Y4 K6u6iEUeBaR4bwgzrga4WiqYSHKxndIRTYyPqT+ShoxhbsWmy9jdRkxlmzMX6Ap0RYp2 yg5fuZNmYu1Wq0giYUO42qWKvqYYFMaSCD6XOpBXlDGwai2/uYOLizgKUjARXEzgfutc LR1A== 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=OkFjRfsAjps4q5BZOeMRnFuTrh8wyj/wqSyqCxYJOH4=; b=w1MWh+WTKT6GmwTblVWmAvyj+jimhuX2gayt7/nUjOTPlWzkhEPZJEYjUgqMUa2jf7 CUbSy8vXNcAp8D6mBJG6RA9AhfIe7xMYMYO6P9FeYafCMZpixXJpYlqPxtXgu3Ub4/uq rGEd0sYtNemGCYskHW6Y3LyALy1MWAvN4T+4qgMrjTaHeuxTEToA7743BCc4bJy1DjbW m3xtDr7VFbaTgzkE+DZOThi5GlinNSdf/5nzI1zYRA8SCqPS4pSA0RaiyfKR2u21oe34 TJEj7PvuTMyNHRF8ggH/PFbl9jtM+t1D1Oy5yC+i1SVh+KMkoez7ttH0JarXT32yc0NP Cirg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RannkZZx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si2184732edz.108.2020.07.01.09.17.58; Wed, 01 Jul 2020 09:18:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=RannkZZx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732297AbgGAQOo (ORCPT + 99 others); Wed, 1 Jul 2020 12:14:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:44380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731948AbgGAQOn (ORCPT ); Wed, 1 Jul 2020 12:14:43 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D077B207FB; Wed, 1 Jul 2020 16:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593620082; bh=vvX5vaeR82uMFf05stT8fYK8rwwdtEyVA9ggdjIUTSk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RannkZZxUNr/2BO7IaAn8Qr+8Phk2tvtIMdK4syCoQuo0bI6dP7tnUrGkL3XamGdi 3CLO4HRmAPF8jjYENRZ4Vz8v3lrJ0JXUml2WVg2Ra6cfhn1K25YMWtT/4UPO1kbs+w P02+rvCCDKBa5pPZIMuBH8qcvS/oQzQ4escNjoac= Date: Wed, 1 Jul 2020 09:14:42 -0700 From: Jaegeuk Kim To: Chao Yu Cc: Nathan Chancellor , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v3] f2fs: avoid readahead race condition Message-ID: <20200701161442.GB1724572@google.com> References: <20200624012148.180050-1-jaegeuk@kernel.org> <20200629150323.GA3293033@google.com> <20200629202720.GA230664@google.com> <20200630204348.GA2504307@ubuntu-s3-xlarge-x86> <20200630205635.GB1396584@google.com> <285a4e16-2cbc-d1e9-8464-8a06bacbaaa0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/01, Chao Yu wrote: > On 2020/7/1 9:59, Chao Yu wrote: > > On 2020/7/1 4:56, Jaegeuk Kim wrote: > >> On 06/30, Nathan Chancellor wrote: > >>> On Mon, Jun 29, 2020 at 01:27:20PM -0700, Jaegeuk Kim wrote: > >>>> If two readahead threads having same offset enter in readpages, every read > >>>> IOs are split and issued to the disk which giving lower bandwidth. > >>>> > >>>> This patch tries to avoid redundant readahead calls. > >>>> > >>>> Signed-off-by: Jaegeuk Kim > >>>> --- > >>>> v3: > >>>> - use READ|WRITE_ONCE > >>>> v2: > >>>> - add missing code to bypass read > >>>> > >>>> fs/f2fs/data.c | 18 ++++++++++++++++++ > >>>> fs/f2fs/f2fs.h | 1 + > >>>> fs/f2fs/super.c | 2 ++ > >>>> 3 files changed, 21 insertions(+) > >>>> > >>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > >>>> index 995cf78b23c5e..360b4c9080d97 100644 > >>>> --- a/fs/f2fs/data.c > >>>> +++ b/fs/f2fs/data.c > >>>> @@ -2296,6 +2296,7 @@ static int f2fs_mpage_readpages(struct inode *inode, > >>>> unsigned nr_pages = rac ? readahead_count(rac) : 1; > >>>> unsigned max_nr_pages = nr_pages; > >>>> int ret = 0; > >>>> + bool drop_ra = false; > >>>> > >>>> map.m_pblk = 0; > >>>> map.m_lblk = 0; > >>>> @@ -2306,10 +2307,24 @@ static int f2fs_mpage_readpages(struct inode *inode, > >>>> map.m_seg_type = NO_CHECK_TYPE; > >>>> map.m_may_create = false; > >>>> > >>>> + /* > >>>> + * Two readahead threads for same address range can cause race condition > >>>> + * which fragments sequential read IOs. So let's avoid each other. > >>>> + */ > >>>> + if (rac && readahead_count(rac)) { > >>>> + if (READ_ONCE(F2FS_I(inode)->ra_offset) == readahead_index(rac)) > >>>> + drop_ra = true; > >>>> + else > >>>> + WRITE_ONCE(F2FS_I(inode)->ra_offset, > >>>> + readahead_index(rac)); > >>>> + } > >>>> + > >>>> for (; nr_pages; nr_pages--) { > >>>> if (rac) { > >>>> page = readahead_page(rac); > >>>> prefetchw(&page->flags); > >>>> + if (drop_ra) > >>>> + goto next_page; > >>> > >>> When CONFIG_F2FS_FS_COMPRESSION is not set (i.e. x86_64 defconfig + > >>> CONFIG_F2FS_FS=y): > >>> > >>> $ make -skj"$(nproc)" O=out distclean defconfig fs/f2fs/data.o > >>> ../fs/f2fs/data.c: In function ‘f2fs_mpage_readpages’: > >>> ../fs/f2fs/data.c:2327:5: error: label ‘next_page’ used but not defined > >>> 2327 | goto next_page; > >>> | ^~~~ > >>> ... > >> > >> Thanks. I pushed the fix for -next. > >> https://lore.kernel.org/linux-f2fs-devel/1be18397-7fc6-703e-121b-e210e101357f@infradead.org/T/#t > > It will hang the kernel because we missed to unlock those cached pages, > I changed to 'goto set_error_page', the issue was gone. How about v4? > > Thanks, > > > > > Reviewed-by: Chao Yu > > > > Thanks, > > > >> > >> Thanks, > >> > >>> > >>> Cheers, > >>> Nathan > >>> > >>> > >>> _______________________________________________ > >>> Linux-f2fs-devel mailing list > >>> Linux-f2fs-devel@lists.sourceforge.net > >>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >> > >> > >> _______________________________________________ > >> Linux-f2fs-devel mailing list > >> Linux-f2fs-devel@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >> > > > > > > _______________________________________________ > > Linux-f2fs-devel mailing list > > Linux-f2fs-devel@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >