From patchwork Tue Feb 28 21:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13155252 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 4F22CC7EE30 for ; Tue, 28 Feb 2023 21:38:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2E686B0099; Tue, 28 Feb 2023 16:37:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 98EA86B009A; Tue, 28 Feb 2023 16:37:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71DA46B009C; Tue, 28 Feb 2023 16:37:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5ACF36B0099 for ; Tue, 28 Feb 2023 16:37:56 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1707340B40 for ; Tue, 28 Feb 2023 21:37:56 +0000 (UTC) X-FDA: 80518013352.06.9CE4FC5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 5C6C3C0012 for ; Tue, 28 Feb 2023 21:37:54 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="LP/NyLEv"; dmarc=none; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677620274; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GeBhKEWLK25eomw3eGszIimIpcpbCe83zHF885nubCM=; b=cxLkBjmEP78smQH2QSACgiqKpMoPfGgytMMAvU1yxwKg2ZcaBFzFd987oAmaXWKze89BOz wrxRpffSMAZaeeOtGH85PtvGLHxbGuokNSW11hws+dxUaux7sL399eSDNSnAddA4t9NLgh k0iS/ezTz8Ox0rlj3N6koRJdH2y3M2k= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="LP/NyLEv"; dmarc=none; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677620274; a=rsa-sha256; cv=none; b=5RIAk1cKr8xPgbwScHwnrcOtwhJRfMq2H1aMifLo1JV266TfTv8QWV7CXzbQR8LTF3Fh6p jsK8mEXIsE5K5j78UAn3aBakjwRd5BMaq8DRsu4iIWaTLaV1zPMjctJyCLVkkHX74DqGNU dMYsmYYaY+vhgRTV+fcM0+5H2jl7YSo= 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=GeBhKEWLK25eomw3eGszIimIpcpbCe83zHF885nubCM=; b=LP/NyLEvU7Zr38BcJdWijZxpuz gziV4LpTw0wg2ceBinWysRsZZcycgBwZA2g7/Lm3HyxGiF1EEYEB3oZEMgrlbMW/lL2X2nrparQGy Zw04V6x8HNF5cPBAJOvScFx9DZMJVWxlE6+lIdHHDhw+d3ZT5d8h4XrEnqJGiVw0cPI4xltr7qIBy bUFvwy+/iUiECz7wXz+84dGuTi/q6iFsO4jyZD4oI7XQrBoeSvJnhDDqLdZ4xGHT8Bw5vZmVtkoVA C9BfuyTn+j+hO03JV95B0gmKzMTE65OMlLGGPxQnsIVjRDXfIlhs+T6oOBoljZ+Q77g/iY3WItu5S Pb6xt5sw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX7fL-0018rJ-PM; Tue, 28 Feb 2023 21:37:43 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: Yin Fengwei , linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v3 34/34] filemap: Batch PTE mappings Date: Tue, 28 Feb 2023 21:37:37 +0000 Message-Id: <20230228213738.272178-35-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230228213738.272178-1-willy@infradead.org> References: <20230228213738.272178-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5C6C3C0012 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: xrm9nkwaf5a7fdq1wbmfm7bqaxfzaa6b X-HE-Tag: 1677620274-778041 X-HE-Meta: U2FsdGVkX1/IfATThEpx/6sTz+5zocOLHnjA1OXcAkNyJutn/u3dwJCGM3fxMjV3pCSdDLPQ5L168dL/W1n4pRf0uyhFiLJCs71HPw0GCYZmnTpEn8ZUDBRZrvBF+TdH8+Wul3Zp+U0MEvLY3TdNXh5GncjikfF+vCTLrksGYx4AraN6+LFmc4pGInE5g53+Qv+HnpAs9x4tBMpOQgeJ2XjJzAhCMaC9RiJ3vBWiW6M0lM3JA0CVxDjIyrsYEqyp2hDdZLUA8Af8j6JmbX+EdLsQaQ9k+NizYZCKoCAb/CZsp7w3obl/1Dwxi+q4cIxLuzsyWkkrtPzEm4TSb2jSeduo9k1H9h4Zhgt7dO9IEIW3dNKTgn92tDc+sEcwSotkVbP8XW5/h0aFCIgGG6rLn0yNG5qqXZqgx80LLUj7ConLycxK84QM6+u+W/OeEq3TWZvAMGakfXd6jespE6CYMfT1ipimcoGW415sKsF7A/OzJXXLHqqSnkbElIEij7m3lm1gys5lws2joDg/jARa/JBOrOpD+5Cu8fsjeUsSh7/nGnAAh7viV10/erAgtr4wTNWn1RBxIhu2touUdBflc1BAujIR4oyhOEGfZFuQd2liQjPY8GLRQbVs141a4iSd6Y6RRgwtRoRpNeBF0YnMXNmZaWDskrVFbgFyLdBiKeihbYu2UyEr2PLtxa2EUZt0EL6C765eXnmf8JykwCdhgUqovSegLfRWzKhGVdhq0nzahofVWcW6MpVksITwS3p1PgCCBhJAKJsCyyUQFQjXd5nzmKGmvze3AxuywE2OYNHcHw7G49aX6nsItmDXVGDuwqr8dgXhWXCe7g1MOgbaP9Svca0BeWOMlLzrRFNxbxhTtZcdthpudhsdYoCyyaO9na479wKj+aDbiwKujL5PeJdaaCfXS34xGHMzqu6E14Acqap8/EubpZlUBbxoTbZD1B6oE7aRBNgfY6SpPGP OTlnJK5G bPTvpK2qwr1mx9aphPjb6kshZOdfBVHXOfXOFcB1GGztmwD7iu3mLGMolSbVYO186kdjR97y8ulKw4u8mcKI0yhhu31dP7uDseyT+P9IospcFK2xsiSjmrZvSFHcd/TO/2OlxomzYHHrTwx5cvWa+RZmHdUhPPLcC/+EAZBfGDCh4BL2nCQUBR1hYq5KvEZcyJ8RGKmvmdTYlcRHD/CZ1gN/P65NTsrvqMZvSOV8e7WgoDUhtQif54CI6UQ== 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: From: Yin Fengwei Call set_pte_range() once per contiguous range of the folio instead of once per page. This batches the updates to mm counters and the rmap. With a will-it-scale.page_fault3 like app (change file write fault testing to read fault testing. Trying to upstream it to will-it-scale at [1]) got 15% performance gain on a 48C/96T Cascade Lake test box with 96 processes running against xfs. Perf data collected before/after the change: 18.73%--page_add_file_rmap | --11.60%--__mod_lruvec_page_state | |--7.40%--__mod_memcg_lruvec_state | | | --5.58%--cgroup_rstat_updated | --2.53%--__mod_lruvec_state | --1.48%--__mod_node_page_state 9.93%--page_add_file_rmap_range | --2.67%--__mod_lruvec_page_state | |--1.95%--__mod_memcg_lruvec_state | | | --1.57%--cgroup_rstat_updated | --0.61%--__mod_lruvec_state | --0.54%--__mod_node_page_state The running time of __mode_lruvec_page_state() is reduced about 9%. [1]: https://github.com/antonblanchard/will-it-scale/pull/37 Signed-off-by: Yin Fengwei Signed-off-by: Matthew Wilcox (Oracle) --- mm/filemap.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 07ebd90967a3..40be33b5ee46 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3486,11 +3486,12 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, struct file *file = vma->vm_file; struct page *page = folio_page(folio, start); unsigned int mmap_miss = READ_ONCE(file->f_ra.mmap_miss); - unsigned int ref_count = 0, count = 0; + unsigned int count = 0; + pte_t *old_ptep = vmf->pte; do { - if (PageHWPoison(page)) - continue; + if (PageHWPoison(page + count)) + goto skip; if (mmap_miss > 0) mmap_miss--; @@ -3500,20 +3501,33 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, * handled in the specific fault path, and it'll prohibit the * fault-around logic. */ - if (!pte_none(*vmf->pte)) - continue; + if (!pte_none(vmf->pte[count])) + goto skip; if (vmf->address == addr) ret = VM_FAULT_NOPAGE; - ref_count++; - set_pte_range(vmf, folio, page, 1, addr); - } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages); + count++; + continue; +skip: + if (count) { + set_pte_range(vmf, folio, page, count, addr); + folio_ref_add(folio, count); + } - /* Restore the vmf->pte */ - vmf->pte -= nr_pages; + count++; + page += count; + vmf->pte += count; + addr += count * PAGE_SIZE; + count = 0; + } while (--nr_pages > 0); + + if (count) { + set_pte_range(vmf, folio, page, count, addr); + folio_ref_add(folio, count); + } - folio_ref_add(folio, ref_count); + vmf->pte = old_ptep; WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret;