From patchwork Mon Apr 29 07:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13646408 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 17017C4345F for ; Mon, 29 Apr 2024 07:24:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 594F26B0085; Mon, 29 Apr 2024 03:24:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 513096B0087; Mon, 29 Apr 2024 03:24:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 364516B0089; Mon, 29 Apr 2024 03:24:36 -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 194566B0085 for ; Mon, 29 Apr 2024 03:24:36 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6EFE8140D46 for ; Mon, 29 Apr 2024 07:24:35 +0000 (UTC) X-FDA: 82061731710.17.3C9469D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id E43AE8000B for ; Mon, 29 Apr 2024 07:24:32 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714375473; 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=eMrGXSIKBSiih200eyCVfCV6cTNkIK6OZo1ibcy6MLc=; b=vbOp4avKa1p1Vua3im8n9iHv6X1OK4dEXUYHhuHPllFc/OY5jSQ14CyA9hTna7YRyxwOug aFwXuz3jaa1H9QL8dxG3WoaE5E95MSnED+NUNrebdYj3bbyjxIIixB8om4bmpZywCV9i/o Pbktn5UmmTMxI9yo5tAZcnFRaZ/V7N4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714375473; a=rsa-sha256; cv=none; b=ltp4jZ28CY/70EvntV81vw7q0yp4CzNOKLpe8iWtmeWQ1ft6VBHh3GtfUwgkRRBEFaB1C7 ViCL30ucPWZNNdMh/pROIsaYh6ieRyWHc1vdJdlEeeg+dGfE24NlAyZiXTk2lxi/GUpLkE Aq8O8a6rWJkRbDloju1nR5OalUYzW+U= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VSZWP0vXzzvQsT; Mon, 29 Apr 2024 15:21:21 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 316A7140444; Mon, 29 Apr 2024 15:24:29 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) 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; Mon, 29 Apr 2024 15:24:28 +0800 From: Kefeng Wang To: Andrew Morton CC: "Matthew Wilcox (Oracle)" , , , Kefeng Wang Subject: [PATCH rfc 2/4] mm: filemap: add filemap_set_pte_range() Date: Mon, 29 Apr 2024 15:24:15 +0800 Message-ID: <20240429072417.2146732-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240429072417.2146732-1-wangkefeng.wang@huawei.com> References: <20240429072417.2146732-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Rspamd-Queue-Id: E43AE8000B X-Rspamd-Server: rspam06 X-Stat-Signature: u1mruquitcu7np1hgepe7pneiwwkjrsz X-HE-Tag: 1714375472-279454 X-HE-Meta: U2FsdGVkX1/u2MX4cfWwY6tNeN2ho7XAhGtlzbSEMG5wgHseKQLic9VzVMpTP5wm9B5TmRMQRe1ZUFRUBXzHW4RzJ6TvoOzsr8FEhNy2UE9A/Oq55CtCX/d+YDUJRKZEymuZx0v06ZP/srNUZMv7X+UCXe04X7oJvm8MB+mDHTqUYY5OrCbANXphbLSouhTJnHiE7cXWwWToslahFIkC057eUxBRZHs0hGO0GgtERmXY6C5DhGZ7Mg26rOpagod0E9sFEz9OtQHhnZbvkoFIgNUkrB6KyhQ2+ziaW8rEXv8xrxEe3OG28epb0inAAqxZGrjXVs94kqpnixcsNeKTrJTlMn2zkRiLKLOCPm1nIFOwIow0uae4QrgwRuRaRiCPnXENPlqbc7fLT7ngJXHMlqTRnYHcfha+s/NYzzSvGZq5m8ELNQYCtHclzen8LCjziw74pcb4mkgRzczkCV5xzxqlHMvli8rL1l/kj37wQgU7enhP0Gob65dWCJm4JWqxyTOm6cTbeO4UuUhQT5BKkWpTaNCGpiLGvM0LIC5jNu+lznkNAnSn8fVOwCdRk6A5gMuWi5E56PCZeA/lAhlkqwgwxlIA9lt3rRWyQnM89XTFmGj7aKNloBAzUuyNGWemJiswbDSUZWEuE9+rwFicCWDnn13Q5TQbkASD1s2UTnP3qqu00W9iDo+BZQqxoK6UFjSbx+gXz74bzGKpngRD8i3w2m8IAjqMitONuwLFm/aSPPaDqjy72SLxD5UzrmsnF0TinHoRE85UcSjv9/htnCETYhGWO9darEOSNFpzfK8bKLvbh3r4u0zpwvtGJ426feV9qXWXIC3lRC0KVFogoonmTB1HjRW9w579iX1oTgVPJQKuNmXefMH7KMxbsM/TSX4EMSEIkW9Rwb6NGvxGz1xfRdBats8wBUlyiU3/t4I4wHEpLQLH+c0VF1BoHIoAelvL0nWsc/eOc48pLsf 94MjDz/K yZFUYPvVmTp8AN7kN6zda5dygLHrT8ZELOq6cOW6X9EKF9pkkjKqsw7p1R7BpFJoERMzSYqWiwNwdDYhA9X8eCFuNrcpV2Gbj55dxc6VCFprpa8yYMKLzAyoz8axOLwdaXWBW6c1fNE4MdgilfWSz5CzT5781onFyssorpI6WFebp2PlZ++N0KQ0XzZjnVvTz6O2a 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: Adding filemap_set_pte_range() independent of set_pte_range() to unify the rss and folio reference update for small folio and large folio, which also is prepare for the upcoming lruvec stat batch updating. Signed-off-by: Kefeng Wang --- mm/filemap.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index ec273b00ce5f..7019692daddd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3499,6 +3499,25 @@ static struct folio *next_uptodate_folio(struct xa_state *xas, return NULL; } +static void filemap_set_pte_range(struct vm_fault *vmf, struct folio *folio, + struct page *page, unsigned int nr, unsigned long addr, + unsigned long *rss) +{ + struct vm_area_struct *vma = vmf->vma; + pte_t entry; + + entry = prepare_range_pte_entry(vmf, false, folio, page, nr, addr); + + folio_add_file_rmap_ptes(folio, page, nr, vma); + set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr); + + /* no need to invalidate: a not-present page won't be cached */ + update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr); + + *rss += nr; + folio_ref_add(folio, nr); +} + /* * Map page range [start_page, start_page + nr_pages) of folio. * start_page is gotten from start by folio_page(folio, start) @@ -3539,9 +3558,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, continue; skip: if (count) { - set_pte_range(vmf, folio, page, count, addr); - *rss += count; - folio_ref_add(folio, count); + filemap_set_pte_range(vmf, folio, page, count, addr, rss); if (in_range(vmf->address, addr, count * PAGE_SIZE)) ret = VM_FAULT_NOPAGE; } @@ -3554,9 +3571,7 @@ static vm_fault_t filemap_map_folio_range(struct vm_fault *vmf, } while (--nr_pages > 0); if (count) { - set_pte_range(vmf, folio, page, count, addr); - *rss += count; - folio_ref_add(folio, count); + filemap_set_pte_range(vmf, folio, page, count, addr, rss); if (in_range(vmf->address, addr, count * PAGE_SIZE)) ret = VM_FAULT_NOPAGE; } @@ -3591,9 +3606,7 @@ static vm_fault_t filemap_map_order0_folio(struct vm_fault *vmf, if (vmf->address == addr) ret = VM_FAULT_NOPAGE; - set_pte_range(vmf, folio, page, 1, addr); - (*rss)++; - folio_ref_inc(folio); + filemap_set_pte_range(vmf, folio, page, 1, addr, rss); return ret; }