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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D774C433EF for ; Fri, 4 Feb 2022 20:22:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC4158D0010; Fri, 4 Feb 2022 15:21:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4C7D8D0007; Fri, 4 Feb 2022 15:21:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9FAB8D0010; Fri, 4 Feb 2022 15:21:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 9D68A8D0007 for ; Fri, 4 Feb 2022 15:21:42 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6037D86E62 for ; Fri, 4 Feb 2022 20:21:42 +0000 (UTC) X-FDA: 79106218044.26.73D0B54 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id DE79A20003 for ; Fri, 4 Feb 2022 20:21:41 +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=L37MxzcVyvY09GTWOfKpnrpDRYDGlN5/2cipacEt3mI=; b=ZhFNNZhgMvwA2TG2/a6FGpBoc9 AqK7iDGsWQzCBRJn+TEe0o+W86DMYD9LcFyzHjiowHJ8Tu6VXhtQjRLYHOE2KpmXIo8V/RRqsLTrF WbG52N+2uWo532xUuSdlpYwuEK0pg3X/daE+obSOZZlg9P6iKyZOYpBevBtumYw9wIu/ubBuHFGzs utudAFbWmLtrVZ3/ztqbAAA3oXWGGg377/i7eNlbgylA3AWNWj+KMTWnNMaQqLCH1et5AkgFy1ePM 1H4DVtT9Dn1TGeU/lLU510OFH5mEPPWfQInO8YndDKoPnP2aDo0LNMfdeFONzgQ+ceUEzlLdXc4q3 MZRnsSWQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG4jb-007Lqq-EK; Fri, 04 Feb 2022 19:59:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH 67/75] mm/filemap: Allow large folios to be added to the page cache Date: Fri, 4 Feb 2022 19:58:44 +0000 Message-Id: <20220204195852.1751729-68-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220204195852.1751729-1-willy@infradead.org> References: <20220204195852.1751729-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DE79A20003 X-Stat-Signature: fwdin1pzofd9scqsz49w9y31qigdb3bc Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZhFNNZhg; dmarc=none; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1644006101-618402 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 folio. 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 | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index ad8c39d90bf9..8f7ac3de9098 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -842,26 +842,27 @@ noinline int __filemap_add_folio(struct address_spa= ce *mapping, { XA_STATE(xas, &mapping->i_pages, index); int huge =3D folio_test_hugetlb(folio); - int error; bool charged =3D false; + long nr =3D 1; =20 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); mapping_set_update(&xas, mapping); =20 - folio_get(folio); - folio->mapping =3D mapping; - folio->index =3D index; - if (!huge) { - error =3D mem_cgroup_charge(folio, NULL, gfp); + int error =3D mem_cgroup_charge(folio, NULL, gfp); VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio); if (error) - goto error; + return error; charged =3D true; + xas_set_order(&xas, index, folio_order(folio)); + nr =3D folio_nr_pages(folio); } =20 gfp &=3D GFP_RECLAIM_MASK; + folio_ref_add(folio, nr); + folio->mapping =3D mapping; + folio->index =3D xas.xa_index; =20 do { unsigned int order =3D xa_get_order(xas.xa, xas.xa_index); @@ -885,6 +886,8 @@ noinline int __filemap_add_folio(struct address_space= *mapping, /* entry may have been split before we acquired lock */ order =3D xa_get_order(xas.xa, xas.xa_index); if (order > folio_order(folio)) { + /* How to handle large swap entries? */ + BUG_ON(shmem_mapping(mapping)); xas_split(&xas, old, order); xas_reset(&xas); } @@ -894,29 +897,31 @@ noinline int __filemap_add_folio(struct address_spa= ce *mapping, 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) - __lruvec_stat_add_folio(folio, NR_FILE_PAGES); + if (!huge) { + __lruvec_stat_mod_folio(folio, NR_FILE_PAGES, nr); + if (folio_test_pmd_mappable(folio)) + __lruvec_stat_mod_folio(folio, + 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 (charged) - mem_cgroup_uncharge(folio); + if (xas_error(&xas)) goto error; - } =20 trace_mm_filemap_add_to_page_cache(folio); return 0; error: + if (charged) + mem_cgroup_uncharge(folio); folio->mapping =3D NULL; /* Leave page->index set: truncation relies upon it */ - folio_put(folio); - return error; + folio_put_refs(folio, nr); + return xas_error(&xas); } ALLOW_ERROR_INJECTION(__filemap_add_folio, ERRNO); =20 --=20 2.34.1