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.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 404EFC433DF for ; Mon, 29 Jun 2020 18:24:34 +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 16D33255D4; Mon, 29 Jun 2020 18:24:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="alCA23yg"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="E11XuN+7"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="VLYj4Vfu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16D33255D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@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.90_1) (envelope-from ) id 1jpySH-0000E6-ON; Mon, 29 Jun 2020 18:24:33 +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.90_1) (envelope-from ) id 1jpySF-0000Du-PO for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jun 2020 18:24:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: 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=EcZm6LEuE9ZlsSoO9HFDjOlCJ1W6WJ65go2sMD0RQnE=; b=alCA23ygn3oum0cU8YPmgIWX/r thww2GW3KaN1tK16A94xjVNak3QvnNbku5TbPtnJ+CsEBCRnyQpt0aqBtofV+WgTPqssMrKFjZprh CBgwb6VJaiTViTEOghNYK6+gP1Cfod1/EMglZYHAOPn3ekRzb1ZLbR02mc4rTNi7GdzA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding: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=EcZm6LEuE9ZlsSoO9HFDjOlCJ1W6WJ65go2sMD0RQnE=; b=E11XuN+74rVh7/+hB/df8iHK5p 7hf+0R3819m5hLGCuhEKHwOSaTZqp6m7sHkxgX1LOjXqoHWk7mXVz2VbtctaZPvwzDnSR0CgMWs7+ OJzwoG6YQ892yP99OSMFFcI7tOekq7w8dECe/jenXK+8IfbHx1zotW5jr0M51TE1Bpg8=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jpySB-006PKF-6O for linux-f2fs-devel@lists.sourceforge.net; Mon, 29 Jun 2020 18:24:31 +0000 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 99E7D255D3; Mon, 29 Jun 2020 18:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593455054; bh=5BtOUyBPHv1XjW6A3W5IKba33SWQaJTlQxm8F41y4Eo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VLYj4VfuOWwNmP2KnxL0EGpvHQfQnzm/BM+pA2ZGNJI4SvMdRISbGEJPArlkAZoCc kOFcLI28FBYZkBd5w160C9Ku8SdgzNfGPcpZJA6GKKE+MmIdUF4N4toHcmdDKSnHdw RKTI8pD2QrHfeM4d9kJD1JPaCqupivRthaMAV0Lw= Date: Mon, 29 Jun 2020 11:24:14 -0700 From: Jaegeuk Kim To: Eric Biggers Message-ID: <20200629182414.GA1117827@google.com> References: <20200624012148.180050-1-jaegeuk@kernel.org> <20200629150323.GA3293033@google.com> <20200629160934.GA1752982@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200629160934.GA1752982@gmail.com> X-Headers-End: 1jpySB-006PKF-6O Subject: Re: [f2fs-dev] [PATCH v2] f2fs: avoid readahead race condition 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: kernel-team@android.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 06/29, Eric Biggers wrote: > On Mon, Jun 29, 2020 at 08:03:23AM -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 > > --- > > 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, 20 insertions(+), 1 deletion(-) > > > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > > index d6094b9f3916..9b69a159cc6c 100644 > > --- a/fs/f2fs/data.c > > +++ b/fs/f2fs/data.c > > @@ -2403,6 +2403,7 @@ int f2fs_mpage_readpages(struct address_space *mapping, > > #endif > > unsigned max_nr_pages = nr_pages; > > int ret = 0; > > + bool drop_ra = false; > > > > map.m_pblk = 0; > > map.m_lblk = 0; > > @@ -2413,13 +2414,25 @@ int f2fs_mpage_readpages(struct address_space *mapping, > > 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 (pages && is_readahead) { > > + page = list_last_entry(pages, struct page, lru); > > + if (F2FS_I(inode)->ra_offset == page_index(page)) > > + drop_ra = true; > > + else > > + F2FS_I(inode)->ra_offset = page_index(page); > > + } > > This is a data race because ra_offset can be read/written by different threads > concurrently. > > It either needs locking, or READ_ONCE() and WRITE_ONCE() if races are okay. I just wanted to keep zero overhead, since it doesn't matter either cases of skipping readahead or not. > > - Eric _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel