From patchwork Fri Apr 12 06:47:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13626909 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 A7E4BC4345F for ; Fri, 12 Apr 2024 06:20:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C6D56B0089; Fri, 12 Apr 2024 02:20:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE5646B0092; Fri, 12 Apr 2024 02:20:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB8536B008C; Fri, 12 Apr 2024 02:20:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 96DF96B0087 for ; Fri, 12 Apr 2024 02:20:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4D6E8160D4D for ; Fri, 12 Apr 2024 06:20:48 +0000 (UTC) X-FDA: 81999881376.30.E527D3E Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf13.hostedemail.com (Postfix) with ESMTP id A98A82000D for ; Fri, 12 Apr 2024 06:20:45 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712902846; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IVswTnD8aWwptx/keX4Qk7oKY4mTtAgGZnxRj4nn3Z8=; b=g9ukqzhDTd31/aIdJsV1J2PQqsU4KvzZKwUx2RxMt/CDwdMydMCYNp+qv5t8FXPfI1nbLt CsLfjDVp6DSjTDbEL/e0U2P/RIJuEkaf7cLS6DiA+ZvWCI58oSTLe7NRDF6AtPuB9lHtCe JY7cOmz30Laqq9ekrJKvKYlh0BgGTX4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712902846; a=rsa-sha256; cv=none; b=zob39mGMlkZdlSlAQAmXBQ6Rcq5s+zXgpOxf2X+FEXBTcWhuEQUc/I5l4HEDyxpcfjT5Fl 4lcdE6cpHNAKYKbsixOWHKHPtw0PPB6FklarNNr9tWTg42kdLm6hXhImDkSmluRq53KIDS BqmUtbVFlj9PGwz33eBgYy2n6OkA2AI= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4VG5wc6D5cz1ynKD; Fri, 12 Apr 2024 14:18:24 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 85E5B140554; Fri, 12 Apr 2024 14:20:42 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 12 Apr 2024 14:20:42 +0800 From: Kefeng Wang To: Andrew Morton CC: "Matthew Wilcox (Oracle)" , , , Kefeng Wang Subject: [PATCH v3 2/2] mm: filemap: batch mm counter updating in filemap_map_pages() Date: Fri, 12 Apr 2024 14:47:51 +0800 Message-ID: <20240412064751.119015-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240412064751.119015-1-wangkefeng.wang@huawei.com> References: <20240412064751.119015-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Stat-Signature: mrka4qr57q5s4f8puzmcyyrziaoxp5rs X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A98A82000D X-HE-Tag: 1712902845-958795 X-HE-Meta: U2FsdGVkX1/3gJeDaL+XjpSE+1OoKrQC/hXEJebYigUT3fbCuSGClMuE5bl4+F4eNN6V7utZNeS2/ICLsKgVqaojfCExrS0+2OeNELnIDV4jf7p2pvITa2jzby9VoYlvvrIvQjMRcQ0Uo6TXJU3SP/d6LIt/m77xAFKcsaiitDKNECOxR30T95A/HhffFf22C32Z/GZ9nWZ9pFEkbmczm0oG/c6zTXGHnrmzvFxkTnXwOj7BubJxhogLEyUbpDAMk0qnHuWMSXMEj+iD74xIcsGh6ODAr50yEPjLFZpKX1PxiwQe00zMsIftpRdPiLJVmeWBdl8mMX4P0ecXwlgSBk2BKPH8lVZw3ilVWD4rUpl+NkkR+dO+Ex4ynX7TCIUimMiw7dtBdpy28JqDuoTpS3R6m/BwgD2xCZlR56m9E1PhbvV6ruxyHsZcjK3c7ckEU2SIKSuw/hEE93RfB9HrltK8jk8pOzaxXZk4jupgGKyGgknW+PKiV4HbHoZNSBQYI4RxNrmoeHXf5MpHLmvrrkRKWMNoi3SIiNPxsMyGC4HoqpNDl6n2F4dUBc3cKfJYHAz/tw60nuo8ubkDMZk/Hb6v7wLBK51VsUixbs2EA3W28pTR3mXWA3NCgOgSX7H3QSyQDxLVqHRaebeszZxuG9GNuajgDyeqPvKx0rugRyuDU5201/pnd7SR9ALyAe8d2jJ4phhCdNG87VUmvPhdrpfUtoCRmLvM8j/uypiyVDkQOCRIFD/kXLFuDoZMlhp4j31ASzzJRlUBZGnX5ZStFvp+edx0fppGQYRZbwz02XOributdaEntxy7Sx4W8AxVdIcfl0NbyLkh+NZD7VLzSdUnyu7/L2mAkbZtADtFNmjBDc5TY15SC55Q2FNRxAw5yRanV3ox0hMXmUAg7blXdFtxsYElA2Fc3mEnPwwQajiNIH6KVCl1dFbwlMlvrLq4OWTh0u5ZknrunFEvW+q 4dWMnwXT +TVARIvrCWlsEdcMusel+mIRI1T/ML0QDbumt4kTP3YCYqSGIPGuA+TkZIozu4owXPmZv44yKLeER7Iu+OrszIw/Saanv10mrtO8IhJ1YR1zUewvo2AUXbiCYCnYv21siFxf8benC0Euhxh1gSq1UbsDx9gj0v+Bdue4/v90Y9MrjdnSONh8w2QuUNoqu4jJuwR/9 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: List-Subscribe: List-Unsubscribe: Like copy_pte_range()/zap_pte_range(), make mm counter batch updating in filemap_map_pages(), since folios type are same(MM_SHMEMPAGES or MM_FILEPAGES) in filemap_map_pages(), only check the first folio type is enough, the 'lat_pagefault -P 1 file' test from lmbench shows 12% improvement, and the percpu_counter_add_batch() is gone from perf flame graph. Signed-off-by: Kefeng Wang --- mm/filemap.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 04b813f0146c..531af4acc667 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3506,7 +3506,7 @@ static struct folio *next_uptodate_folio(struct xa_state *xas, static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, struct folio *folio, unsigned long start, unsigned long addr, unsigned int nr_pages, - unsigned int *mmap_miss) + unsigned long *rss, unsigned int *mmap_miss) { vm_fault_t ret = 0; struct page *page = folio_page(folio, start); @@ -3540,8 +3540,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, skip: if (count) { set_pte_range(vmf, folio, page, count, addr); - add_mm_counter(vmf->vma->vm_mm, mm_counter_file(folio), - count); + *rss += count; folio_ref_add(folio, count); if (in_range(vmf->address, addr, count * PAGE_SIZE)) ret = VM_FAULT_NOPAGE; @@ -3556,7 +3555,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, if (count) { set_pte_range(vmf, folio, page, count, addr); - add_mm_counter(vmf->vma->vm_mm, mm_counter_file(folio), count); + *rss += count; folio_ref_add(folio, count); if (in_range(vmf->address, addr, count * PAGE_SIZE)) ret = VM_FAULT_NOPAGE; @@ -3569,7 +3568,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf, struct folio *folio, unsigned long addr, - unsigned int *mmap_miss) + unsigned long *rss, unsigned int *mmap_miss) { vm_fault_t ret = 0; struct page *page = &folio->page; @@ -3593,7 +3592,7 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf, ret = VM_FAULT_NOPAGE; set_pte_range(vmf, folio, page, 1, addr); - add_mm_counter(vmf->vma->vm_mm, mm_counter_file(folio), 1); + (*rss)++; folio_ref_inc(folio); return ret; @@ -3610,7 +3609,8 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, XA_STATE(xas, &mapping->i_pages, start_pgoff); struct folio *folio; vm_fault_t ret = 0; - unsigned int nr_pages = 0, mmap_miss = 0, mmap_miss_saved; + unsigned long rss = 0; + unsigned int nr_pages = 0, mmap_miss = 0, mmap_miss_saved, folio_type; rcu_read_lock(); folio = next_uptodate_folio(&xas, mapping, end_pgoff); @@ -3629,6 +3629,8 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, folio_put(folio); goto out; } + + folio_type = mm_counter_file(folio); do { unsigned long end; @@ -3640,15 +3642,16 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, if (!folio_test_large(folio)) ret |= filemap_map_order0_folio(vmf, - folio, addr, &mmap_miss); + folio, addr, &rss, &mmap_miss); else ret |= filemap_map_folio_range(vmf, folio, xas.xa_index - folio->index, addr, - nr_pages, &mmap_miss); + nr_pages, &rss, &mmap_miss); folio_unlock(folio); folio_put(folio); } while ((folio = next_uptodate_folio(&xas, mapping, end_pgoff)) != NULL); + add_mm_counter(vma->vm_mm, folio_type, rss); pte_unmap_unlock(vmf->pte, vmf->ptl); out: rcu_read_unlock();