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.6 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 C31C7C2D0A3 for ; Thu, 29 Oct 2020 19:34:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 393B8207DE for ; Thu, 29 Oct 2020 19:34:32 +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="GG08yJaq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 393B8207DE 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 703236B0073; Thu, 29 Oct 2020 15:34:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 639F96B0080; Thu, 29 Oct 2020 15:34:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 415516B0073; Thu, 29 Oct 2020 15:34:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 09F076B0073 for ; Thu, 29 Oct 2020 15:34:13 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AFB371EE6 for ; Thu, 29 Oct 2020 19:34:13 +0000 (UTC) X-FDA: 77425963986.24.meal66_301776927290 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 9502C1A4A5 for ; Thu, 29 Oct 2020 19:34:13 +0000 (UTC) X-HE-Tag: meal66_301776927290 X-Filterd-Recvd-Size: 4533 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 19:34:13 +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=2Bn5b1P1ATGl/MqPbstL/ShGH6FmIS/ZdMSjQOY1lJ4=; b=GG08yJaqKcj195RpDR4Pd6vfkR aKZdXWtCjSMaAt8/DxgYYwzJoEUHTh6Mo3BGXx587A3pM9VPifVfz70pzEuLyJ3tEyDpU8EsjvZns 1MQpV1Eb87bpv64/Pyl5Iz4nWnMm7gInAI5dNaGqWXF2CKJcbLKnIVuX1IN+9CpDy+H+cF63BpRAy KrBz5WxU75R48VKwmCaJG2wPop9AtlfB5mCVfxrsMWHliVanDoqRlkVnEfGO+L6V9NwNy3+2dNEAx L0yEknmsmX5I1kKvCvhIDSYp2ZyUiaEkC2ArZxVTUfE5FOURW8rhG/9G2eaIA2ScRm5kWCC9xoEDl QSvlDUxg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYDgX-0007c1-S2; Thu, 29 Oct 2020 19:34:09 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 09/19] mm/filemap: Allow THPs to be added to the page cache Date: Thu, 29 Oct 2020 19:33:55 +0000 Message-Id: <20201029193405.29125-10-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201029193405.29125-1-willy@infradead.org> References: <20201029193405.29125-1-willy@infradead.org> MIME-Version: 1.0 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: We return -EEXIST if there are any non-shadow entries in the page cache in the range covered by the THP. If there are multiple shadow entries in the range, we set *shadowp to one of them (currently the one at the highest index). If that turns out to be the wrong answer, we can implement something more complex. This is mostly modelled after the equivalent function in the shmem code. Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 64fe0018ee17..dabc26cf0067 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -811,23 +811,25 @@ noinline int __add_to_page_cache_locked(struct page= *page, { XA_STATE(xas, &mapping->i_pages, offset); int huge =3D PageHuge(page); - int error; + unsigned int nr =3D 1; =20 VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(PageSwapBacked(page), page); mapping_set_update(&xas, mapping); =20 - get_page(page); - page->mapping =3D mapping; - page->index =3D offset; - if (!huge) { - error =3D mem_cgroup_charge(page, current->mm, gfp); + int error =3D mem_cgroup_charge(page, current->mm, gfp); + if (error) - goto error; + return error; + xas_set_order(&xas, offset, thp_order(page)); + nr =3D thp_nr_pages(page); } =20 gfp &=3D GFP_RECLAIM_MASK; + page_ref_add(page, nr); + page->mapping =3D mapping; + page->index =3D xas.xa_index; =20 do { unsigned int order =3D xa_get_order(xas.xa, xas.xa_index); @@ -851,6 +853,8 @@ noinline int __add_to_page_cache_locked(struct page *= page, /* entry may have been split before we acquired lock */ order =3D xa_get_order(xas.xa, xas.xa_index); if (order > thp_order(page)) { + /* How to handle large swap entries? */ + BUG_ON(shmem_mapping(mapping)); xas_split(&xas, old, order); xas_reset(&xas); } @@ -860,27 +864,30 @@ noinline int __add_to_page_cache_locked(struct page= *page, if (xas_error(&xas)) goto unlock; =20 - mapping->nrpages++; + mapping->nrpages +=3D nr; =20 /* hugetlb pages do not participate in page cache accounting */ - if (!huge) - __inc_lruvec_page_state(page, NR_FILE_PAGES); + if (!huge) { + __mod_lruvec_page_state(page, NR_FILE_PAGES, nr); + if (nr > 1) + __mod_node_page_state(page_pgdat(page), + NR_FILE_THPS, nr); + } unlock: xas_unlock_irq(&xas); } while (xas_nomem(&xas, gfp)); =20 - if (xas_error(&xas)) { - error =3D xas_error(&xas); + if (xas_error(&xas)) goto error; - } =20 trace_mm_filemap_add_to_page_cache(page); return 0; error: page->mapping =3D NULL; /* Leave page->index set: truncation relies upon it */ - put_page(page); - return error; + page_ref_sub(page, nr); + VM_BUG_ON_PAGE(page_count(page) <=3D 0, page); + return xas_error(&xas); } ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO); =20 --=20 2.28.0