Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3076558ybt; Mon, 29 Jun 2020 14:42:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrNP68CQyCALe6UzLv5tNeSiYDFahuOtYR7dS55t7/XhBjT7KCkODNwya7qBO4cTcMNRgy X-Received: by 2002:a17:906:492:: with SMTP id f18mr15576687eja.279.1593466954013; Mon, 29 Jun 2020 14:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593466954; cv=none; d=google.com; s=arc-20160816; b=tNJy9JTPbhanBwHUi7cFZH+i+zqAaiVEvuKvhaf/tVFRWe+kRoAOXzgCaB6I04kcCF NaQdMYwzgRYdhvEB7lV2tbSuLzXoZu+XFZfDeLGGpPUzPNts6CHX7icF8CdoWiWzTsU0 Q+GMUkIXeiXk8goVs/D+eEqybnAia2Ad+aaZtdcUDzbD7bmoKatRqwpbE6NT1NwM8106 wc5oT/67hvPqjh2aXWoi8SVSPTA47h/W0ZfEfBzZFJd/yA5JUXdzNGdLCs1cxuDVBol7 mfENI1fgalwvErYnEz6z0pFd27c3b8o+SDoKPHCNQ/KK/AmU/5Heh1Td80N7qJOMPnDs OflQ== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=EcZm6LEuE9ZlsSoO9HFDjOlCJ1W6WJ65go2sMD0RQnE=; b=cL3LBh9nrBQRP+eZR8Spy2Le4dn6s3B6+rlTs0v5QIChHOh/2rhBFubZvfHLe71vEe GNTqlPVk8CGuYd49QEhbArvH5Q5V6ZuavekpD8ga+7uWY3V6ySce322Hxyq2kzHQTMc/ XEKgyUSfyGiU4op0S34T8MPp+i+U4l5tntdZ9FWVk/Y1AxHkuPLJLyT68eaDQlS9f7HY Xc4se5DA6267wgrh5kPV6ZvnRc0eoXDLXGZ86+3K/zlXmoycqT3eEGzJd3V6Y5+Vl+Ro 9qpoGAEB2+iKNe47F8WDUDqpnHFJq3X5On+kxo9RhPjOOIE8He6p4O0VTHSaOBjLo7gX wKSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VLYj4Vfu; 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 17si545570ejw.686.2020.06.29.14.42.11; Mon, 29 Jun 2020 14:42:34 -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=VLYj4Vfu; 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 S2403886AbgF2VlV (ORCPT + 99 others); Mon, 29 Jun 2020 17:41:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:60656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbgF2SkU (ORCPT ); Mon, 29 Jun 2020 14:40:20 -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 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 Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Subject: Re: [f2fs-dev] [PATCH v2] f2fs: avoid readahead race condition 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200629160934.GA1752982@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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