From patchwork Thu Mar 2 11:58:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13157121 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 8A605C6FA8E for ; Thu, 2 Mar 2023 11:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5731D6B007E; Thu, 2 Mar 2023 06:37:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FBAD6B0075; Thu, 2 Mar 2023 06:37:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2099A6B007B; Thu, 2 Mar 2023 06:37:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0796C6B0073 for ; Thu, 2 Mar 2023 06:37:50 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B2F3640FB7 for ; Thu, 2 Mar 2023 11:37:49 +0000 (UTC) X-FDA: 80523758658.10.06A4610 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id E36661C0002 for ; Thu, 2 Mar 2023 11:37:46 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1677757068; 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=xbLPhSiqjy6IWZ/qhYrXAG1DUxlcCUFQt7fRdvz4lyg=; b=60PGgU8+tB+CJJdt+vLQ9dnDfU/kZGkit39NblVToIm6QLP3kPTLf+5agJNeTn9nuODRAg kEYwbPJapyKGshos1eF6n7jDPBsC520SgcB8zRNtY6CoVjjUFZOF8s/ysfUQtEcQudWOgx WKl5/1zmreBr+69yoHFi5fk8Avojd7M= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677757068; a=rsa-sha256; cv=none; b=ubtzjClycDrPyWPIhvwVOU8RPiSMJH9GPRmZr6tAv555vIhm7Lp2y8pQMYAO3K9FUKeWrd JFBzrIrozHH5swGoLFhnii/yIslUsKv5SMTbTjozqmJgZiC9tNh7ymgxPEQHfzAf7SQn2R NTxrpC7RyuXTsKkedBOHzG+u9e6BkEo= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PS8Cp0vWWz16P6X; Thu, 2 Mar 2023 19:35:02 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 2 Mar 2023 19:37:41 +0800 From: Kefeng Wang To: CC: , , "Matthew Wilcox (Oracle)" , Kefeng Wang Subject: [PATCH v2 1/7] mm: huge_memory: convert __do_huge_pmd_anonymous_page() to use a folio Date: Thu, 2 Mar 2023 19:58:29 +0800 Message-ID: <20230302115835.105364-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230302115835.105364-1-wangkefeng.wang@huawei.com> References: <20230302115835.105364-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E36661C0002 X-Stat-Signature: 453oatr3xn8fb8t7posjgtg4yiyeyykh X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677757066-356002 X-HE-Meta: U2FsdGVkX1+mkWEDb27hwf3EX1QwwdXX1uzjbNzpnE4/zIKtkMRD+iAd3+d/m/1AoO0FYPm/bcfILDSvjGq2GHHyRozg1osHMknwGmjd4ruEofmfX9tP6ltmMGYTBL4hqVLxRtP4dStBTIt//JEHCE1JxW46dvRlWuQrgZdgzYTMEc0MCsLkLptoXqndxJJBh0536i9UcwBUe76BbEyaTMRh339aaxSfdXmiYFha8OAwlv0XDWPVWpnRpBR4XFKeDESo68hRxfwul9xoaL+f63sRoQdDalhL36tXwDZriYb78eoK2ag+pLY+kop37TTy666GRbFQwkih2BhswRumsRZRhBL/dVQuHdXeeIbBR7v/f60vx9zLWAUbdV0LFQEXJI7552BUVqc/huSUIsH36Dxa+Ou6+3RoAxeeEKSQzBoDUnUCZrTY6PF17QJUjfHHA2Uen+mXBOAa3ONDBFE6Zfqu9rkEQ20K/JMwlXwGkW8opv2cs8Z3q1q5IydJwfbCFHr+MvJ4VMLsTvv9+8NjMsvV4lnxDi5OA4xxYjqD4o6H1cQkEoqn+VL6zqPB4eY0AZd6ZVrqhH7EXPvNUz7JcbIx8wOzwdeIfB4+MAZaj1/WWod3ImAgFEpINmCjzuPO1428GZ+NOWL3Y05R3dLFDRExrnmVgxPCF+f6bLcfFelARvw4zphD8QFtIXl06w/MNTSL15IYzN+kOWLBGBVPeOFGwOgWODxCi7aaA+1CGaGDhUt2UheVtpF43Ar3yTf9aGUnxWgc1ulm5VN5rqD4jfrb0/QSHLjsYJhOM2Rjoq0skiU+laOMuCwrhNnhFIwfvu4E9rzHzoFOi6tMSeCzJ0lvaOPnhK4Iz3DG4X6qdpq8DztfpgbCcoXdjXV84HOxnZjODr03DRjvoBYNxMr/kQ8TlasHzO4iKhPi9ZHqskCenEDE+wbJfgmuo8WpoghP34AhhJldr8lEFeB+j1y UC65TfLX PL5QrLvTGjA0CbHLmkXHsfhvCAwNb3QTe3ERvIB8hIN8ZZ13u5oTUV8IY1paso/ENDLEgC1JMHAeHo4vclXtX+HTwQfD7WQNrnZkgVMaLMAzk6zN+xh6bmTJdB1TMCP+Y1H60+tNCHMujq46ETdVydMfIhePAtHQnaPfgYyoWDOHxjcWlx8EsavVNGorWhpd0Dg5PFJBfVwS/95k= 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: Convert from page to folio within __do_huge_pmd_anonymous_page(), as we need the precise page which is to be stored at this PTE in the folio, the function still keep a page as the parameter. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4fc43859e59a..39c19c5345ae 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -656,19 +656,20 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page, gfp_t gfp) { struct vm_area_struct *vma = vmf->vma; + struct folio *folio = page_folio(page); pgtable_t pgtable; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; vm_fault_t ret = 0; - VM_BUG_ON_PAGE(!PageCompound(page), page); + VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); - if (mem_cgroup_charge(page_folio(page), vma->vm_mm, gfp)) { - put_page(page); + if (mem_cgroup_charge(folio, vma->vm_mm, gfp)) { + folio_put(folio); count_vm_event(THP_FAULT_FALLBACK); count_vm_event(THP_FAULT_FALLBACK_CHARGE); return VM_FAULT_FALLBACK; } - cgroup_throttle_swaprate(page, gfp); + folio_throttle_swaprate(folio, gfp); pgtable = pte_alloc_one(vma->vm_mm); if (unlikely(!pgtable)) { @@ -678,11 +679,11 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, clear_huge_page(page, vmf->address, HPAGE_PMD_NR); /* - * The memory barrier inside __SetPageUptodate makes sure that + * The memory barrier inside __folio_mark_uptodate makes sure that * clear_huge_page writes become visible before the set_pmd_at() * write. */ - __SetPageUptodate(page); + __folio_mark_uptodate(folio); vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); if (unlikely(!pmd_none(*vmf->pmd))) { @@ -697,7 +698,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, /* Deliver the page fault to userland */ if (userfaultfd_missing(vma)) { spin_unlock(vmf->ptl); - put_page(page); + folio_put(folio); pte_free(vma->vm_mm, pgtable); ret = handle_userfault(vmf, VM_UFFD_MISSING); VM_BUG_ON(ret & VM_FAULT_FALLBACK); @@ -706,8 +707,8 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, entry = mk_huge_pmd(page, vma->vm_page_prot); entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); - page_add_new_anon_rmap(page, vma, haddr); - lru_cache_add_inactive_or_unevictable(page, vma); + folio_add_new_anon_rmap(folio, vma, haddr); + folio_add_lru_vma(folio, vma); pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable); set_pmd_at(vma->vm_mm, haddr, vmf->pmd, entry); update_mmu_cache_pmd(vma, vmf->address, vmf->pmd); @@ -724,7 +725,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, release: if (pgtable) pte_free(vma->vm_mm, pgtable); - put_page(page); + folio_put(folio); return ret; }