From patchwork Fri Feb 3 13:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13127505 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 5108AC636D4 for ; Fri, 3 Feb 2023 13:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E29CC6B007D; Fri, 3 Feb 2023 08:14:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB2E46B007E; Fri, 3 Feb 2023 08:14:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2C656B0080; Fri, 3 Feb 2023 08:14:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B0A076B007D for ; Fri, 3 Feb 2023 08:14:55 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 74BD5A0740 for ; Fri, 3 Feb 2023 13:14:55 +0000 (UTC) X-FDA: 80426025750.26.E24A05B Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf10.hostedemail.com (Postfix) with ESMTP id 4A8FEC0015 for ; Fri, 3 Feb 2023 13:14:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=L4rDe16L; spf=pass (imf10.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675430093; 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=UTcTiYEDWZ/mD11MQF2nw4B+pzOsZZdmCp0kmgLs/rE=; b=EHLZmGhNvOdEd1XII60a3pY4unHIYmRr7fDACe9pCAyILjT8wxNk+JYgcPbg1FE8D6Aga3 YU6Ob1lhvS/7EsaxHlkuDy2GktXgJ+2LG5IJOaEhX4wZB6Uw5KJuzeGnf+FwwSU9nIqQzy fhWZKsiApRWvJYCndXons/+zmDfDV+s= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=L4rDe16L; spf=pass (imf10.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675430093; a=rsa-sha256; cv=none; b=O3TqnIEdlbOohXFlKD8Lw7DxAWY9tKjaiMSGgbYy7keBH7zMV4fm16+EJTRBxFO693ome1 96XOV24+9FRwdH2egJfph+n6j5Cjwl9+8yby+lk7uCgKmIfOcPFjygP0tGwfqu+uIzBTRh MxBajDkXCuce8wYg8oq5ovtrZh8fQsU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675430093; x=1706966093; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ej/z7Kbe67ZMdA6zpK1CWP2O1oj7nyZh2d/x7rAyAbA=; b=L4rDe16LHM4FqZDmMYCZ+T91Zok0/xRLV9btG/Fff8jQxlmP9g5J70dU ZIjRbReEQOflaQ4qA2OyZxueAXxGLAvbg88YwSXs2B/T+txyDfQO+PRzc 4Tx3OTk8+v30arnuD2B+x3KjNWoqEfpTRtWFRL6l8cuiElJj79Q2fYyvY MLyaAKmm++jFpYPoFRb7zn0klu/qCSrecF/eVyeTtLb0106KHLoKIcYBs 6nCv4BnQFenKStga80sIkR1FRdXO7ZSEfSFWOQculSNFOS5Tnjbmq28qw hvwtI/7FZNdCq9/mI48CY6GpZqnT1XUEwHCXGjKZsE0pZXO6j1l0XHI0Q w==; X-IronPort-AV: E=McAfee;i="6500,9779,10609"; a="326441899" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="326441899" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2023 05:14:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10609"; a="667641953" X-IronPort-AV: E=Sophos;i="5.97,270,1669104000"; d="scan'208";a="667641953" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga007.fm.intel.com with ESMTP; 03 Feb 2023 05:14:50 -0800 From: Yin Fengwei To: willy@infradead.org, david@redhat.com, linux-mm@kvack.org Cc: dave.hansen@intel.com, tim.c.chen@intel.com, ying.huang@intel.com, fengwei.yin@intel.com Subject: [RFC PATCH v3 4/4] filemap: batched update mm counter,rmap when map file folio Date: Fri, 3 Feb 2023 21:16:36 +0800 Message-Id: <20230203131636.1648662-5-fengwei.yin@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230203131636.1648662-1-fengwei.yin@intel.com> References: <20230203131636.1648662-1-fengwei.yin@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6zroo55aw1t9upynk69gzxcd1gtcckwx X-Rspamd-Queue-Id: 4A8FEC0015 X-HE-Tag: 1675430093-784812 X-HE-Meta: U2FsdGVkX1+MqKKm6NqpGGysEwLqmCPAP2zVX484Jhw/2nkab14ehECvtzTKThFK5nqcpLP6xxdjg7Jwtd8byBrE5i7AqFXagghbrS8+KXVvjbG63yUaonz5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, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use do_set_pte_range() in filemap_map_folio_range(). Which batched updates mm counter, rmap for large folio. 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. 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 --- mm/filemap.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 74046a3a0ff5..be75352050fe 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3364,11 +3364,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 mapped = 0; + pte_t *pte = vmf->pte; do { if (PageHWPoison(page)) - continue; + goto map; if (mmap_miss > 0) mmap_miss--; @@ -3378,20 +3379,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(pte[mapped])) + goto map; if (vmf->address == addr) ret = VM_FAULT_NOPAGE; - ref_count++; - do_set_pte(vmf, page, addr); - } while (vmf->pte++, page++, addr += PAGE_SIZE, ++count < nr_pages); + mapped++; + continue; - /* Restore the vmf->pte */ - vmf->pte -= nr_pages; +map: + if (mapped) { + do_set_pte_range(vmf, folio, addr, pte, start, mapped); + folio_ref_add(folio, mapped); + } + + /* advance 1 to jump the HWPoison or !pte_none entry */ + start += mapped + 1; + pte += mapped + 1; + addr += (mapped + 1) * PAGE_SIZE; + mapped = 0; + } while (page++, --nr_pages > 0); + + if (mapped) { + do_set_pte_range(vmf, folio, addr, pte, start, mapped); + folio_ref_add(folio, mapped); + } - folio_ref_add(folio, ref_count); WRITE_ONCE(file->f_ra.mmap_miss, mmap_miss); return ret;