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=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 C904BC433DF for ; Thu, 20 Aug 2020 16:45:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F5B5207DE for ; Thu, 20 Aug 2020 16:45:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="YI1lMpQ4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F5B5207DE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 190968D001E; Thu, 20 Aug 2020 12:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 141DD8D0002; Thu, 20 Aug 2020 12:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 057E68D001E; Thu, 20 Aug 2020 12:45:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id E2D678D0002 for ; Thu, 20 Aug 2020 12:45:53 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 95653181AEF07 for ; Thu, 20 Aug 2020 16:45:53 +0000 (UTC) X-FDA: 77171523786.26.fight40_200577227032 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 542251804B65A for ; Thu, 20 Aug 2020 16:45:53 +0000 (UTC) X-HE-Tag: fight40_200577227032 X-Filterd-Recvd-Size: 4501 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Aug 2020 16:45:52 +0000 (UTC) Received: from kernel.org (unknown [87.70.91.42]) (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 0C8772072D; Thu, 20 Aug 2020 16:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597941952; bh=1N4N7lW5MVeLs+DqxzXoSXZiWCLJTm8mjKFiKJLpIcI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YI1lMpQ4VlBBR7pv5QltUyex6A4bRfzFzEpfHU+BoCNdlVbw1FrRqUoIFWm3K3AmE FY/VxPwbBqLbp0Xf8kJ+AsgEqs2HjLtpGdq5ycv4mNAox16v3jUFjumWQ1TzGQQsey 8wENiwNf7L49yqW0jN24Ri+ezJhG/nUAMRAeawso= Date: Thu, 20 Aug 2020 19:45:46 +0300 From: Mike Rapoport To: "Matthew Wilcox (Oracle)" Cc: linux-mm@kvack.org, Andrew Morton , Hugh Dickins , William Kucharski , Johannes Weiner , Jan Kara , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] mm: Rewrite shmem_seek_hole_data Message-ID: <20200820164546.GD752365@kernel.org> References: <20200819150555.31669-1-willy@infradead.org> <20200819150555.31669-3-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200819150555.31669-3-willy@infradead.org> X-Rspamd-Queue-Id: 542251804B65A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 19, 2020 at 04:05:50PM +0100, Matthew Wilcox (Oracle) wrote: > use the XArray directly instead of using the pagevec abstraction. > The code is simpler and more efficient. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > mm/shmem.c | 61 +++++++++++++++++++++--------------------------------- > 1 file changed, 24 insertions(+), 37 deletions(-) > > diff --git a/mm/shmem.c b/mm/shmem.c > index a7bbc4ed9677..0f9f149f4b5e 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -2659,53 +2659,40 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) > } > > /* > - * llseek SEEK_DATA or SEEK_HOLE through the page cache. > + * llseek SEEK_DATA or SEEK_HOLE through the page cache. We don't need > + * to get a reference on the page because this interface is racy anyway. > + * The page we find will have had the state at some point. For my non-native ear "will have had" is too complex ;-) > */ > static pgoff_t shmem_seek_hole_data(struct address_space *mapping, > pgoff_t index, pgoff_t end, int whence) > { > + XA_STATE(xas, &mapping->i_pages, index); > struct page *page; > - struct pagevec pvec; > - pgoff_t indices[PAGEVEC_SIZE]; > - bool done = false; > - int i; > > - pagevec_init(&pvec); > - pvec.nr = 1; /* start small: we may be there already */ > - while (!done) { > - pvec.nr = find_get_entries(mapping, index, > - pvec.nr, pvec.pages, indices); > - if (!pvec.nr) { > - if (whence == SEEK_DATA) > - index = end; > - break; > + rcu_read_lock(); > + if (whence == SEEK_DATA) { > + for (;;) { > + page = xas_find(&xas, end); > + if (xas_retry(&xas, page)) > + continue; > + if (!page || xa_is_value(page) || PageUptodate(page)) > + break; > } > - for (i = 0; i < pvec.nr; i++, index++) { > - if (index < indices[i]) { > - if (whence == SEEK_HOLE) { > - done = true; > - break; > - } > - index = indices[i]; > - } > - page = pvec.pages[i]; > - if (page && !xa_is_value(page)) { > - if (!PageUptodate(page)) > - page = NULL; > - } > - if (index >= end || > - (page && whence == SEEK_DATA) || > - (!page && whence == SEEK_HOLE)) { > - done = true; > + } else /* SEEK_HOLE */ { > + for (;;) { > + page = xas_next(&xas); > + if (xas_retry(&xas, page)) > + continue; > + if (!xa_is_value(page) && > + (!page || !PageUptodate(page))) > + break; > + if (xas.xa_index >= end) > break; > - } > } > - pagevec_remove_exceptionals(&pvec); > - pagevec_release(&pvec); > - pvec.nr = PAGEVEC_SIZE; > - cond_resched(); > } > - return index; > + rcu_read_unlock(); > + > + return xas.xa_index; > } > > static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence) > -- > 2.28.0 > > -- Sincerely yours, Mike.