From patchwork Fri Sep 22 19:36:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13396370 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 5AEE1E8180C for ; Fri, 22 Sep 2023 19:36:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3E356B02FD; Fri, 22 Sep 2023 15:36:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC7076B0305; Fri, 22 Sep 2023 15:36:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCABB6B0307; Fri, 22 Sep 2023 15:36:53 -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 A82D96B02FD for ; Fri, 22 Sep 2023 15:36:53 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 82A491CAF46 for ; Fri, 22 Sep 2023 19:36:53 +0000 (UTC) X-FDA: 81265241106.15.A99017B Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf16.hostedemail.com (Postfix) with ESMTP id AE545180017 for ; Fri, 22 Sep 2023 19:36:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="XJ/lfBsB"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.171 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=1695411411; 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=tNVby2wunRWEn0qOBvwSo9+1ZckN5VFf0mdscjhq8sg=; b=yXzAjU1YaF2Zbhn4CQjOwJkbPJ0+AbRc3P5vDX0xPCA3u/AFGDAwQKKJExCPXFpmyz09Bs EXl9DrIA+Rmf69i+GFkJFz6kd/tzEYgO/8UbT4oQO+/IBrVrO2i97eDyJ38qjprvpSmy3h Zdl0mI6go49FHrbaSw4ouYcL41jStC4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="XJ/lfBsB"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695411411; a=rsa-sha256; cv=none; b=j5x4pmTszERUirlsOptSm6TJqM8I8Vw5rVl1HIeQ7WhFBKBfXpaU2XUBtW+kIKDNcFpS8d B7nggEUPK35sULEeGAyHJCpP3A6A+U0YX8sPk9pv3eiBl4z35Bvr+eJxU/DnE2XW0m9/MM q8bU08EPAaTOUPJyLP6jyGBQdVeXjEA= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1c5db4925f9so19194685ad.1 for ; Fri, 22 Sep 2023 12:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695411410; x=1696016210; 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=tNVby2wunRWEn0qOBvwSo9+1ZckN5VFf0mdscjhq8sg=; b=XJ/lfBsBt0chkgC2bzun8xdzx3BMOFagAs7MHPqmqfRWOGOugzy5mGqpq9AtYV6mtA wUr7YOuZH/2DtTp1JUbbwX9nGL16lNe3RLiQT6Sp6RMRQUEYvoMjaTLvNzXcPS7+qMQO JkRffPz0BMvBJpRnoY7fOnjzQcWuYVnumMjaTEEtjQoaq2LUBmhgLlWhn+YvcRzHqVF9 zDMUbrY9OUp3ngri0lOb1/8IfSMPQfvs4SCE9pIuNvrySvbRPxkCLPcIpqiJFE0FdIwv iSiuiZVfSVQhjO4vslFyvjCoYcQUhx03c+x0P9UP14o7Zk4AOCxFN4KTfpz6lxv3YL/B 8oOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695411410; x=1696016210; 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=tNVby2wunRWEn0qOBvwSo9+1ZckN5VFf0mdscjhq8sg=; b=NTXmQ/QXigAtvBrwBN25+yxqkuO8fb7sMq1cJw9Z0OoLitIaLDuOTPgKFcryUBiiCm M7kxkRrUu29ri9MLIdoEGNEI7WaCCs2Y+wXB+iY/QEO9sX01svLwt00pJ3ipqrH3R8Qj R2NEb72ku3sUqmrE+tK1vGhg9HN2KAY8bFeZUW0gMzpuWstTkHlzYZbVHN5gM+P3pA6O P31OrE6L0N280FJNah8Jo/N2gsG8WxbRAjp173c5DDsrrvrse7NiOVO8VqxDy8xH8YFt wtMjjmwQfNFMLEXODvQ/NLciCN17AYLE92h+h44SysyTEQW8OlagClFEOe0ZCEkSY5PA e/TQ== X-Gm-Message-State: AOJu0Yy4spj7I+2Mo0CvSQL9f+BkbpKhuDXHwASg5Ud3vjjz3SXx0CT+ P4g9J2oD41/XkSEroA/F+tQvPHQeIE8= X-Google-Smtp-Source: AGHT+IGcVd17kQbCASxBJAiH40hBMFyzCh+Dp7Xr+380ebvaazbf0iRs5Z0HFn9TFwM6Y5hNVP2tfQ== X-Received: by 2002:a17:903:18d:b0:1bd:d510:78fb with SMTP id z13-20020a170903018d00b001bdd51078fbmr5245132plg.3.1695411410275; Fri, 22 Sep 2023 12:36:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:36:49 -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 1/2] mm/khugepaged: Convert __collapse_huge_page_isolate() to use folios Date: Fri, 22 Sep 2023 12:36:38 -0700 Message-Id: <20230922193639.10158-2-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: AE545180017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: ei5s8fg96sp1r6kfojw6aqsrw9bc13jy X-HE-Tag: 1695411411-320375 X-HE-Meta: U2FsdGVkX18A3lE4724/brAPW15kUJwlbEtAOoR6UuFUsVNtsxiHC4nkT2rxVvFuwmwYRcCObeo+rRKvrxsWRNgA0Smm0j3ocWitlJ7/BdP150J8SLIgjPLniunNUYgS6UuJViBCsDMl/MOuHSSyudwMZP1SFrz7sqnpU6oH1HksBImACCKj73kZQPCe7VRqKRzleL7jQmmxE8ZIpN0/m6R6FkVxnG0021EVBpK10zzqpk0eZEG99JvfVZ63aa2dzk/1Mpq9/yf1F+jgeolqKuBOlbXj8GvheoahybaHsJdAkI3NS1JJ449KTClAeOv3VkBS8V1mkUCN81iWs7HFyJKEnpIV5DteVVCTEZm7Vh26Iq5QQTe1V73Jd755pSIHLfbb+RWfNWd5ht7xN4K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sQQ== 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: This is in preparation for the removal of the khugepaged compound_pagelist. Replaces 11 calls to compound_head() with 1, and removes 499 bytes of kernel text. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/khugepaged.c | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 88433cc25d8a..f46a7a7c489f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -541,7 +541,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, struct collapse_control *cc, struct list_head *compound_pagelist) { - struct page *page = NULL; + struct folio *folio = NULL; pte_t *_pte; int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; bool writable = false; @@ -570,15 +570,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, result = SCAN_PTE_UFFD_WP; goto out; } - page = vm_normal_page(vma, address, pteval); - if (unlikely(!page) || unlikely(is_zone_device_page(page))) { + folio = vm_normal_folio(vma, address, pteval); + if (unlikely(!folio) || unlikely(folio_is_zone_device(folio))) { result = SCAN_PAGE_NULL; goto out; } - VM_BUG_ON_PAGE(!PageAnon(page), page); + VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); - if (page_mapcount(page) > 1) { + if (folio_estimated_sharers(folio) > 1) { ++shared; if (cc->is_khugepaged && shared > khugepaged_max_ptes_shared) { @@ -588,16 +588,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, } } - if (PageCompound(page)) { - struct page *p; - page = compound_head(page); + if (folio_test_large(folio)) { + struct folio *f; /* * Check if we have dealt with the compound page * already */ - list_for_each_entry(p, compound_pagelist, lru) { - if (page == p) + list_for_each_entry(f, compound_pagelist, lru) { + if (folio == f) goto next; } } @@ -608,7 +607,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * is needed to serialize against split_huge_page * when invoked from the VM. */ - if (!trylock_page(page)) { + if (!folio_trylock(folio)) { result = SCAN_PAGE_LOCK; goto out; } @@ -624,8 +623,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * but not from this process. The other process cannot write to * the page, only trigger CoW. */ - if (!is_refcount_suitable(page)) { - unlock_page(page); + if (!is_refcount_suitable(&folio->page)) { + folio_unlock(folio); result = SCAN_PAGE_COUNT; goto out; } @@ -634,32 +633,33 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * Isolate the page to avoid collapsing an hugepage * currently in use by the VM. */ - if (!isolate_lru_page(page)) { - unlock_page(page); + if (!folio_isolate_lru(folio)) { + folio_unlock(folio); result = SCAN_DEL_PAGE_LRU; goto out; } - mod_node_page_state(page_pgdat(page), - NR_ISOLATED_ANON + page_is_file_lru(page), - compound_nr(page)); - VM_BUG_ON_PAGE(!PageLocked(page), page); - VM_BUG_ON_PAGE(PageLRU(page), page); + node_stat_mod_folio(folio, + NR_ISOLATED_ANON + folio_is_file_lru(folio), + folio_nr_pages(folio)); + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); - if (PageCompound(page)) - list_add_tail(&page->lru, compound_pagelist); + 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 */ if (cc->is_khugepaged && - (pte_young(pteval) || page_is_young(page) || - PageReferenced(page) || mmu_notifier_test_young(vma->vm_mm, + (pte_young(pteval) || folio_test_young(folio) || + folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm, address))) referenced++; if (pte_write(pteval)) writable = true; + } if (unlikely(!writable)) { @@ -668,13 +668,13 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, result = SCAN_LACK_REFERENCED_PAGE; } else { result = SCAN_SUCCEED; - trace_mm_collapse_huge_page_isolate(page, none_or_zero, + trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero, referenced, writable, result); return result; } out: release_pte_pages(pte, _pte, compound_pagelist); - trace_mm_collapse_huge_page_isolate(page, none_or_zero, + trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero, referenced, writable, result); return result; }