From patchwork Thu Jan 12 08:30:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761667wrt; Thu, 12 Jan 2023 00:24:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpyP23Y6/391rQRw4j5p7zvV3DMFOH7XL6vMsuA9+8LdQcqY2sl5+XpK7cCaU0yKrHxw9+ X-Received: by 2002:a17:907:a08d:b0:7c1:6986:2b7c with SMTP id hu13-20020a170907a08d00b007c169862b7cmr58153816ejc.8.1673511891182; Thu, 12 Jan 2023 00:24:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511891; cv=none; d=google.com; s=arc-20160816; b=BaWEwMeduZEP16e9kgfVV5m3vnjNErP05fA2bVBA/0p+0xEi07CyRzzJ04tJbDYNpK 2FXdF9BDKHsRbqd8nA5onPNYkYRrhJGn0xk+e7+mtfQPGF3PQ1cDl/yUr5Ii9h6TsF8/ kA5NccQ5Es/T434SmSqensB0YZxhPeMyIbkEVoQqFY4PwsTsUi7Cdy/x/mMtOR5Q/SEH O1BX1KnkHX/G9fLsjPsZgssYGw1o1o8R3/+WOqDwmSnotarBUu47450NtPfyp+Cp6Lj+ nsP3P0qNsir3+vlQ2oLLGTa6Hs/13WXR1B4DYrIqbwtKDeb0tvncpaOzgFL4oVr2P81P +7OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rhxXxRerinKO8R0zStf2Cd5XszshE2EKPbc9CMcsJVk=; b=lK+XelriwhDXXk0UneRNsX4fuCRyxxWYpN7Zj4kRicXSPV8E1nsMnZk8EpSins6KUj WGqg49mk82C45XtCBpU7hJW3pliCjVrjE1xljm6PACXRN6WfTaY/aJNoGeQE7hthdzok ZAoe7a5/ta5cMLB7LYVFv36aht8LqrPWjsV6Dt+4ZmyiAJgEixGUggEf2spOOZ+rDi+2 Cq4bjz0rFJx9yXNT81NKx1M3aKcqB7L43nPivyaq/66/SpfOsSSWlwVTJ255jb/5gpYs L3meLGq7hdm1yqwnZ1sazjC1/Rn3XXkEvE21hluQPnSk4HwL0O+fQOXniZvnscHYlzhq ivMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq13-20020a1709073f0d00b007c0905bab0esi19240602ejc.59.2023.01.12.00.24.26; Thu, 12 Jan 2023 00:24:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239958AbjALITZ (ORCPT + 99 others); Thu, 12 Jan 2023 03:19:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239601AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 724CF32183 for ; Thu, 12 Jan 2023 00:17:35 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Nsy304mYVzqV9c; Thu, 12 Jan 2023 16:12:44 +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.2375.34; Thu, 12 Jan 2023 16:17:31 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 1/7] mm: huge_memory: make __do_huge_pmd_anonymous_page() to take a folio Date: Thu, 12 Jan 2023 16:30:00 +0800 Message-ID: <20230112083006.163393-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804404806973003?= X-GMAIL-MSGID: =?utf-8?q?1754804404806973003?= Let's __do_huge_pmd_anonymous_page() take a folio and convert related functions to use folios. Signed-off-by: Kefeng Wang --- mm/huge_memory.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c13b1f67d14e..cb23b24e2eb8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -650,22 +650,23 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, EXPORT_SYMBOL_GPL(thp_get_unmapped_area); static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, - struct page *page, gfp_t gfp) + struct folio *folio, gfp_t gfp) { struct vm_area_struct *vma = vmf->vma; + struct page *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)) { @@ -675,11 +676,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))) { @@ -694,7 +695,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); @@ -704,7 +705,7 @@ 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_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); @@ -721,7 +722,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; } @@ -834,7 +835,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) count_vm_event(THP_FAULT_FALLBACK); return VM_FAULT_FALLBACK; } - return __do_huge_pmd_anonymous_page(vmf, &folio->page, gfp); + return __do_huge_pmd_anonymous_page(vmf, folio, gfp); } static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, From patchwork Thu Jan 12 08:30:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761203wrt; Thu, 12 Jan 2023 00:23:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3LVV2yQ/Rkjcx1OT+iRG0KuwchGsj2rUASQfHiDg2GuGSj4nZvuH3XxUNUbyivisle4td X-Received: by 2002:a17:906:edd6:b0:84d:138a:316 with SMTP id sb22-20020a170906edd600b0084d138a0316mr21499296ejb.36.1673511806698; Thu, 12 Jan 2023 00:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511806; cv=none; d=google.com; s=arc-20160816; b=YxRN2ehodSd2ELxNvRPetmwx7xfMNmyFhHQwrohigI4gHh4aN70X0rimC1ofIE/48X /K2J7swBhOpsAew3+rDSavq9I+2qlxsKT+GiicRj0aaorxhUe6SxcOG7ku+2eKEGetTE QxkZQTm/CRD5BPFnTE1Pk387ZVmHHORp5vCO4QPwvBCGoTCo8AtEILrEu9F5BsJ5KL9P baQsNb84+xrLkHAf8FgbBXS1IgxIfjbcq9IJVLnGZ3JGjpGaJepX2TBc34yAE/VoClI0 aZNlJO0qknCbQrY0xcf2/XtUo1Of1xsf4CfMbA1TTSZjVBR3wlbGADhPHVUlO8x93XER iodg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=f410hYM6HfpdiyxHhhDFQuD0DaLql9Gj21P5cfv/VWA=; b=UFVsfliL2Q0dpf0RzY0PAdhNwkd5Fwna9d8T3EePvKjlSgLB3+1QgS04sMfu/cR3w6 dPfTth6lhns6mFfZClDbkwKXUFJ6xfslgC1bI5wkYTbSkfP4CApBPd74i9mHRLixbOZ1 5rhKEN8I51ByiC/EAAHCP0CjPe+ZFZuL/JLY6lvA7jK241fhKjInPekUd0uasXWa8zVo GF1A2Ba51uwf7cMwbn0p7S+pv9WEw69Thg3AHvcM/0l+I/RoaEth8DAnREksU7kpy28A o+GL0HIG+XG+OYZrmrEXon8ZDr9SPy32X9BVMeFteDjpgacMzW4u1sYY5uRGYjRwxkFn GuEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd40-20020a1709076e2800b007815e9c5b80si19163921ejc.617.2023.01.12.00.23.03; Thu, 12 Jan 2023 00:23:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239678AbjALIR7 (ORCPT + 99 others); Thu, 12 Jan 2023 03:17:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239481AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 467B935902 for ; Thu, 12 Jan 2023 00:17:35 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Nsy3m238PzJq98; Thu, 12 Jan 2023 16:13:24 +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.2375.34; Thu, 12 Jan 2023 16:17:32 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 2/7] mm: memory: convert do_anonymous_page() to use a folio Date: Thu, 12 Jan 2023 16:30:01 +0800 Message-ID: <20230112083006.163393-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804316229484351?= X-GMAIL-MSGID: =?utf-8?q?1754804316229484351?= Convert do_anonymous_page() to use a folio and replace related functions to folio functions. Signed-off-by: Kefeng Wang --- mm/memory.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 56b571c83a0e..1cfdb0fd8d79 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4002,6 +4002,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct page *page; + struct folio *folio; vm_fault_t ret = 0; pte_t entry; @@ -4055,16 +4056,17 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) if (!page) goto oom; - if (mem_cgroup_charge(page_folio(page), vma->vm_mm, GFP_KERNEL)) + folio = page_folio(page); + if (mem_cgroup_charge(folio, vma->vm_mm, GFP_KERNEL)) goto oom_free_page; - cgroup_throttle_swaprate(page, GFP_KERNEL); + folio_throttle_swaprate(folio, GFP_KERNEL); /* - * The memory barrier inside __SetPageUptodate makes sure that + * The memory barrier inside __folio_mark_uptodate makes sure that * preceding stores to the page contents become visible before * the set_pte_at() write. */ - __SetPageUptodate(page); + __folio_mark_uptodate(folio); entry = mk_pte(page, vma->vm_page_prot); entry = pte_sw_mkyoung(entry); @@ -4085,13 +4087,13 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) /* Deliver the page fault to userland, check inside PT lock */ if (userfaultfd_missing(vma)) { pte_unmap_unlock(vmf->pte, vmf->ptl); - put_page(page); + folio_put(folio); return handle_userfault(vmf, VM_UFFD_MISSING); } inc_mm_counter(vma->vm_mm, MM_ANONPAGES); page_add_new_anon_rmap(page, vma, vmf->address); - lru_cache_add_inactive_or_unevictable(page, vma); + folio_add_lru_vma(folio, vma); setpte: set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry); @@ -4101,10 +4103,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); return ret; release: - put_page(page); + folio_put(folio); goto unlock; oom_free_page: - put_page(page); + folio_put(folio); oom: return VM_FAULT_OOM; } From patchwork Thu Jan 12 08:30:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761909wrt; Thu, 12 Jan 2023 00:25:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXtBcqqLqfTnGdr4Lmz8jSoSWpkx3yyxioj1isy223EwcEeoBk//NALpoEgeOawpaQwRUq+u X-Received: by 2002:a17:906:a1c5:b0:7c1:2529:b25e with SMTP id bx5-20020a170906a1c500b007c12529b25emr62771033ejb.43.1673511945581; Thu, 12 Jan 2023 00:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511945; cv=none; d=google.com; s=arc-20160816; b=KKtq1Ob5Ld6SpsxCHp2U4q0hNsZ94m6uYzdoU/os/KQ7vb9Ced854arvZuH+KpSgAq eja38LMapuKzL9/VSYjOf3qg1bCbnkyQt8kq23t5vNtKuvSnY+FkBhKIa4Bmi8gLX7TG 5fmssQdyjsW0Rp8RlTw4/i0poVm4JDDlpUhgIRbZBPi940+jtL2tzwwWcx3cvwgXvDnQ M9ZBC4y9boFDoI1e56JWbsR/k7L8fDxVQIMkyb9T52J+/MJjRnrGIVVN+DsEMpQHQqrP 3F3tFbJ7unLfHRIOpWfhls35ZsFiLLnGJf6kBS2KRPZTOkSQ+SkMpsU70r38XINCRlWY EDQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EWkJujdwo//0sP1d8/c4d92QJNqcyfaKcDeRJS35TxY=; b=LTmppqLJpzPQu57K+gfOrvL2d0GhiiVQ/ae5OGN+aNJxannJ78pjd3tn7BhbGfUb+P HaMQWGEpTbXTA3AAo1jZ8jD4vA7MTngs1qH5GvFJ1LiCB9Dwzq39WKCk9/6ruFfRcyOD uy3FAqu8MmASObss+A+DOoo+U6EY71wO3YpRTnU0/JdB4eNDFAuQRUy6EuEL+xWQRn+a R+nJ8gKLupdvn0HECz5qxSh3GSH3IF9PG3o2C6DryhBtrm+X8rbzSYBs4OJFFlGLShBT ye0ZedW1sETrwtWghp4uZhS5niewxyoolSaQFmFb99inT+Lapczk1yfuQ6euYy8yEdvE ojoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020aa7c68f000000b0048e8c54f6e9si15503574edq.384.2023.01.12.00.25.21; Thu, 12 Jan 2023 00:25:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239720AbjALISK (ORCPT + 99 others); Thu, 12 Jan 2023 03:18:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239628AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB1436319 for ; Thu, 12 Jan 2023 00:17:36 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Nsy6j12wLz16MkP; Thu, 12 Jan 2023 16:15:57 +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.2375.34; Thu, 12 Jan 2023 16:17:32 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 3/7] mm: memory: convert do_cow_fault to use folios Date: Thu, 12 Jan 2023 16:30:02 +0800 Message-ID: <20230112083006.163393-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804461724899780?= X-GMAIL-MSGID: =?utf-8?q?1754804461724899780?= The page functions are converted to corresponding folio functions in do_cow_fault(). Signed-off-by: Kefeng Wang --- mm/memory.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1cfdb0fd8d79..f29bca499e0d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4507,22 +4507,24 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf) static vm_fault_t do_cow_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct folio *cow_folio, *folio; vm_fault_t ret; if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; - vmf->cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address); - if (!vmf->cow_page) + cow_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, vmf->address, + false); + if (!cow_folio) return VM_FAULT_OOM; - if (mem_cgroup_charge(page_folio(vmf->cow_page), vma->vm_mm, - GFP_KERNEL)) { - put_page(vmf->cow_page); + if (mem_cgroup_charge(cow_folio, vma->vm_mm, GFP_KERNEL)) { + folio_put(cow_folio); return VM_FAULT_OOM; } - cgroup_throttle_swaprate(vmf->cow_page, GFP_KERNEL); + folio_throttle_swaprate(cow_folio, GFP_KERNEL); + vmf->cow_page = &cow_folio->page; ret = __do_fault(vmf); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY))) goto uncharge_out; @@ -4530,16 +4532,17 @@ static vm_fault_t do_cow_fault(struct vm_fault *vmf) return ret; copy_user_highpage(vmf->cow_page, vmf->page, vmf->address, vma); - __SetPageUptodate(vmf->cow_page); + __folio_mark_uptodate(cow_folio); ret |= finish_fault(vmf); - unlock_page(vmf->page); - put_page(vmf->page); + folio = page_folio(vmf->page); + folio_unlock(folio); + folio_put(folio); if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY))) goto uncharge_out; return ret; uncharge_out: - put_page(vmf->cow_page); + folio_put(cow_folio); return ret; } From patchwork Thu Jan 12 08:30:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761428wrt; Thu, 12 Jan 2023 00:24:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXtarGC8NeyqzzgpeOagYs60M+PqXrjCUoo6SIq4KeLyx2UYUqEtTG7rY+JIHgX54MKodX7c X-Received: by 2002:a05:6402:f02:b0:46f:a2c2:405b with SMTP id i2-20020a0564020f0200b0046fa2c2405bmr78200585eda.37.1673511844481; Thu, 12 Jan 2023 00:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511844; cv=none; d=google.com; s=arc-20160816; b=T7MkQD3EVK6k8ZExLZ/9bHfrMxPuWkyKKxb+TR9ypeTVW30GBn5ObA6W43ULufzZff A2FPzNUsBqfmmq212G63cuJaPMfHCg0enC4NZvv2OCEFk5noDI+3Gk0SarPwKM2gdpEn QHob8+2bkO6Pi8CExorfx5R5GRbSpnjsYrM+Z/dTpsYHo0hmCfuRf/J9CIm3qZR6x/t3 UAu8PkJGT7BTUOpI/ZjHPKaYK69AR5ThijHLcCS/OBAqR26BghXTSaxs58UIRp523EB3 K9dweSdbBPaKJHiFYjAiTGzKhhcbzxCPX7c3LgWJAxVpD37wIIa6il2bMTIY/bdz5aLo B7AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vPWAoifsdZDSaIY3s2IrQdDt6yOwKVi4WGwzwvvUpwQ=; b=a5EhHHJ+op2tcGnpr30uzgQdn29vYsGaG531AeCWXE3B/dXXqt32YVfemcdnyRqedL i3UBl/ZVaUwXVxlOgZCQNAiAXa2MYi1VQP2WQ7fZDrM3JlAbT+IxU3+Wt6xW+WA7AbtE maC0xd0q8MrATuhhTyGFFLk5Hn56IOcgO/zOhZ8wxWlTjV3XSmP2Q0G/fxMUXBRTQ32t 1x9pgYKHNIvw2Nd0f2ZYykQOLWhTFZdmDABtpF7wdrPvRTYBQE90sRRPbfgCD4Ta2WdB jv3lHD5oqLwlSCjenCZCH3w6bThp7jg2wPkw/9TcPjPnZG8CzZHj7JjGZJUbGjXF6r27 m3NQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ez19-20020a056402451300b00489e993b8easi14843558edb.630.2023.01.12.00.23.41; Thu, 12 Jan 2023 00:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239825AbjALISa (ORCPT + 99 others); Thu, 12 Jan 2023 03:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239535AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FA4C3591A for ; Thu, 12 Jan 2023 00:17:35 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Nsy315qzgzqV8x; Thu, 12 Jan 2023 16:12:45 +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.2375.34; Thu, 12 Jan 2023 16:17:33 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 4/7] mm: memory: convert page_copy_prealloc() to use a folio Date: Thu, 12 Jan 2023 16:30:03 +0800 Message-ID: <20230112083006.163393-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804356221352111?= X-GMAIL-MSGID: =?utf-8?q?1754804356221352111?= The page functions are converted to corresponding to folio functions in page_copy_prealloc(). Signed-off-by: Kefeng Wang --- mm/memory.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f29bca499e0d..b66c425b4d7c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -958,19 +958,19 @@ static inline struct page * page_copy_prealloc(struct mm_struct *src_mm, struct vm_area_struct *vma, unsigned long addr) { - struct page *new_page; + struct folio *new_folio; - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, addr); - if (!new_page) + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, addr, false); + if (!new_folio) return NULL; - if (mem_cgroup_charge(page_folio(new_page), src_mm, GFP_KERNEL)) { - put_page(new_page); + if (mem_cgroup_charge(new_folio, src_mm, GFP_KERNEL)) { + folio_put(new_folio); return NULL; } - cgroup_throttle_swaprate(new_page, GFP_KERNEL); + folio_throttle_swaprate(new_folio, GFP_KERNEL); - return new_page; + return &new_folio->page; } static int From patchwork Thu Jan 12 08:30:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761432wrt; Thu, 12 Jan 2023 00:24:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXu17Gew/g4rix7jbs8G/Te53Yx9az4AkeN8F2Bj9WaA6ArC2b7MhUoWY06SUyLw1zgwrStr X-Received: by 2002:aa7:d849:0:b0:497:7e1e:caf9 with SMTP id f9-20020aa7d849000000b004977e1ecaf9mr19191835eds.15.1673511844953; Thu, 12 Jan 2023 00:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511844; cv=none; d=google.com; s=arc-20160816; b=ktXrLTBw4IA/n86fPsKnpbKM905Q++KsaaDHht5o7SztOidiG1uYzhoxsu26OV4NUx 1UPAnwAd8q/gInShq8gZlxS1BN9KR8ZbXTY6r1so5QDkDrJBqhbqYJl58LwS4dfkOJQc RuJy6MSs+CAu21U6zWB2vr6BB3VobMUWJmCI9Qr+GhEeQOsrN+Y0buOEsWtO1+ROpvt4 dgYPra4zC5z8D8hPQ00TRiILJlfe2NDF96YMBpbEeIerBi47oxLkk5Nybv4BXC3JZ84b F5b+wSXzucw+E10/KcPG2eQJP/iGTOC5nqRqXRRGHXfk1/ThB+T9KaeqX4V0MFj00oK+ OT3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BI+GrC6ViWwQkI7N2V00Cjbe16xcRU3pJmqY+T7EhCQ=; b=zmI71TZDlv5icteLhImGQdhX1GkbfB2p1w6pFphY0ZkZepB7PMADTrw7ZoejH1yfc7 1AMSv9UU5t6LlZ2bM7cONrkpxVpQZjug906liA7zRwh5s40cxIgCdWgFrWcjkpJAvSSd K4qxo3E4Uih8j77Sus4SWpykAk1UQG3dpgU0pr4Um8D36R3mHfz/OGfCAcLeYmih+wBY TJpuffvrbTqvXbVva4x2yGkc4wA4NI+DwY031mGaqajT5mGoZZzVa1+jKoNfExDkFnUa WBD9zrxjlcZjCPYvKitH0dowq5tGV8gdHpHJkdiMJtVwaS9Ef9BBScijBNB6olZRpI0G npsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a056402275300b0048d5b18b00asi19370459edd.130.2023.01.12.00.23.41; Thu, 12 Jan 2023 00:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239882AbjALITJ (ORCPT + 99 others); Thu, 12 Jan 2023 03:19:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239507AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4695E35912 for ; Thu, 12 Jan 2023 00:17:36 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Nsy6j6Y2kz16Mkg; Thu, 12 Jan 2023 16:15:57 +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.2375.34; Thu, 12 Jan 2023 16:17:33 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 5/7] mm: memory: convert wp_page_copy() to use folios Date: Thu, 12 Jan 2023 16:30:04 +0800 Message-ID: <20230112083006.163393-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804356583744355?= X-GMAIL-MSGID: =?utf-8?q?1754804356583744355?= The old_page/new_page are converted to old_folio/new_folio in wp_page_copy(), then replaced related page functions to folio functions. Signed-off-by: Kefeng Wang Tested-by: SeongJae Park --- mm/memory.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b66c425b4d7c..746f485366e8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3044,7 +3044,9 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; struct mm_struct *mm = vma->vm_mm; struct page *old_page = vmf->page; + struct folio *old_folio = page_folio(old_page); struct page *new_page = NULL; + struct folio *new_folio = NULL; pte_t entry; int page_copied = 0; struct mmu_notifier_range range; @@ -3060,12 +3062,13 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) vmf->address); if (!new_page) goto oom; + new_folio = page_folio(new_page); } else { - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, - vmf->address); - if (!new_page) + new_folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, vma, + vmf->address, false); + if (!new_folio) goto oom; - + new_page = &new_folio->page; ret = __wp_page_copy_user(new_page, old_page, vmf); if (ret) { /* @@ -3075,9 +3078,9 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * from the second attempt. * The -EHWPOISON case will not be retried. */ - put_page(new_page); - if (old_page) - put_page(old_page); + folio_put(new_folio); + if (old_folio) + folio_put(old_folio); delayacct_wpcopy_end(); return ret == -EHWPOISON ? VM_FAULT_HWPOISON : 0; @@ -3085,11 +3088,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) kmsan_copy_page_meta(new_page, old_page); } - if (mem_cgroup_charge(page_folio(new_page), mm, GFP_KERNEL)) + if (mem_cgroup_charge(new_folio, mm, GFP_KERNEL)) goto oom_free_new; - cgroup_throttle_swaprate(new_page, GFP_KERNEL); + folio_throttle_swaprate(new_folio, GFP_KERNEL); - __SetPageUptodate(new_page); + __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, vmf->address & PAGE_MASK, @@ -3101,8 +3104,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ vmf->pte = pte_offset_map_lock(mm, vmf->pmd, vmf->address, &vmf->ptl); if (likely(pte_same(*vmf->pte, vmf->orig_pte))) { - if (old_page) { - if (!PageAnon(old_page)) { + if (old_folio) { + if (!folio_test_anon(old_folio)) { dec_mm_counter(mm, mm_counter_file(old_page)); inc_mm_counter(mm, MM_ANONPAGES); } @@ -3130,7 +3133,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ ptep_clear_flush_notify(vma, vmf->address, vmf->pte); page_add_new_anon_rmap(new_page, vma, vmf->address); - lru_cache_add_inactive_or_unevictable(new_page, vma); + folio_add_lru_vma(new_folio, vma); /* * We call the notify macro here because, when using secondary * mmu page tables (such as kvm shadow page tables), we want the @@ -3139,7 +3142,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) BUG_ON(unshare && pte_write(entry)); set_pte_at_notify(mm, vmf->address, vmf->pte, entry); update_mmu_cache(vma, vmf->address, vmf->pte); - if (old_page) { + if (old_folio) { /* * Only after switching the pte to the new page may * we remove the mapcount here. Otherwise another @@ -3166,14 +3169,14 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) } /* Free the old page.. */ - new_page = old_page; + new_folio = old_folio; page_copied = 1; } else { update_mmu_tlb(vma, vmf->address, vmf->pte); } - if (new_page) - put_page(new_page); + if (new_folio) + folio_put(new_folio); pte_unmap_unlock(vmf->pte, vmf->ptl); /* @@ -3181,19 +3184,19 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * the above ptep_clear_flush_notify() did already call it. */ mmu_notifier_invalidate_range_only_end(&range); - if (old_page) { + if (old_folio) { if (page_copied) free_swap_cache(old_page); - put_page(old_page); + folio_put(old_folio); } delayacct_wpcopy_end(); return 0; oom_free_new: - put_page(new_page); + folio_put(new_folio); oom: - if (old_page) - put_page(old_page); + if (old_folio) + folio_put(old_folio); delayacct_wpcopy_end(); return VM_FAULT_OOM; From patchwork Thu Jan 12 08:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761469wrt; Thu, 12 Jan 2023 00:24:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXvrDAfLtBJsDk7US5jJsz/XohCp4uGwsMqPHpfrqFGuTFU2DUadbCEEEMarxmSCaHBdQS6d X-Received: by 2002:a17:906:494b:b0:862:e612:effe with SMTP id f11-20020a170906494b00b00862e612effemr3291959ejt.14.1673511853630; Thu, 12 Jan 2023 00:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511853; cv=none; d=google.com; s=arc-20160816; b=ihkXdt9zCVY7+YE8p9CCEz52lFLvKzVux1pDfXuYKLrg0BRca1H4BMJdLWE07Y76JG Oc0aFrwZqXSTRpE9UAj1PSDhPNlSifoxb8/H4AmWEAh3hWEYzUwWTxmz7u6BndYQO5HG Q4dz+59yPK/WTf5BLFSt45hMamIcpekJ3gqO3YdXwREphY/gziqLqaNXZk57RVPJfxwH TsueX8i5VJZ0ueAVqAnBbMs5KJ42U3JLJ2So7njBDCNmpNqSxi6M8rB+BbGs5MGYdCSd +YM7M+pmR/PJ6Jq0UwNyy8hLg+mnbolPEyHjyrwuRyNV2m1S8Fv2UXdkLdp+cQMSAUF1 fV4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Al8EKcnYAtYB1JWIzS1KLhE26inWUEAs3Hs0krdsZ4w=; b=IjZQ38NhvM64JdXR1RHofbwMZQYr/q+E/sU7x+xP+OzS1EDHtafP+50WWUBx2wqlKp V06QJwBEsVQ2zo+eDUDrjFtcM+jMZjuZRo5/zqcfDQ4WJjEz428XXNALb8vXRXUQVu6u Yq0UAEkon1jY+iQdQzLd8ZEzOt7y4xeMpmNo6M+Ni6UyNULgiiGTyLuTx1cLtPbZyR+F 4Jvcs5vnMrYbh4XllkZULlol0VDqbJXloEQbQUta0mGcYO/xQM4S+dODXT1j3lzWMitY nMQIEYbbNiWWUblXMj1EnnUO7+aiC3kDH7sT/CkKh4csoGXEce9F7ldDmRIap0BpECqZ OcpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di15-20020a170906730f00b0078d805901b1si19337024ejc.489.2023.01.12.00.23.50; Thu, 12 Jan 2023 00:24:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239747AbjALISQ (ORCPT + 99 others); Thu, 12 Jan 2023 03:18:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239635AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC873724D for ; Thu, 12 Jan 2023 00:17:36 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Nsy324H2pzqV7h; Thu, 12 Jan 2023 16:12:46 +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.2375.34; Thu, 12 Jan 2023 16:17:33 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 6/7] mm: memory: use folio_throttle_swaprate() in do_swap_page() Date: Thu, 12 Jan 2023 16:30:05 +0800 Message-ID: <20230112083006.163393-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804365863494814?= X-GMAIL-MSGID: =?utf-8?q?1754804365863494814?= Directly use folio_throttle_swaprate() instead cgroup_throttle_swaprate(). Signed-off-by: Kefeng Wang --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 746f485366e8..abc4e606d8bc 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3839,7 +3839,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) lru_add_drain(); } - cgroup_throttle_swaprate(page, GFP_KERNEL); + folio_throttle_swaprate(folio, GFP_KERNEL); /* * Back out if somebody else already faulted in this pte. From patchwork Thu Jan 12 08:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 42299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3761427wrt; Thu, 12 Jan 2023 00:24:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXvuQFT+gLaVDoUXFo0euC/DLBAaddCF2bTnvHKlb5Ev7NPR3Qh9gke7HBu3AxeL8Iz56P83 X-Received: by 2002:a05:6402:2497:b0:48e:b020:6c14 with SMTP id q23-20020a056402249700b0048eb0206c14mr40387839eda.26.1673511844442; Thu, 12 Jan 2023 00:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673511844; cv=none; d=google.com; s=arc-20160816; b=nYz6gYlHgwLJVbVC00Lt7Ov1n9lT36Bazh+6AxhfIt41V1tb0QsG3085Yhv/BU1fHL 1RZvLbdajE/HLffuCuoCleFDtZX+rMGuSew4RdQk+iMK1+eBJR+zuFT9GiMLio1W5yAH ZaOzdB8x0awv7HJY5+vo+1CqxWzkGQTPr4Nay3i2f/vQEGIImqB0njOnlQgLZzDGr5Wf 1om9z3Pm4u8tvmMqeLtii3aQv7lfDhzrgo9+UBm3Pkkb6wx6aTgcdECKgguOcjfZSGmt J3cr/Rbk+eljWbGXZ7QF63uypK+8osjVpzy6m5ZZb7vn85fyoINRDmTySro+uZY6g2XR BT0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+z4eofE9nff3vyL8ObJyK/MRgR2W0Z1B4DVPxEokq1E=; b=gY5GTVNZ5usYEXMKl/4HXbEQQoXZqBST+SperRqvZ8S6hUbnd41KhArKILPuuoJZQ3 nS9DZ0GUmgwzogtrl5wNG5Of4IgnrdeOGlt9I5yQDY4jTZx+rqIYvBuy/salgIf3LTyg 9twPnPaEUmvb/bDSof1QsUz51wnu2UorpcDCl2rMMReBljCvdVMGI4ZAmOk43SpeYtTc 89+GaWyl8vCyahEgHh1l3FV1DQ+4qqJyEtCa1j6ZPszdSiEhLqQLHyJqFZpeMN7T4cdn 22jMAVR6Ds9vW1twV9N5gRyIxmWd6FkvvYhRQ0yNGBfasWW2kqLqClXHxL+I7Uu38ba1 igqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id er18-20020a056402449200b004971b435d43si15668837edb.82.2023.01.12.00.23.41; Thu, 12 Jan 2023 00:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239844AbjALITA (ORCPT + 99 others); Thu, 12 Jan 2023 03:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239622AbjALIRx (ORCPT ); Thu, 12 Jan 2023 03:17:53 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FBE23724A for ; Thu, 12 Jan 2023 00:17:37 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Nsy6k50gwz16MZK; Thu, 12 Jan 2023 16:15:58 +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.2375.34; Thu, 12 Jan 2023 16:17:34 +0800 From: Kefeng Wang To: , , CC: , Kefeng Wang Subject: [PATCH -next 7/7] mm: swap: remove unneeded cgroup_throttle_swaprate() Date: Thu, 12 Jan 2023 16:30:06 +0800 Message-ID: <20230112083006.163393-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230112083006.163393-1-wangkefeng.wang@huawei.com> References: <20230112083006.163393-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754804356192133231?= X-GMAIL-MSGID: =?utf-8?q?1754804356192133231?= All the callers of cgroup_throttle_swaprate() are converted to folio_throttle_swaprate(), so make __cgroup_throttle_swaprate() to take a folio, and drop unused cgroup_throttle_swaprate(). Signed-off-by: Kefeng Wang --- include/linux/swap.h | 12 ++++-------- mm/swapfile.c | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 209a425739a9..2674408e6d63 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -641,22 +641,18 @@ extern atomic_t zswap_stored_pages; #endif #if defined(CONFIG_SWAP) && defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) -extern void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask); -static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) +extern void __cgroup_throttle_swaprate(struct folio *folio, gfp_t gfp_mask); +static inline void folio_throttle_swaprate(struct folio *folio, gfp_t gfp_mask) { if (mem_cgroup_disabled()) return; - __cgroup_throttle_swaprate(page, gfp_mask); + __cgroup_throttle_swaprate(folio, gfp_mask); } #else -static inline void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) +static inline void folio_throttle_swaprate(struct folio *folio, gfp_t gfp_mask) { } #endif -static inline void folio_throttle_swaprate(struct folio *folio, gfp_t gfp) -{ - cgroup_throttle_swaprate(&folio->page, gfp); -} #if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP) void mem_cgroup_swapout(struct folio *folio, swp_entry_t entry); diff --git a/mm/swapfile.c b/mm/swapfile.c index a5729273480e..3abf514c3f28 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3636,10 +3636,10 @@ static void free_swap_count_continuations(struct swap_info_struct *si) } #if defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP) -void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) +void __cgroup_throttle_swaprate(struct folio *folio, gfp_t gfp_mask) { struct swap_info_struct *si, *next; - int nid = page_to_nid(page); + int nid = folio_nid(folio); if (!(gfp_mask & __GFP_IO)) return;