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=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 2FA26C433E3 for ; Wed, 19 Aug 2020 15:06:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA15420882 for ; Wed, 19 Aug 2020 15:06:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dUNOgQpc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA15420882 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 929888D0051; Wed, 19 Aug 2020 11:06:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D96B8D0013; Wed, 19 Aug 2020 11:06:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C8FE8D0051; Wed, 19 Aug 2020 11:06:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 63EBC8D0013 for ; Wed, 19 Aug 2020 11:06:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1D5203640 for ; Wed, 19 Aug 2020 15:06:44 +0000 (UTC) X-FDA: 77167645128.10.gate00_58180d027028 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id E606F16AA0E for ; Wed, 19 Aug 2020 15:06:26 +0000 (UTC) X-HE-Tag: gate00_58180d027028 X-Filterd-Recvd-Size: 4304 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 15:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=rGp99648ZL0r8woPVMUKJKf4XOJovtD4R7sQ3PkJTLE=; b=dUNOgQpcGDOwdV8W+iUjybIwz+ r+TCpbUCYbiD/bbVV6c1OmHeGRWxPtfu2txRjPQVQsykgWedkCX3/v3nBLonEAgBvgHc5ioaM6BUq cijdVuMd0vvhpGf3O41lbKHakZeRwKqC+ozro8VGm+DfwJqUjXalnWrHeBaG6doMOvoAHUiwUUQN0 /zzAu3yQ3do3r6oNcMel12m+sHtRdIYmiAqJE69Usrh3NdJvSFYhuQBo4IBQl/2p/57Dki2r/nIg9 SwYXcxtirP9t5Os0G/qp7a7zVQv76J5CffmARXi6O6aoghk/ibUNLObpyowQvAjZXA1WZvJW03atC sc7rTN6g==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8Pf4-0008Fe-H1; Wed, 19 Aug 2020 15:05:58 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Andrew Morton , Hugh Dickins , William Kucharski , Johannes Weiner , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH 2/7] mm: Rewrite shmem_seek_hole_data Date: Wed, 19 Aug 2020 16:05:50 +0100 Message-Id: <20200819150555.31669-3-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200819150555.31669-1-willy@infradead.org> References: <20200819150555.31669-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E606F16AA0E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 Content-Transfer-Encoding: quoted-printable 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: 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) } =20 /* - * 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. */ 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 =3D false; - int i; =20 - pagevec_init(&pvec); - pvec.nr =3D 1; /* start small: we may be there already */ - while (!done) { - pvec.nr =3D find_get_entries(mapping, index, - pvec.nr, pvec.pages, indices); - if (!pvec.nr) { - if (whence =3D=3D SEEK_DATA) - index =3D end; - break; + rcu_read_lock(); + if (whence =3D=3D SEEK_DATA) { + for (;;) { + page =3D xas_find(&xas, end); + if (xas_retry(&xas, page)) + continue; + if (!page || xa_is_value(page) || PageUptodate(page)) + break; } - for (i =3D 0; i < pvec.nr; i++, index++) { - if (index < indices[i]) { - if (whence =3D=3D SEEK_HOLE) { - done =3D true; - break; - } - index =3D indices[i]; - } - page =3D pvec.pages[i]; - if (page && !xa_is_value(page)) { - if (!PageUptodate(page)) - page =3D NULL; - } - if (index >=3D end || - (page && whence =3D=3D SEEK_DATA) || - (!page && whence =3D=3D SEEK_HOLE)) { - done =3D true; + } else /* SEEK_HOLE */ { + for (;;) { + page =3D xas_next(&xas); + if (xas_retry(&xas, page)) + continue; + if (!xa_is_value(page) && + (!page || !PageUptodate(page))) + break; + if (xas.xa_index >=3D end) break; - } } - pagevec_remove_exceptionals(&pvec); - pagevec_release(&pvec); - pvec.nr =3D PAGEVEC_SIZE; - cond_resched(); } - return index; + rcu_read_unlock(); + + return xas.xa_index; } =20 static loff_t shmem_file_llseek(struct file *file, loff_t offset, int wh= ence) --=20 2.28.0