Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1200641ybl; Fri, 24 Jan 2020 17:55:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwDXV+OhYFYvtxbhfeDPdVoVFAcEml2KxYuJRRHb3j4mawbMJUP26Eh/tTKNyU5D2qXqQ6h X-Received: by 2002:aca:4183:: with SMTP id o125mr1173309oia.125.1579917300438; Fri, 24 Jan 2020 17:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579917300; cv=none; d=google.com; s=arc-20160816; b=PJAMfxo9VNhMx/kJwBmrljTYwxxHxyckN5IQR4WgcuyWoonI/IOsmOvwxmbTgQ4uH1 MQ8wIEzONVVwGw1NA9/GmaV+pQPpKmaaFighyNp8qwRGUHGgdK52xgQGQD2/nvpyJqPg oGCNEI42sidyiMMZLDZKrpqixpB143wsTh7HxYjUe8LSSQCfuEQs/lPmL+/pQ5bvpWs1 ktcKtA65b8a5u60NLf8XVNudKf13Ci5Ad0RU/znMP3jBkAXAMIJzD8CRZb8nB9U2bLLH YNyI0nDVO8pJNvs0eDyOHXRp/Xkk2pXSO13ox3xfZFM2u6cRwLMrPZlgeimTgNTvUkPr 3qYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OSF/YZenuXTg1qFTi8ZYIQJDfr1uhEPEs+4F4QHiI5E=; b=VVQ2CAbFIcJaxZG2Qw3zDajMPZ9PGb7IPitaQKoP8ePuh7qQ22PnuWfrMCFeGXAQrI 76ZrF9XK46PHB6HBGzzBXOVwLeVkxqAZjDpbqQEhKTPBEYx8DdneDX1sLSYfkw4DxQQs aUE/0CvXi1CitC64fliDqd/GP5DXZIDHIHBda6GLmpwnKyQkFdlduNiFJLZwpGXH3gbp U1jtzwTDzb/Sm4k4qem8lMhwtvS4It8gXFJsUUzgPRmy25l7SGjXelsiXysydJlV1SHx nbIiMmT+rk7f49q/0QW/fpM36bNJ1M6oJxaCKB941jIZScjQzptYJnk/tewWbiWB5ETD Oqrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=WrMXvB2l; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si2468387otf.32.2020.01.24.17.54.46; Fri, 24 Jan 2020 17:55:00 -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=@aol.com header.s=a2048 header.b=WrMXvB2l; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387634AbgAYBxj (ORCPT + 99 others); Fri, 24 Jan 2020 20:53:39 -0500 Received: from sonic316-55.consmr.mail.gq1.yahoo.com ([98.137.69.31]:35223 "EHLO sonic316-55.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387584AbgAYBxj (ORCPT ); Fri, 24 Jan 2020 20:53:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1579917218; bh=OSF/YZenuXTg1qFTi8ZYIQJDfr1uhEPEs+4F4QHiI5E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=WrMXvB2lMELCodxUGngV8nvB/aC3Qj0QuK9MforNrQhadL3kIPSsWEIB6gy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NbYHdQsx5EDrwanL9m1FsuAf9HR5rtB6ZRjlzmfVGQFnzUfwcKEkVD1Y8YOhjLgejxEcLw 0Nsn4ixBV8MFrKa7ca7WH5wQdhZuxOD3v9BnivN5BsQa5ToFeLae4uQYTIM4zvyF9myduUJyZCok CraPU7KpsxaazsEe7yGRvkr.ljTublOLnM.n.DyLexYEeQXKcYfTIbJR62TJRSQzacCDodTpKtwu Vgjtp3wa9vvRaHm5LNvqGkUMkscdh3MH8pO6WKt47cLkG8ftsJ7HAtlJANLdCVNcMUhdLL5tj6i3 XXY0NAHSxOZXTZvmbjPHGTM_71QoOexBXQ0rKWwxF7ahZcameQs7JERbifss6ZVmnfVj7wjTSY7q feSBdX4TD7SK_3NNJEfKKvllMG1dXIYTVMrKlQOlaGo.B7T467aMxrqZUfxP_kiEw.HLCGjFFS9B LXJD0tohnZroYTSPfo.D2LD3b5JItc_znVc895b49t65MHZHF.o_25bKNHz1ADr6tN4SCm1vPzVD ruHq84YD5QHjm8AP1Pu47pH3ELNwnXsqL91w.awNy7r8XKIF0tkQi2_h.a88el32VVZlnlDVE3x0 KR5EYZBMRzGcNaabuqaAyuWSR1_pjPEv4w5HSb.DYJ7SPFtb6aHZDjsWYK5sw4gHf22NytsyoaBO 64e4eHg_76BOYlABM.otWHAZM39kqrml1kGugqT_LxHsbkkI- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Sat, 25 Jan 2020 01:53:38 +0000 Received: by smtp416.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d56121dea07e775f13fa3ee1b8543b78; Sat, 25 Jan 2020 01:53:34 +0000 (UTC) Date: Sat, 25 Jan 2020 09:53:29 +0800 From: Gao Xiang To: Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 07/12] erofs: Convert uncompressed files from readpages to readahead Message-ID: <20200125015323.GA9918@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20200125013553.24899-1-willy@infradead.org> <20200125013553.24899-8-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200125013553.24899-8-willy@infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Mailer: WebService/1.1.14873 hermes Apache-HttpAsyncClient/4.1.4 (Java/1.8.0_181) Content-Length: 5007 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Matthew, On Fri, Jan 24, 2020 at 05:35:48PM -0800, Matthew Wilcox wrote: > From: "Matthew Wilcox (Oracle)" > > Use the new readahead operation in erofs. Fix what I believe to be > a refcounting bug in the error case. > > Signed-off-by: Matthew Wilcox (Oracle) > Cc: linux-erofs@lists.ozlabs.org > --- > fs/erofs/data.c | 34 ++++++++++++++-------------------- > fs/erofs/zdata.c | 2 +- > include/trace/events/erofs.h | 6 +++--- > 3 files changed, 18 insertions(+), 24 deletions(-) > > diff --git a/fs/erofs/data.c b/fs/erofs/data.c > index fc3a8d8064f8..335c1ab05312 100644 > --- a/fs/erofs/data.c > +++ b/fs/erofs/data.c > @@ -280,42 +280,36 @@ static int erofs_raw_access_readpage(struct file *file, struct page *page) > return 0; > } > > -static int erofs_raw_access_readpages(struct file *filp, > +static unsigned erofs_raw_access_readahead(struct file *file, > struct address_space *mapping, > - struct list_head *pages, > + pgoff_t start, > unsigned int nr_pages) > { > erofs_off_t last_block; > struct bio *bio = NULL; > - gfp_t gfp = readahead_gfp_mask(mapping); > - struct page *page = list_last_entry(pages, struct page, lru); > > - trace_erofs_readpages(mapping->host, page, nr_pages, true); > + trace_erofs_readpages(mapping->host, start, nr_pages, true); > > for (; nr_pages; --nr_pages) { > - page = list_entry(pages->prev, struct page, lru); > + struct page *page = readahead_page(mapping, start++); > > prefetchw(&page->flags); > - list_del(&page->lru); > > - if (!add_to_page_cache_lru(page, mapping, page->index, gfp)) { > - bio = erofs_read_raw_page(bio, mapping, page, > - &last_block, nr_pages, true); > + bio = erofs_read_raw_page(bio, mapping, page, &last_block, > + nr_pages, true); > > - /* all the page errors are ignored when readahead */ > - if (IS_ERR(bio)) { > - pr_err("%s, readahead error at page %lu of nid %llu\n", > - __func__, page->index, > - EROFS_I(mapping->host)->nid); > + /* all the page errors are ignored when readahead */ > + if (IS_ERR(bio)) { > + pr_err("%s, readahead error at page %lu of nid %llu\n", > + __func__, page->index, > + EROFS_I(mapping->host)->nid); > > - bio = NULL; > - } > + bio = NULL; > + put_page(page); Out of curiously, some little question... Why we need put_page(page) twice if erofs_read_raw_page returns with error... One put_page(page) is used as a temporary reference count for this request, we could put_page(page) in advance since pages are still locked before endio. Another put_page(page) is used for page cache xarray. I think in this case the page has been successfully inserted to the page cache anyway, after erroring out it will trigger .readpage again... so probably we need to keep this refcount count for page cache xarray? If I'm missing something, kindly correct me if I'm wrong.... Thanks, Gao Xiang > } > > - /* pages could still be locked */ > put_page(page); > } > - DBG_BUGON(!list_empty(pages)); > > /* the rare case (end in gaps) */ > if (bio) > @@ -358,7 +352,7 @@ static sector_t erofs_bmap(struct address_space *mapping, sector_t block) > /* for uncompressed (aligned) files and raw access for other files */ > const struct address_space_operations erofs_raw_access_aops = { > .readpage = erofs_raw_access_readpage, > - .readpages = erofs_raw_access_readpages, > + .readahead = erofs_raw_access_readahead, > .bmap = erofs_bmap, > }; > > diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c > index ca99425a4536..d3dd8cf1fc01 100644 > --- a/fs/erofs/zdata.c > +++ b/fs/erofs/zdata.c > @@ -1340,7 +1340,7 @@ static int z_erofs_readpages(struct file *filp, struct address_space *mapping, > struct page *head = NULL; > LIST_HEAD(pagepool); > > - trace_erofs_readpages(mapping->host, lru_to_page(pages), > + trace_erofs_readpages(mapping->host, lru_to_page(pages)->index, > nr_pages, false); > > f.headoffset = (erofs_off_t)lru_to_page(pages)->index << PAGE_SHIFT; > diff --git a/include/trace/events/erofs.h b/include/trace/events/erofs.h > index 27f5caa6299a..bf9806fd1306 100644 > --- a/include/trace/events/erofs.h > +++ b/include/trace/events/erofs.h > @@ -113,10 +113,10 @@ TRACE_EVENT(erofs_readpage, > > TRACE_EVENT(erofs_readpages, > > - TP_PROTO(struct inode *inode, struct page *page, unsigned int nrpage, > + TP_PROTO(struct inode *inode, pgoff_t start, unsigned int nrpage, > bool raw), > > - TP_ARGS(inode, page, nrpage, raw), > + TP_ARGS(inode, start, nrpage, raw), > > TP_STRUCT__entry( > __field(dev_t, dev ) > @@ -129,7 +129,7 @@ TRACE_EVENT(erofs_readpages, > TP_fast_assign( > __entry->dev = inode->i_sb->s_dev; > __entry->nid = EROFS_I(inode)->nid; > - __entry->start = page->index; > + __entry->start = start; > __entry->nrpage = nrpage; > __entry->raw = raw; > ), > -- > 2.24.1 >