From patchwork Sat Feb 17 02:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13561207 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 6A201C48BEF for ; Sat, 17 Feb 2024 02:26:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33D006B009B; Fri, 16 Feb 2024 21:25:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B566B00A0; Fri, 16 Feb 2024 21:25:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7007C6B009D; Fri, 16 Feb 2024 21:25:54 -0500 (EST) 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 359E26B009B for ; Fri, 16 Feb 2024 21:25:54 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0E8334014A for ; Sat, 17 Feb 2024 02:25:54 +0000 (UTC) X-FDA: 81799705428.11.1C5BA15 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id 6551FC0005 for ; Sat, 17 Feb 2024 02:25:51 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VJ0aIzZp; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708136751; 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=o3omPoxMLsk94BWO3XT1KRKpFrR6WgQB/H8HRcd+FzA=; b=KeO1SKTj+HtzZi3SroKDlTwEo3IPm2gXOpqUme1UYRjb0fJLYwbPl2CECsnnKbq3Wl85dA HfOIIQbg0em+GsVDKAu3Fv0CIV4FzdToYBKF43Jv8acFaeb8iSuWKrWXijeJPB61ouoYdi grpxtRKDWR9z1+g8pKxMR1sxkFRmIAM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708136751; a=rsa-sha256; cv=none; b=28bLqYpEvcnVmCbibZ1X3EUjIh7W9AndFSpC76h5yLyXnRO2DkoiZApvMn7/F+0A0xI3xg 3xRnXTzAFCdx7LjxsPj+ZFKgfzcXn3vKSgxq0ODYYl0D0ETfkQ7We5zME+xB0/EIrNXXyj DRlbV+19+tHxPiLMZdpoCbmlk/CdnmY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VJ0aIzZp; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=o3omPoxMLsk94BWO3XT1KRKpFrR6WgQB/H8HRcd+FzA=; b=VJ0aIzZpZYScSdiK1VA91ch2kK qgM6xBppoz7JwAnhOg7N2GpvgrnlKGIy+31R/uX9swaexH57A3L5qlKyO4iXpbFuys0kstjBI3IjP tB8CsONFpWCktgvql9jFRRENltvdUr3LDeUgZi/XZ8wUhbDIUR0q6xjnMxyWRTWbxleU3uRArfIit 21reC5P56+j91tkX1HWaCXACt/kXeLqPw6YWe3qnI2q7KmPsn8KBBKB2EbjN3Jmh/l/JA/UDtjAjf B2rITmRlLXT56B2QhBKwCKMpAcmXGY54+hdjsJiDu488KqsgcSu4ycguUGBQ5An4imZY2LaA6G9iA gUblaoEQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbAOj-00000006HEJ-4ATV; Sat, 17 Feb 2024 02:25:50 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 17/18] mm: Use a folio in __collapse_huge_page_copy_succeeded() Date: Sat, 17 Feb 2024 02:25:43 +0000 Message-ID: <20240217022546.1496101-18-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240217022546.1496101-1-willy@infradead.org> References: <20240217022546.1496101-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: jcu15b46u3ebr38dfp5cm8kuze5fg8p9 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6551FC0005 X-Rspam-User: X-HE-Tag: 1708136751-146579 X-HE-Meta: U2FsdGVkX19shWxub8GqZj16bf0VZa3fbNaT5o/ldd3UOanuvSDEeXq4vFStj62oNXEcIXaoH6e7dY4EiBlZc8YIwYmhbcwUl4S7Tb53d9l7LErlLpTVKK8EEGAOMjC3glHoDefEgPCumXoGoZbIX/jZ0GixQwF9sqBvRgUSRlsAc6srTKbnEN2aAKwhMWnM39YrLKQoeOATIPGrA7IX/k+zOkM7LfLs5CU+pekPXiJlqW/WgicT8EO8gd2Vra4ipqOgPmyx73WVhIHyWsSCftnGURFaLtoo0MA4T2VpKXxIwUgbszjPMt1dC4MxlHflGVOL1Z26sRxCvAIeZiVUe+IlGkuC3Pqs7Oy5ZrOx5iNSqczwmkOQ5fXvRM05x8FuyNd2J+2ieSJ0q/RgofRMZJJHP1SkEQpmKdgyI56meSY40dRh0S8ni7SRB0sjOG8JlW/6u33VRY7VGQXrZPet7ApwM96OWtbF5JHqAAQiL6qORxSeUzCla6IHaDwo/K0d+EMv/9W36MWtEjjH1S2zZCQRa7tqLqWfNFJBVN5qnOkzDlXESOETXF7Dm2X+g88yooDoF9MdF/LNsyNuGk452576iq7ETLcgAxxGTLNl3AQWbxIkB7ZutAAzqN0X7ruelOa9C9s+rNl3CjzsDLcZ5CxjYWJhXCu5c1xYVuaY0uzx4Zw/Y99GGpmGxhBIMfWYCecC9PCu8JxT8So/409d5yBZFGlWldE/Vib6mfiEDdxpqdN18B/HetJkclhKJKFMSnSSC99RaKTZtuvRTXwfw4sz8wKkGlJQ9Fc9Z2NTJpPvexp/RBsx39TqEvSMqpqjfvX0hamtcB5zLj808ppSi7HZR/wM9uKVxzXqPztN4s0aFd/RSR4vziXMot1K/TmsKmM9JkoM7HA3C7B2MAVxm5rdkke+Q1Ad1jAqienBnC3jRmHkOlANdkwsEJNG6VC/2PuGaECSUcKKek0qRlw nn84wOOw eBqk9EHBgHXxAHIHWGFZhiZY1xGGx7zdE5pVm7Squmm+DkpDbP+AzVoypYPXN9WXyngeUCm/3R70guVOqN0mSs3PPHi8ZE1XVh9Rmhr9soohxAQ1f9hW3DVo6DN1MjGDH7OrwAsn5cQhcSOQL1UY76H/sEW1TsMnJv+4soYpZG+F0Xku+EhmQ8GaA+0Po0tnzXEPd/pwim9b6f47kdbXgxfOfCTOu3HIHnmOB 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: List-Subscribe: List-Unsubscribe: These pages are all chained together through the lru list, so we know they're folios. Use the folio APIs to save three hidden calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/khugepaged.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 2771fc043b3b..5cc39c3f3847 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -689,9 +689,7 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, spinlock_t *ptl, struct list_head *compound_pagelist) { - struct folio *src_folio; - struct page *src_page; - struct page *tmp; + struct folio *src, *tmp; pte_t *_pte; pte_t pteval; @@ -710,10 +708,11 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, ksm_might_unmap_zero_page(vma->vm_mm, pteval); } } else { - src_page = pte_page(pteval); - src_folio = page_folio(src_page); - if (!folio_test_large(src_folio)) - release_pte_folio(src_folio); + struct page *src_page = pte_page(pteval); + + src = page_folio(src_page); + if (!folio_test_large(src)) + release_pte_folio(src); /* * ptl mostly unnecessary, but preempt has to * be disabled to update the per-cpu stats @@ -721,20 +720,19 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, */ spin_lock(ptl); ptep_clear(vma->vm_mm, address, _pte); - folio_remove_rmap_pte(src_folio, src_page, vma); + folio_remove_rmap_pte(src, src_page, vma); spin_unlock(ptl); 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); + list_for_each_entry_safe(src, tmp, compound_pagelist, lru) { + list_del(&src->lru); + node_stat_sub_folio(src, NR_ISOLATED_ANON + + folio_is_file_lru(src)); + folio_unlock(src); + free_swap_cache(&src->page); + folio_putback_lru(src); } }