From patchwork Mon Oct 14 10:24:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13834598 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 A1D82CFC535 for ; Mon, 14 Oct 2024 10:25:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC0D06B0089; Mon, 14 Oct 2024 06:25:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E49426B008A; Mon, 14 Oct 2024 06:25:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEB036B008C; Mon, 14 Oct 2024 06:25:03 -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 AE17F6B0089 for ; Mon, 14 Oct 2024 06:25:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3FB9980CBD for ; Mon, 14 Oct 2024 10:24:56 +0000 (UTC) X-FDA: 82671824760.18.EFF50C1 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 3FA5210000C for ; Mon, 14 Oct 2024 10:24:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="wSkE9N1/"; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728901429; 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:references:dkim-signature; bh=RfYIKH4GciTHGtaGZLfxiERKrYeVVndHxoup3ZNPKks=; b=40HZ/MU12LJdRcYE5TZArP2r/JcSpQazUE4WJPwfhprZ+S509ic3OMrRNNnjYuK2l4jFCv 9JETz8ZmZF1c8LSBgALhVYbRG8mxALyH8M4BZPlPv5APugGLrJND6q2N/B/Y4S6thZ2Jw5 /XO9sNpQM/Bn8hw+27jCQiHUfHA25h8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="wSkE9N1/"; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728901429; a=rsa-sha256; cv=none; b=o48rPpnzRUXavvatAhZtTb9l9L+Qik5OftGOqrnfafu36fMBHuIPWFdO+1of67Ilc2paiv s4Z/qlJXnfsn7SN6f8iWFNqOcrRUmDC13k92TjcDFGxJZkxf0MUz3+sOugbFcNjsivqHbo vzoDbcm/uYaRUe/mVszmMk/ENdZhLFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1728901497; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=RfYIKH4GciTHGtaGZLfxiERKrYeVVndHxoup3ZNPKks=; b=wSkE9N1/YK6lTirQH7xl7+nBwgHMFTFcIGjk1m2yPTDdwQjAn1nRvVMKiWKcZYQRjKUJnbM8RAEarnyLknf6/BWqNriRx0N1mV4fQyAmK3WQHxDvhZxTaJg+GBrdSr6+5c2U+9iyAQWKDxv/jpO1jfLh88FOVU+4TkWa7O1wN9Y= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WH4yvy8_1728901495 cluster:ay36) by smtp.aliyun-inc.com; Mon, 14 Oct 2024 18:24:56 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: khugepaged: fix the incorrect statistics when collapsing large file folios Date: Mon, 14 Oct 2024 18:24:44 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3FA5210000C X-Stat-Signature: rhno3f6nd6jzqnj4t8hsirt6wm7bao6p X-HE-Tag: 1728901492-241070 X-HE-Meta: U2FsdGVkX19c9ggPwtimIJ78qHSq/ENFn76xLCS0RTHZdUfo9KrtVz4Gm3mwq3v1wziZqPOHNjoyYbLvGFY1w6BMT0JzXujGn5OGnb7A05HxF6riDUbGfBYI/GU4tz9Z+ezM0EcWxCEmmuW/6dpI+Ca/T+dct3OzA0sYU3bTb4/GjdvIgzS0b62xgnZTbIEAfq3F58g10feZYEoqS06vSCUt4FxzYi+dP2h4VchJXdGBXrWjfU8VYV8JCBY5PLzQmz24NNfQ3gK6AqjW3hCifPCEAk54Fp99mijvTI2ruw/YtO6hXQu8ToIMVPdHTumtRCzGQv4XTJFh1TRL7w9OzTbB6Du58HEC572M3J/M5p7HhZa7otTfytVP8SzV+LIHr0kGOiXBHdOinuDM5ALSenKfYTk6xlc+g7V/nG2nfWQGgKqcGSi3E1jhNCiNTpnEud5PyVcovvkiNOClZZCC1rvttPuUfnxPQJzb0UO9LD16vbjvaAIti6xMp4zIXujrMByUBzTBfO0fr5aRhOoOQWjB/FFWIOLe4HGyWeitadgN9RI7fFA0R1Qp6duh9bWqS079drTMWP3YRHc8e2Th1bFUe/f2HywHafRnKZOuBYa38BOtShQULY50qIDv4KtqPXm/TYzhfLhmXRWCK8OiDczDLaIgJ10KVRHm4VoSrm7ltyyw2qJpkyIlHcncDjxBYJldx1NL/0Beb2XdWEQD1HcMgd55piFExCKIiel9XpJotrWCnM4JsmypoWQ1dqndGVAw4C0JFZgF51Lj7SPM/b9UliFh9cvZm0UstBFkkE3auFjBLZNVqmZ7TE++rY0/5ojW1l+ga7D0fXzGy4+akkdjGfRP/XqeIDldH0sIc6yGC2EfF0vmtgvtpCUNZ4ALXQ/xwBSxnR8B9QuMrbqG8VUfmxA8qHgsQkdq69hb96h4qTn6CHOGjDp5Rks8Z7tvKja/5A80vPhuI8jANUQ C5kGRLL2 bKNZmJrkg5EokYceb9teXEY7IxRteDFLImLjbQJsXxfyybH6vtG9id9PWx8i3YQpKiOeCTcUCC9CsR/N2UKfMJKkPl+s9geTPWBeMcK+nUhS62irvRBw4iBS3XShNBmGwd0D2633WtUgrOBcuvTIiW7Vo7EeCtTzinzpXpKqpaCkueI+AT6XZbpQNxhmfgd6i4ZECaeN2QBTGzGKmjaBFc//qaDfvAJfWqYq2 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: Khugepaged already supports collapsing file large folios (including shmem mTHP) by commit 7de856ffd007 ("mm: khugepaged: support shmem mTHP collapse"), and the control parameters in khugepaged: 'khugepaged_max_ptes_swap' and 'khugepaged_max_ptes_none', still compare based on PTE granularity to determine whether a file collapse is needed. However, the statistics for 'present' and 'swap' in hpage_collapse_scan_file() do not take into account the large folios, which may lead to incorrect judgments regarding the khugepaged_max_ptes_swap/none parameters, resulting in unnecessary file collapses. To fix this issue, take into account the large folios' statistics for 'present' and 'swap' variables in the hpage_collapse_scan_file(). Fixes: 7de856ffd007 ("mm: khugepaged: support shmem mTHP collapse") Signed-off-by: Baolin Wang Acked-by: David Hildenbrand Reviewed-by: Barry Song Reviewed-by: Yang Shi --- mm/khugepaged.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ba28ba09fe89..6f8d46d107b4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2267,7 +2267,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, continue; if (xa_is_value(folio)) { - ++swap; + swap += 1 << xas_get_order(&xas); if (cc->is_khugepaged && swap > khugepaged_max_ptes_swap) { result = SCAN_EXCEED_SWAP_PTE; @@ -2314,7 +2314,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, * is just too costly... */ - present++; + present += folio_nr_pages(folio); if (need_resched()) { xas_pause(&xas);