From patchwork Fri Nov 3 14:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13444569 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 DF53BC4332F for ; Fri, 3 Nov 2023 14:04:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93F48280026; Fri, 3 Nov 2023 10:04:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EECC280021; Fri, 3 Nov 2023 10:04:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B848280026; Fri, 3 Nov 2023 10:04:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 63314280021 for ; Fri, 3 Nov 2023 10:04:06 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2A9B8A062F for ; Fri, 3 Nov 2023 14:04:06 +0000 (UTC) X-FDA: 81416812092.30.1FAB43B Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf05.hostedemail.com (Postfix) with ESMTP id DC1A9100026 for ; Fri, 3 Nov 2023 14:04:01 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1699020244; 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=MdhMIc9GunfmcgvY7/8IJnElK+TVJK6hHFkN45VneUA=; b=gqjOEWMe5DXP+VntirblWPAtU2I7hYjzxRnNezEvAAPWYi/MMrAiSgwFzimZcii6cxJtEI GDCu62nqlPI8W3J/F9Z+mnKl3urwYOeuNDdRIJq05QKe1PLqQp0DD9FKNV8SycpdVZERCB YfihRDVv/SRAaM3EhbKeVhqwEC/05Is= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699020244; a=rsa-sha256; cv=none; b=v088MN8valtlWrchtrJ69lZ/Nn4hkEtaFkiRMFOWe0k2W07JpuOjsgdPENB3vfyS2AMPfz MpLQBGCKuVMLd4E3YrjqqMQkVTQZb+VSR/O/AoTK5X/9+gbjepZYMsTJPq1Gb+FLCpZv0q SnOadE6J8pQd5AJWK35kLqQi9EJKSGE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SMMpQ12P0z1P7pT; Fri, 3 Nov 2023 22:00:46 +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_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 22:03:48 +0800 From: Kefeng Wang To: Andrew Morton CC: , , Matthew Wilcox , David Hildenbrand , , Kefeng Wang Subject: [PATCH 13/18] mm: memory: use a folio in insert_page_into_pte_locked() Date: Fri, 3 Nov 2023 22:01:14 +0800 Message-ID: <20231103140119.2306578-14-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231103140119.2306578-1-wangkefeng.wang@huawei.com> References: <20231103140119.2306578-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-CFilter-Loop: Reflected X-Stat-Signature: mg65y8dsifoqf3xrn8ctfu3dif87bonr X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DC1A9100026 X-Rspam-User: X-HE-Tag: 1699020241-776320 X-HE-Meta: U2FsdGVkX19mwJVJJRlGqc2Q2wPeZg566XF5WnwxMGXrmtwXBJEfkG0qdSJVc3jNHJ9At83LnL01UZ2cpIyrHLIO7C0l09gsv0v0c1/IuCL9W32j9/pue/aCSHt1rDJxYNcjJ/+PvFVSP2/gGkUvYCUJK5i4USHG/FYU+t0F9cm6uCbsmSSX5icRHqSp7XgMInhhLwtdwktxy6jSx11ZxXg7u2j2/yCMMlFweViZ5a1ST3T8TicOuIMjO4haagAuaAngEbVy83FcLROoUPd5thdOfhy3qqvF7gvQf8NmR61bdOzUZ8cZT0PirCWpm7qW8hPXj20APT0uONi/KXrFDo9rAO497QUWdBaFGI00Pm144jEC3B6tmxfJ7Vcnh4pqB8QONoG1T7zrvCGbpaQgREY9MuHgeFcy3Gczid208PtXrGH06oNcocgn/1+Tgj9lN8UCoGclkVBNfvh4svVDzGVxeosaRiDErmFMFUo0d6T91oJ2RqFDb98T3p6TLDz+7ZtmDbi8IdYO2IEtfrnzajN+mZhhPJCANmaSMQX+ZR3iW9iB/IYVi/Cdas008BHWyt0J0EH/79vn6qgMmgIrc6g7yLMLjEE89lgOW1zhqUn/58boL6x9Z82emT/xlnsSoXzzDkX3weRRQaCiLjEDegkaR5MsnE+ndF9D+Mtw/lQoDRwTD+4tPcrWN4wNaGcgFm6eGyEnZh1gKHjUvu+TPuXFvo47mWYRvqNARomiumMsNNmmsFZQ8eO2hwiRJywrNgqeHEDZ5x+4zduXjm1xfqsMWndxSyFbUrV+//qeF5XRWAh93TpdBUfyEuDC422bW2HwFfzOUPYJGDLLHSAQZxI5au89ULgONBAlt0Ni4cK7MLJHZzZLr6B1h4JMhe1oaHVtJI6/TVCFgR4BrPXmeivtjJvIuQPYnT9GLGLokM7sBq13XWZd0tFded6E40oewTt2zhZJ2lobn00zJ/b nA6/aYPB s4mC68VUv1bVmZIrE/y0GNDMsVmycXJmrYSvmNJVnb1EBTwAuEPFfdqNryI0e6x1PLSGHSoczdit7oKalqOaY0O6dissYYW7KOnJdiF/5jJNeV/E/lbEUT/cnJwf3oSmve4J5a0n7t5GJuJtKfj8Dn2pNtKf3mMeYzVBGZ3v/8Wv+IN7K42V2nYYJxsGMo/Nr6Ol8II3uweG3TzizpqBLFArOKg== 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: Use mm_counter_file_folio() to save one compound_head() call in insert_page_into_pte_locked(). Signed-off-by: Kefeng Wang --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 2d90da70a1c8..584fe9a550b9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1845,11 +1845,14 @@ static int validate_page_before_insert(struct page *page) static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, unsigned long addr, struct page *page, pgprot_t prot) { + struct folio *folio; + if (!pte_none(ptep_get(pte))) return -EBUSY; + folio = page_folio(page); /* Ok, finally just insert the thing.. */ - get_page(page); - inc_mm_counter(vma->vm_mm, mm_counter_file(page)); + folio_get(folio); + inc_mm_counter(vma->vm_mm, mm_counter_file_folio(folio)); page_add_file_rmap(page, vma, false); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0;