From patchwork Fri Sep 22 19:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13396369 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 77045E8180A for ; Fri, 22 Sep 2023 19:36:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED9C76B0305; Fri, 22 Sep 2023 15:36:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3DCD6B0307; Fri, 22 Sep 2023 15:36:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB5F86B0309; Fri, 22 Sep 2023 15:36:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B0E436B0305 for ; Fri, 22 Sep 2023 15:36:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8AD99C02D2 for ; Fri, 22 Sep 2023 19:36:54 +0000 (UTC) X-FDA: 81265241148.07.E6AD0D9 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf25.hostedemail.com (Postfix) with ESMTP id 922C9A0026 for ; Fri, 22 Sep 2023 19:36:52 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cjin4MA4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695411412; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0U3LCSGR9Uhg87btUKAqCyaspyDfBYXfRcxhUzWxmiQ=; b=M63/VtGg9BnKaWx6uDI/5HsbK65hCLb0MgKsdgSDwWUJj7lv0PPRbhvkzXI/qNHPzlixAw tJRfS2/BeuZJAk3GIMCiwSGIOT3jXIHgVCloN3MgCYs8j4k5sPctGnxktbXhHMncnNnkIH Qi/rDkwxHZ+34yR0gC7ezgFavCvnz1Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cjin4MA4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695411412; a=rsa-sha256; cv=none; b=YgBl39isKAopgtaOWx4vDik35W5K0nx7U7OMNE4KIXCTUEYieygRSgwxGKqx7hyt8Ls6Hj d1o+0L2cX7qhc42OlbgLXSqVbRRXB1BL7E9A2WnWoG/AybishQ9uGhFt6115d16vQ5V8wB socrQFQhIuoxPkI3ILPZJ425ViJE8pU= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1c465d59719so22799335ad.1 for ; Fri, 22 Sep 2023 12:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695411411; x=1696016211; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0U3LCSGR9Uhg87btUKAqCyaspyDfBYXfRcxhUzWxmiQ=; b=cjin4MA4s4zLct53zOeMaTns1XTeC5935ifttddPYgSoQX5A8MKPX3aawaYkPggDB6 UsQqlCl24c7sUOpLku37VeeEgVFORAcmn5KSCgTr9ojUB4AL4niGqBSBCem4Az4j1DWF 0uliZ3hk8uDb3zyr0TcoYThnpcMh37bbAH3aqBCNME047EbNG0C9Ne3+Y2lsrtcpdxan Hudul1JTf7vFK59Z5uZ3PwzZaixWP7lKkpyDc1ggAZMnW3xdf+/1r38kQWwdX7I0pnWt Ivb5gbynyCVSj+xpj5zxEhuK58Zh6WSNmCRBMxdlCB6HYY4czubydrezuFd7F70/fTIo aahg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695411411; x=1696016211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0U3LCSGR9Uhg87btUKAqCyaspyDfBYXfRcxhUzWxmiQ=; b=nJ2Xo+0vtTQ+NanRchPGP7MImlQqudkRi30NMUsI5mIH/HVy7yGJv1AxBh9AmiKKCT omAYXfoB+n6Nhi+DpjHKOhFstGMFV+H04+O8DlFLiN7NawJ2Bs5vnmZPhzaA07UDhDYf Cn/dS4MAp1c9BKtLV/uDRRZr4t7Zx78vqlyvlizMb9qmy9xpIGeHD7Pemj+FP+4cqGxi XYjt4WoefRedGXcjN214UdFbzZoQIxs8hx1CJ/xILTJ1mz7VoBCiiwRxNrlyNPgBC4OD tfYp2kESmnf0SoQuxOllwIanmkhUjxbJb0Zzx9h4BEN2RMIQvjD2HM3xwxvXPihaNPKz Z9zQ== X-Gm-Message-State: AOJu0YxoKVK4nzdVrRI4dh+hNMTpXdquEhTrmE/Zf8RXm1UqDakX6F5K Fdv8JeayBDG96HaWTWJzKMWKDcUhpjM= X-Google-Smtp-Source: AGHT+IFXiOoyqmw7Xh6EuLjaPNmIhMs1ArpEPXr7cCXwinyLyUAQ1cQwwDEcx7Cz+xj6D8q4+onGTQ== X-Received: by 2002:a17:902:9004:b0:1c5:ea60:85c1 with SMTP id a4-20020a170902900400b001c5ea6085c1mr365596plp.12.1695411411279; Fri, 22 Sep 2023 12:36:51 -0700 (PDT) Received: from fedora.. (c-73-170-51-167.hsd1.ca.comcast.net. [73.170.51.167]) by smtp.googlemail.com with ESMTPSA id q16-20020a170902dad000b001c0cb2aa2easm3841833plx.121.2023.09.22.12.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:36:50 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Vishal Moola (Oracle)" Subject: [RFC PATCH 2/2] mm/khugepaged: Remove compound_pagelist Date: Fri, 22 Sep 2023 12:36:39 -0700 Message-Id: <20230922193639.10158-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230922193639.10158-1-vishal.moola@gmail.com> References: <20230922193639.10158-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 922C9A0026 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jfaozyj9jfow6on8ewhtjij7uga8nwsk X-HE-Tag: 1695411412-628185 X-HE-Meta: U2FsdGVkX1+rZ2XE3dvgp9CKw6vZANu8De1qzXy28/9FN/0p+qhcu9bS/2ry66Os3OjDg9MWdWmXPwENV3bonelr+ceTApOJJhLbA8J/CxNEWKVtTJiHilH4h8UuenjkO33ShMdks9fhT9P9vQ/vXNYNF73N07WRgUFtVZnqjuEB31F/uiWgxs3EeN5MqPFOvQQeiCfiM6kHLDS6pwoJfAxeeJHxlZpUSz05iG0omRr8lbvDAiITkE1CKDuRZTi9CcXVEs/76XvOURDh1J/G9NBYBw6zBRyPojP6qL9783Uebh0en5X3KuXZSjHvUOiyr+FHdFRdcsL+wq3noOGX1leudwOCBy21aufOGeo/0EopGHZNFuR/6VlOEbB8Nr96Fi8ruo3Dv0hUC7ziOaj4qDdjHDhEGuyimagQYQzFQ53AJ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tGrUdphFOMeGUreIlTb2siczCSSPSPXFvcXdcDvf3VIofVdsCLbpjRGaqKZG5mkWGrHJ4ZGw7ov1qw7d9P7GpcKZQJ0g== 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: Currently, khugepaged builds a compound_pagelist while scanning, which is used to properly account for compound pages. We can now account for a compound page as a singular folio instead, so remove this list. Large folios are guaranteed to have consecutive ptes and addresses, so once the first pte of a large folio is found skip over the rest. This helps convert khugepaged to use folios. It removes 3 compound_head calls in __collapse_huge_page_copy_succeeded(), and removes 980 bytes of kernel text. Signed-off-by: Vishal Moola (Oracle) --- mm/khugepaged.c | 76 ++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f46a7a7c489f..b6c7d55a8231 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -498,10 +498,9 @@ static void release_pte_page(struct page *page) release_pte_folio(page_folio(page)); } -static void release_pte_pages(pte_t *pte, pte_t *_pte, - struct list_head *compound_pagelist) +static void release_pte_folios(pte_t *pte, pte_t *_pte) { - struct folio *folio, *tmp; + struct folio *folio; while (--_pte >= pte) { pte_t pteval = ptep_get(_pte); @@ -514,12 +513,7 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, continue; folio = pfn_folio(pfn); if (folio_test_large(folio)) - continue; - release_pte_folio(folio); - } - - list_for_each_entry_safe(folio, tmp, compound_pagelist, lru) { - list_del(&folio->lru); + _pte -= folio_nr_pages(folio) - 1; release_pte_folio(folio); } } @@ -538,8 +532,7 @@ static bool is_refcount_suitable(struct page *page) static int __collapse_huge_page_isolate(struct vm_area_struct *vma, unsigned long address, pte_t *pte, - struct collapse_control *cc, - struct list_head *compound_pagelist) + struct collapse_control *cc) { struct folio *folio = NULL; pte_t *_pte; @@ -588,19 +581,6 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, } } - if (folio_test_large(folio)) { - struct folio *f; - - /* - * Check if we have dealt with the compound page - * already - */ - list_for_each_entry(f, compound_pagelist, lru) { - if (folio == f) - goto next; - } - } - /* * We can do it before isolate_lru_page because the * page can't be freed from under us. NOTE: PG_lock @@ -644,9 +624,6 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); - if (folio_test_large(folio)) - list_add_tail(&folio->lru, compound_pagelist); -next: /* * If collapse was initiated by khugepaged, check that there is * enough young pte to justify collapsing the page @@ -660,6 +637,10 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, if (pte_write(pteval)) writable = true; + if (folio_test_large(folio)) { + _pte += folio_nr_pages(folio) - 1; + address += folio_size(folio) - PAGE_SIZE; + } } if (unlikely(!writable)) { @@ -673,7 +654,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, return result; } out: - release_pte_pages(pte, _pte, compound_pagelist); + release_pte_folios(pte, _pte); trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero, referenced, writable, result); return result; @@ -682,11 +663,9 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, static void __collapse_huge_page_copy_succeeded(pte_t *pte, struct vm_area_struct *vma, unsigned long address, - spinlock_t *ptl, - struct list_head *compound_pagelist) + spinlock_t *ptl) { struct page *src_page; - struct page *tmp; pte_t *_pte; pte_t pteval; @@ -706,8 +685,7 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, } } else { src_page = pte_page(pteval); - if (!PageCompound(src_page)) - release_pte_page(src_page); + release_pte_page(src_page); /* * ptl mostly unnecessary, but preempt has to * be disabled to update the per-cpu stats @@ -720,23 +698,12 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, free_page_and_swap_cache(src_page); } } - - list_for_each_entry_safe(src_page, tmp, compound_pagelist, lru) { - list_del(&src_page->lru); - mod_node_page_state(page_pgdat(src_page), - NR_ISOLATED_ANON + page_is_file_lru(src_page), - -compound_nr(src_page)); - unlock_page(src_page); - free_swap_cache(src_page); - putback_lru_page(src_page); - } } static void __collapse_huge_page_copy_failed(pte_t *pte, pmd_t *pmd, pmd_t orig_pmd, - struct vm_area_struct *vma, - struct list_head *compound_pagelist) + struct vm_area_struct *vma) { spinlock_t *pmd_ptl; @@ -753,7 +720,7 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, * Release both raw and compound pages isolated * in __collapse_huge_page_isolate. */ - release_pte_pages(pte, pte + HPAGE_PMD_NR, compound_pagelist); + release_pte_folios(pte, pte + HPAGE_PMD_NR); } /* @@ -769,7 +736,6 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, * @vma: the original raw pages' virtual memory area * @address: starting address to copy * @ptl: lock on raw pages' PTEs - * @compound_pagelist: list that stores compound pages */ static int __collapse_huge_page_copy(pte_t *pte, struct page *page, @@ -777,8 +743,7 @@ static int __collapse_huge_page_copy(pte_t *pte, pmd_t orig_pmd, struct vm_area_struct *vma, unsigned long address, - spinlock_t *ptl, - struct list_head *compound_pagelist) + spinlock_t *ptl) { struct page *src_page; pte_t *_pte; @@ -804,11 +769,9 @@ static int __collapse_huge_page_copy(pte_t *pte, } if (likely(result == SCAN_SUCCEED)) - __collapse_huge_page_copy_succeeded(pte, vma, address, ptl, - compound_pagelist); + __collapse_huge_page_copy_succeeded(pte, vma, address, ptl); else - __collapse_huge_page_copy_failed(pte, pmd, orig_pmd, vma, - compound_pagelist); + __collapse_huge_page_copy_failed(pte, pmd, orig_pmd, vma); return result; } @@ -1081,7 +1044,6 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, int referenced, int unmapped, struct collapse_control *cc) { - LIST_HEAD(compound_pagelist); pmd_t *pmd, _pmd; pte_t *pte; pgtable_t pgtable; @@ -1168,8 +1130,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); if (pte) { - result = __collapse_huge_page_isolate(vma, address, pte, cc, - &compound_pagelist); + result = __collapse_huge_page_isolate(vma, address, pte, cc); spin_unlock(pte_ptl); } else { result = SCAN_PMD_NULL; @@ -1198,8 +1159,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, anon_vma_unlock_write(vma->anon_vma); result = __collapse_huge_page_copy(pte, hpage, pmd, _pmd, - vma, address, pte_ptl, - &compound_pagelist); + vma, address, pte_ptl); pte_unmap(pte); if (unlikely(result != SCAN_SUCCEED)) goto out_up_write;