From patchwork Wed Oct 18 20:32:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13427840 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 9F92BCDB483 for ; Wed, 18 Oct 2023 20:33:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06BD980019; Wed, 18 Oct 2023 16:33:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F38198D0016; Wed, 18 Oct 2023 16:33:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3B9080019; Wed, 18 Oct 2023 16:33:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BFEDD8D0016 for ; Wed, 18 Oct 2023 16:33:10 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7A88140527 for ; Wed, 18 Oct 2023 20:33:10 +0000 (UTC) X-FDA: 81359731740.28.30B3941 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf25.hostedemail.com (Postfix) with ESMTP id 6F966A000E for ; Wed, 18 Oct 2023 20:33:08 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Jc/i759g"; spf=pass (imf25.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697661188; 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=VN0zp0snARiXWQz31GgzZoIBHJFk7ynRrvZrhH9BDQE=; b=Lv0HmBzCXjGESbbhRY5OINN42Rt/VTdezSY6YDesxJzhz+LFvPAUNg2Eiwmw4JyenfuzJB 81Uk4waX1FYrJHOlYr8GkT5W0pUsfaOwfd5vKC2325ZZO/3TZq+TQAGfWvPVr8+aDuSAdN JJ2QDW1zStIq4czUkt9Cmcju+LuEvN8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697661188; a=rsa-sha256; cv=none; b=vma5xMdsXIXDmDpfUNb+06iq6fUs4IlP7/ry+gWNAt7rrJvngbXcZBzEHlYxYHXFqKF35J Wkhb/VX4YfIT7oqyHSQ2Pf41aLRWJX6GyIhuirIvorLj702Djd9HILU2xchHEP1Eib9KAo g40xwyhakC+DGmHFYzFM1B4r1rrChc4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Jc/i759g"; spf=pass (imf25.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5ad5178d1bfso4044861a12.2 for ; Wed, 18 Oct 2023 13:33:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697661187; x=1698265987; 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=VN0zp0snARiXWQz31GgzZoIBHJFk7ynRrvZrhH9BDQE=; b=Jc/i759gjoJZcIy9K00tPPGX2kUaHWfNvMwQb/YIWjPg5ER/02tbIqB5dawo8s+i+/ /ZzFfyWmxMU6Toa3seEFRtznJkMFBTirNwnk4wrvYgU7apCvYi55e0UPXZSllv9Gmmsq eeLKS2yHLbomR/wkr/H4JNX1wEg/Yy8N3/lesorKxikUpHBdaCGUIbNGliCHxolBiWPM ya0V78zyrvCUrl/AOzZx/D4kXAgzW1gRO0Uk1bFoJVzlLFhSxYmEbZkmG832Hqtg+WH3 E1FmJGjIYuSWiJ5ks5pL+o3vroQHzou4kk/kkoQD08HWdbysEAb5gSBKJeAevJIBeFag p0hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697661187; x=1698265987; 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=VN0zp0snARiXWQz31GgzZoIBHJFk7ynRrvZrhH9BDQE=; b=QE1j9YFIVGPENpxdTzwG8iwsmhoPFJtHtpdayXYEw0oCg4nqhfjAB2xdS5maDax8Zn YCJh1jai5t65/XtvzmQGoEp2vrClo2ticJeVWEQKA6b3mVgU3P/jjIcqw7lyP0aWclhV 7dBcTndsV2XgKEQFsFRZ3YnEkKSV8lmL3Y/bfQexsZK+3tK1NiTsMB/kBQ4XwtWK56nx apafx5nd6gg3VRXpnAAKqQAkcPAzcMkV6B85nvwzfsu2Ol2JE3X21kRfIA1vnX8OK1UY 7LZ+RNntc1QrkPFn3UW2l5CUhjvmm5spRqZiXwCZdAuPAscf9dwKavCJCYA/YiWgwhVJ D94w== X-Gm-Message-State: AOJu0YxfUFXZFu1SG21d4/WFXpF93LlhefIZC+BuA51jipGlgmhXU9V2 ciF1l4YMiwkK8U+SVSQlgVLrrD+c+5E= X-Google-Smtp-Source: AGHT+IE6UrwDxrBBS7hjFHieWc31jxdejoBL6wMFdYPOtBiCq+4eALL+xiIct2VZuc3ylwqsKZTYgw== X-Received: by 2002:a05:6a21:6da0:b0:14c:d494:77c5 with SMTP id wl32-20020a056a216da000b0014cd49477c5mr307966pzb.13.1697661187061; Wed, 18 Oct 2023 13:33:07 -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 w12-20020a170902d3cc00b001c61e628e9dsm354412plb.77.2023.10.18.13.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:33:06 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, shy828301@gmail.com, "Vishal Moola (Oracle)" , Matthew Wilcox Subject: [PATCH v2 1/5] mm/khugepaged: Convert __collapse_huge_page_isolate() to use folios Date: Wed, 18 Oct 2023 13:32:09 -0700 Message-Id: <20231018203213.50224-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231018203213.50224-1-vishal.moola@gmail.com> References: <20231018203213.50224-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Stat-Signature: oeepbi58erywxybhkcck4gm38hahr7to X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6F966A000E X-Rspam-User: X-HE-Tag: 1697661188-73539 X-HE-Meta: U2FsdGVkX1/FXG6HUQ5/uT2WiSKXFkz/H7/wIkdgL3L7blSws0L6ne/CGENL+E6lo1GS4+4jQNqoubRooQLdpxKwaOquGtQANXuUmBeS3D5Hxjvhmq/fhUvw/3CzGjH5FJ+WkDwVg/EUGcGlShdhyCmR/CAkArgfKoHZDER2gfWLG0SS52cL46N+tt5BtKvABVzAhUro6u25s1AKbo6tRdO/NAzzIG83+1RsRA4oWUooVPLDsdf6ij0AXvhjHatfJiR+VBIBfj6rmuQUZT/48f7930YLTy15lq7oSjpYnOrHO1bL/djlLpfrNATsgSozsfLHPd/1nyynHCqCVuJlyleU0sudiWA1XwQfNCLx4N2LVRmI2wn7nx8eah9gxAWw2D3eXeKUCs9F6fj//t2Tmqg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3uLd4//vItMHn8GqBirWv4GoCPIJgfCW6mu+jtj1t9XUrAqrCjwU8/w0mm4nCOIASrnwh27683Gqo9mtCgjQUKw01dHMdKqj85YEVNAglcPaFHB8N8F67cS85nHEX3f3eyXzZKInN7Hrq6PZsXf3vSvRt9A3vSyNDrIJ7Cpr+2Eg== 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: Replaces 11 calls to compound_head() with 1, and removes 1348 bytes of kernel text. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/khugepaged.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 88433cc25d8a..500756604488 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -542,6 +542,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, 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; @@ -576,7 +577,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, goto out; } - VM_BUG_ON_PAGE(!PageAnon(page), page); + folio = page_folio(page); + VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); if (page_mapcount(page) > 1) { ++shared; @@ -588,16 +590,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 +609,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 +625,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,27 +635,27 @@ 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++; @@ -668,13 +669,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; }