Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2991621ybt; Mon, 29 Jun 2020 12:17:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/CXIs1dLWwQVldo6mTwKWgTDUCHdqSvwxbSqM/9Ghv8FCvOtxMMBFyCuiUPQu6JQylsXr X-Received: by 2002:a05:6402:3d0:: with SMTP id t16mr18420924edw.287.1593458267717; Mon, 29 Jun 2020 12:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593458267; cv=none; d=google.com; s=arc-20160816; b=GedE6w8hMZQlNEA7zVwaHlP8V3KYZXPT2/OQYQIhv5ZpA/RqRI1jOQthbf7ZmT2M7o diS9K3MNYEpr46Q/rqWz6iG/aP8vhiQk2YFBMXGmb4lZNkD+j6egldI6ZNMKZkwD8B7I y78sQlsKeJ7JCA+nc64xum1pXTM1TdU+Eajtb5dhTWfCFS+i9FFNBbjrJ/kgQ82RFEOc FkDYpUgcf8ARDsECEYIqvXyFD6KSkukpaRGVCPijaS/RL/csFn/SLwjsaLhNmGcKD3Xh SbY5wt/Ft0Yds4IKXK77quxKkdXByo7k/dIofPV6HmufEfbgQ2Fw30Z5mik0cgPtQB1G adGA== 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=+D7ws/5VATWhMiCm09S5qJn2I81GqL4bmwU7L7aQgNE=; b=KBnowpfaEE6Qbx7M7BIdvep1fZcGNFkD10n6SCNmVLOQFDkQ0FWhZ9rcz5YuoiNeN6 ZCIG9+6+kfG0vh+SPstRZ/lzFnVRzJPKeHRQcSwgnVeKjBQ5LviXuVhesYuu8UuCvZFI iuOywo6BxtOJhfm5+9uxwVjuAQ8cAud8vK87gXJ6lx75NN9Z+EYYyCmr55AcVYmA+aIK QP1sgqevXYyHp6UHN55itVHSIW1v/SubTbkft/8WZXJO+oUjx2uH5ZG3OWThXYWGS5EZ ynypajIO27t8h/qURkTcMyzytefXLZPa3qUE7p4ijzy9AE4PnrNxxBthX/zZzzK7XhI+ Vf1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oxrwItvu; 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 a9si278639ejx.271.2020.06.29.12.17.24; Mon, 29 Jun 2020 12:17:47 -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=oxrwItvu; 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 S1731054AbgF2TPX (ORCPT + 99 others); Mon, 29 Jun 2020 15:15:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730567AbgF2TPP (ORCPT ); Mon, 29 Jun 2020 15:15:15 -0400 Received: from gmail.com (unknown [104.132.1.76]) (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 5F64725584; Mon, 29 Jun 2020 16:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593446976; bh=W1dt6kfSnOHTFoS6K7XMXEcOthu54wUoE2DzEwzuUCc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oxrwItvubx0lq7oIN/a7Rq7cYTKxXqo5fqEXmzLXWogl6W9oG5klLLotwLjdgv5qS FznAmT3k1zilakXVbzMjT06uJ/5FUDaZP0tOZISIIzbPdUqTOv1cMt6ZcC9CmRUWM1 mdSdiiHj2iIeTTYSOT2dPyZiv32d6Hv2i0vDArdo= Date: Mon, 29 Jun 2020 09:09:34 -0700 From: Eric Biggers To: Jaegeuk Kim 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: <20200629160934.GA1752982@gmail.com> References: <20200624012148.180050-1-jaegeuk@kernel.org> <20200629150323.GA3293033@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200629150323.GA3293033@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. - Eric