From patchwork Mon Aug 19 08:14:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13768056 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 DB2B6C5320E for ; Mon, 19 Aug 2024 08:14:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B6B56B0093; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93E3A6B008C; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DE1F6B0092; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5AD176B008A for ; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 05B6441060 for ; Mon, 19 Aug 2024 08:14:53 +0000 (UTC) X-FDA: 82468284066.10.F3EE162 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf29.hostedemail.com (Postfix) with ESMTP id 9708C120018 for ; Mon, 19 Aug 2024 08:14:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="Acp9cb/D"; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1724055276; 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=wXFLqHbVSHxFKCZqqifJmzb9vdz6whYXmBhNU0imZD0=; b=CrzWnvSTFma4JFQit/rCYzoMYXi3M6ur4kQ/vGGi5pGdfu1WnyouTXI7FeEEvxfNTRarxv 9YI1YbKWqA7jMBpmPZ3u4194v2tSI+0CAXa794v8h1E9kHy2LCSho3LHnHLzJkNiJdOH44 RykR5OULj+EuV847HtAz8yCA/0PtkUU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b="Acp9cb/D"; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 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=1724055276; a=rsa-sha256; cv=none; b=Ev9PFwK4oDghpuB+KHVeJegPMx6JHKcqzaDblNAAMxQGvZSn+RFKSDVTQjk3bA2eTSpEqA gS4Czagdbt9Wuq0HRNUKHe7N+CE8yjC5oncQEhZgWoEYHxIiQQ6Axw6/igdUuSHqvHnXj+ uKwoElAJTFCEwnEEwWW8XIZbGBH6pZM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724055286; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=wXFLqHbVSHxFKCZqqifJmzb9vdz6whYXmBhNU0imZD0=; b=Acp9cb/DupVdSrhmtniMMNOLRLSPf+tSK5diilQexTp3OG0WHtJP4plCBcbvWXNNrM3oZCgEsPEzHUvZJU5Q309IXP02+C7IO0sKc/Vd70KZtfipB86kabQGLmtesDMvceYXA8tjZKoJp9VXFu/H5+f+C8S7/+7qlvGUJttNaxc= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WD8W7Ls_1724055285) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 16:14:46 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: hughd@google.com, 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 1/5] mm: khugepaged: expand the is_refcount_suitable() to support file folios Date: Mon, 19 Aug 2024 16:14:02 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: qhenr1hwusszau5mhw7sgm9fjraddwjp X-Rspamd-Queue-Id: 9708C120018 X-Rspamd-Server: rspam11 X-HE-Tag: 1724055290-894937 X-HE-Meta: U2FsdGVkX19bczBeOEUR90xeXWUzah4mMjIbelywzVx4HiLenxoGgngaETlc9qhXkmmPsZdBFX6Q9EpbZuPCmmn9llWHkLrpM7j71rW2wQ269vrE3p/zlYMsHYLzZyCbl6s4RgxF5aq7m1nSmVkzME5Mf2oIz0L6uNoRsAvGRCDel3wms0r5nct87Ipzqwj3+D534ANUegpG2j9yXjtjEwNWQpJ5+cQLPNv1Jg/iyS4nXeaMBXca8ZXeMatKKKNVNqyHYKrxARU5I1TQAf6dXvGytwCibZ5D+TRRAL3a6gh5I5x5OGbRbFZ7GLKDPOyGxINOxX8npiQGMdwi77Ccq103NH/3iCYXcxzpUP/d9qOR+27K+CFNq0HGLRIjqNko63pkW6XYDA7dK3wsvaerA5B80DZURqzhiwPieOhzua5y93GVm85nLE6RbYi6feLowXh297tVYU5gpFFsbg7gLh9HkgGEXDeKcRkEzUwLajMdDLPnfN9SR9M35AsWW8MYtnfWsl9ziSqnrwio5ZlgOVC9t7EhT59A/mt1A02zjtYV8671uXhIUkFahYkBgiH5uKHVe2WbK+Zo+kFdI4QjVPGg5xDAi8NSqEbJOm7Jn11fmYyDIyx0RXgGtkOoQAuRSX7EObgsCPIs9H5pdHZ88o5WsR1+U1qFgj4ctYzwFZenoPpPC2C6LNQxcfdCvoct1ODFpfV1WJFz+Y6VodIqfSqdkVfDKS72qvZ7LJANau9toI0SeORCG/mc9jJd7FtgjCLBSjhQINikFlPgDkrOpBbh1U27HBrAIku2DllPsvlTzd9SCZ8m7njVPlUGcZlaglZhix8Sa1kuRR95s6VMicGGvSjxl2whMGJmGLUiNSqsldSF6PMUFcc4iWgsx9D///j6GGkvncgTk8NmbLd7MKVaq6C74q/+AJ+6i9MLUD8QepPAu9YM2kn0k6sYDWVSGP6gK/aPgJb3dai3AvO Lo5XgCc4 0ZtS7DiunVm0PJyI5kTuv09/0fqDKq5P2HgHgV2qQ7H2fwbkqGjj2NhO/sxinaA1RK02BGF/DmW8tRlZp1azLtWXG3e9MZ7MBfaWqy13UzcPKQ+dtIKjVttNQcWV/cANxh3F6R9SB41GSwQ31WBa4bCI5XWHw5jqD8HdTJxsZdwB1NBJag8D8QcW8NMstSG8cDuFn+APNOpzf5mqhk8pTge8BdJ/SwYmxGkDCQpj3v26jzLpiqQ7C4V/YREIitzu8YuYoBHghgE8REjfRtgF2wA+eyqUwUtTv58/dPeKPECDFVDQ= 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: Expand the is_refcount_suitable() to support reference checks for file folios, as preparation for supporting shmem mTHP collapse. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index cdd1d8655a76..f11b4f172e61 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -549,8 +549,14 @@ static bool is_refcount_suitable(struct folio *folio) int expected_refcount; expected_refcount = folio_mapcount(folio); - if (folio_test_swapcache(folio)) + if (folio_test_anon(folio)) { + expected_refcount += folio_test_swapcache(folio) ? + folio_nr_pages(folio) : 0; + } else { expected_refcount += folio_nr_pages(folio); + if (folio_test_private(folio)) + expected_refcount++; + } return folio_ref_count(folio) == expected_refcount; } @@ -2285,8 +2291,7 @@ static int hpage_collapse_scan_file(struct mm_struct *mm, unsigned long addr, break; } - if (folio_ref_count(folio) != - 1 + folio_mapcount(folio) + folio_test_private(folio)) { + if (!is_refcount_suitable(folio)) { result = SCAN_PAGE_COUNT; break; }