From patchwork Mon Jul 10 20:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307626 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 8A025EB64DC for ; Mon, 10 Jul 2023 20:44:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EA558E001C; Mon, 10 Jul 2023 16:43:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 274828E001B; Mon, 10 Jul 2023 16:43:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02EB88E001D; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E03A48E001C for ; Mon, 10 Jul 2023 16:43:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B94B4025F for ; Mon, 10 Jul 2023 20:43:53 +0000 (UTC) X-FDA: 80996878746.01.72C2607 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 9E02C140010 for ; Mon, 10 Jul 2023 20:43:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=c4AwRiQV; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021832; 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=3MITzrjsscz3EOfHnUvCpgkBiqSORw5f6CrRiwc69RA=; b=wastEwV8y54oq3eMmbRwnMA448I+P/PDPXQCN5gA0zpS/u7RddRfdpSCRlu7H8km4c5k1w wfPxx5zTd6SPhegPyISZw6cnkna6Wo8M6TreZ3PahMFUe9vvnTbsr7rv3LG1SmEIGPE/kP ufFsfHVcVsH2JcVLA8sSm7iOA7MVg1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021832; a=rsa-sha256; cv=none; b=Fkcy7o0xO5RhbilR8DSCvapp9WzfnvvMLGwdTBOsFm4wwdVGjjjO3cK5VXysh5pK0YYGUo OFQWkhLHOYydinpgAFhXuHpQEgGqz2s06G6+ogMJHmWVP/SxycyYMxooONxX89dxmOW5Ou pvoPWmnyArEmgnncmM9RMjfzS8HCFgs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=c4AwRiQV; spf=none (imf26.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=3MITzrjsscz3EOfHnUvCpgkBiqSORw5f6CrRiwc69RA=; b=c4AwRiQVrDhrNfG53FzdnE3K+f r0ZI918ORvWE+/rlklI90tC0rTzLt/bZqIrIPosed6W8sSGZxn5juLhXXar5zemsZK9Vcqxkkq584 hDoHHqbFMo7S/5Kft9b2sm/K+b4TNB+bz5U1evgEm9J9ZpskVhypF9jwxVDDkfidplEasdsIZjYqO hH7enTDz4wEm9cPzJr4rkEdVKpTkoNXBC4520HuxwPXnYULE3dtoqo3/DlkNRUpSSrtJge5TyrO3P 66GSziBTrEilNJlA1FCPqBoUjxKyXL04BGstWBXnLIjizU1uhiKJbsmRFrSuJbkOfbXM/ZC6jW7yK Q5ywJ05w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjV-00Eurk-IK; Mon, 10 Jul 2023 20:43:45 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: Yin Fengwei , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v5 37/38] filemap: Batch PTE mappings Date: Mon, 10 Jul 2023 21:43:38 +0100 Message-Id: <20230710204339.3554919-38-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230710204339.3554919-1-willy@infradead.org> References: <20230710204339.3554919-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9E02C140010 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: jeub9ej8sg9x1i54omz1xsqppio6tnxc X-HE-Tag: 1689021831-305164 X-HE-Meta: U2FsdGVkX19BVSexMAC+y3KyKX6amU/EANk08RudFeYdieqET/NA6IjarZOm+IbyVFTwh1LO81jUk7NmiHh9vKRtCyoG12bpgIghrK9yY+lRvD4p6WwnJcTtr1If6kTx43THoF5rWHPoSOeNzivpoYJ7+HzwNgY1H6pHtaA5mSXfOiauLFm5cgpe/fhkbxpvJaIcHDOeVCkF+0L/+44k5CLJZ6Fv67b+oYICd41MqrDtd0cX2lZNSpGREIJbu9DlNI6RMl1hWeXFqkFY7CdOcJLbAhEIX4juvqQsUbVdgNjic3v8oPKbYl3G0CA+SiFy+iz5IcoQ0ZIjIn0yZ4LEBl6RMz18snkEl8ZmSwvVpO3FjO8n5WhE4/opk7/sKH0YDd3n+XpPSqx9CteM8zlbxlpXbvrUrRYpAVAR2QZFqoEADy5yeqt9DslcvDwX3Su9DrV0dT1wcD/JAbUW1mDRF9oIGNPfdzB087jBwBYjHznD2JZ7sD13dsiSGdx8R6s9RsJMXGQFpeXFarOr1pwGBFsixsPOW2z28RajxHOnZsEgTnDirD0dg+VfHWCQ3vcaOoiI8aeOUPTBe6HFj8zoGnbTGribi4GxpiBpWtWQn8G3xjZErBWlhzAna/pCsEdQsP3WS/qxyrfU/C+d38F2Uvufu+y6Vtode+HrdiCrVKdLZ5MhFISAyX4cshQIIKJqbdKI/HeyfWVyAAj7/TJhw22TM+iKPeqxZrlzArxIwfkYMYWTFA0krmy4KCSs8q3cln6/LJaj+UVQok+W8Uzzu7rq2xMOTfjK5d4IYJ7a8ZD8aeKxRBY361K2f6ADECxgNzben8f7FSCygq2QgaLSZDpAlh0cP+QyG5xs8dk+bsTiwptTiDqMiO8CtMhSeqHPPjnr1oE9V9eGm0ymix7Zc6b+Xxwj6vyQVQIGpgYCSlwvB3vHmBP7WNzpXGb5dVxcO2IzHdDCBv1YJ96Y/cS U2TSfM/5 rl1gSVLumfghAjA1GR2iEGWp+dWw0nzt5AH9WL9Lf36KDjw+CNNpVoNTwKBHKMUJYU/XsyqOFFKmhIVGMhuXySXhGAUg76GpH0Yx9llDcV72B5Y/r64rgwO3ATTvN6MKFi4xlowQ2UjeoEerlp4CfWhgisfG84nOuqfxKRfyDgsLBl7hR5U0d7QSRQYZ1/DVDQQ3+n0OTaW5/9GYU/2uluNurW4QIdfK3ilTA 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 | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index c06e9d331416..014b73eb96a1 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3480,11 +3480,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--; @@ -3494,20 +3495,34 @@ 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 (vmf->address == addr) - ret = VM_FAULT_NOPAGE; + if (!pte_none(vmf->pte[count])) + goto skip; - 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); + if (in_range(vmf->address, addr, count)) + ret = VM_FAULT_NOPAGE; + } - /* 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); + if (in_range(vmf->address, addr, count)) + ret = VM_FAULT_NOPAGE; + } - folio_ref_add(folio, ref_count); + vmf->pte = old_ptep; WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret;