From patchwork Wed Mar 15 05:14:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 69955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2145870wrd; Tue, 14 Mar 2023 22:19:36 -0700 (PDT) X-Google-Smtp-Source: AK7set9hr4o8HkrLd2Y+M/JwDIMa4RbBCJEKsyRLMs4ipjW87OZYPySRJuF6V843MV1QFuvwt8jD X-Received: by 2002:a17:90a:578b:b0:23b:3682:c899 with SMTP id g11-20020a17090a578b00b0023b3682c899mr12754102pji.23.1678857576292; Tue, 14 Mar 2023 22:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678857576; cv=none; d=google.com; s=arc-20160816; b=XWE3morNEbt7YXZ+5vnQ57xcd8zj2Wg+bpRqnrzPz+aeFG38OYxrH1qBAREFJ16EXz 0CJsSZHMRsIGKsG96YXRZ6/WIRjPjlbyWz/ru8KGjSBk/10U9T7wR5QC6b/ELK58qT1f WPb6F96gKPAxK9THmMwVk+2bf8l86kRL5AFDX+kmoqzavIohybkrteU/my2YulymDVA+ 0luJgv84W5u0KSupt+s8Jqkb0j4eFQ3VAgf+ttGc5itQ0TOjP3oBFc6VG5TMlvaRFw1Z hJoZKiP1PV1lmwGW5SjBzz5poXmwKrUNgN1mngZARqRNZ3skKqpnNHAYj4phUXYNwZWi MFpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZB/nojsqXTtfSMaj4C8ZgsYbK0b2FnBz3f1ii2GaXkQ=; b=ER2wF5fHUoq/eEAOWcgZ4Yra2wCIW27D6H9EgBmyZxrWvsOgQqMR3xy7mdb5w7Nd5l +0J/hEkGAcrx4WQGBg1XBL0pMB9/Y30TyXgw+c9rLpM0gMzJm26f3QBIQgdCCZ1+66c9 wO/26t/iFyVaTpAJnBXoz41xzIIw3YlR+jKNLkX25x2Sj+RuaEvuc6rxHKplsi7twlJ1 nAdxva4gQhY7Wioyls0o+yDzpcIBN5H040hyHICccRKxw1QHL3MLyHhEI5QuQed7XZzj Vqg7iXP2SFIAmZr8lHB/nHWrxVkj+17NKR1nMJvQL65FShCvBpD8pyv6pJF5hVZwQrge YNUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hY0UUqTG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a65410d000000b004e931d7643asi3953577pgp.707.2023.03.14.22.19.23; Tue, 14 Mar 2023 22:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hY0UUqTG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbjCOFQ7 (ORCPT + 99 others); Wed, 15 Mar 2023 01:16:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbjCOFPJ (ORCPT ); Wed, 15 Mar 2023 01:15:09 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D740301AB; Tue, 14 Mar 2023 22:14:55 -0700 (PDT) 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=ZB/nojsqXTtfSMaj4C8ZgsYbK0b2FnBz3f1ii2GaXkQ=; b=hY0UUqTGJDzLw4RBYtIYxgeVvN 63iW/9r3FQoz3cmvNkkqfiUK9D3PXsg4xMaIMPfprUGUdDWLfFX8lqQ3C82dUtIIJbUVjiPS7bkew 3SVH8K0ra3lSNQjOGGGVyPINBnyh+l1lpy9vvC+bXrgxroKRo6SBBqMHZ/6OCUELUKsVgdksovkJT OvXxNguIF8woiUKmuJj3JF3fXhM+G7vSEr0sxyhz6N12DAq6wpZJTX8hDZKK1dlve+VZatmATm7Qi Cujmwp3ehFlZS15JwLjFg7ZbiZQcI3M7wVp8XqdQrQfxLY2iEj5jOexlolxHUH/oEfQmY/I+3E1Oo YD831Jww==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pcJTO-00DYEB-U2; Wed, 15 Mar 2023 05:14:50 +0000 From: "Matthew Wilcox (Oracle)" To: linux-arch@vger.kernel.org Cc: Yin Fengwei , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: [PATCH v4 36/36] filemap: Batch PTE mappings Date: Wed, 15 Mar 2023 05:14:44 +0000 Message-Id: <20230315051444.3229621-37-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230315051444.3229621-1-willy@infradead.org> References: <20230315051444.3229621-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760409761621080470?= X-GMAIL-MSGID: =?utf-8?q?1760409761621080470?= 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 e2317623dcbf..7a1534460b55 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3483,11 +3483,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--; @@ -3497,20 +3498,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;