From patchwork Tue Aug 20 09:49:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13769793 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 22243C5320E for ; Tue, 20 Aug 2024 09:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 116026B0092; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09CE16B0095; Tue, 20 Aug 2024 05:49:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E57D66B0096; Tue, 20 Aug 2024 05:49:48 -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 BA5AE6B0092 for ; Tue, 20 Aug 2024 05:49:48 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 66549A199C for ; Tue, 20 Aug 2024 09:49:48 +0000 (UTC) X-FDA: 82472152056.14.69BC8F7 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by imf12.hostedemail.com (Postfix) with ESMTP id 7983540008 for ; Tue, 20 Aug 2024 09:49:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=wJmhRB14; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 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=1724147346; a=rsa-sha256; cv=none; b=Z0lUaiuhx6knR4ooD+NihiOKQnWr85oCJBXTXpAbnb8nzv0uySbnZg6QfFqCbC4edrDkc6 i4svUyCdhkH8Etx3OOjx2OR8m+wsJuPe396nU3rLFmwyCTmDZVLh+LhmDuU4raHoluRqu7 li1C0wy4WcXeJE87nyYiwFWRidZ2b/k= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=wJmhRB14; spf=pass (imf12.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 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=1724147346; 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=NJsMChbPBN7mMZhuJpQhE2p+c0ZuMVKGW4qyVg+x7+o=; b=YtX4VQAxVtpc+xngIvR2SSo2XDzVHqDGDd+XjJTnSAE5H1mUqV/yfbSjIoi09rsrHEYXGE uvFrrIlo7FBV1s/v04bJfC1HBC7vQmu5pk6+Y59CWrN+T9uXHh0d++7qfyOC3gWd6zCYIb VAubWS+dzGpiNqCqu2ZyuYOplKYOrrA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724147382; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=NJsMChbPBN7mMZhuJpQhE2p+c0ZuMVKGW4qyVg+x7+o=; b=wJmhRB14xcARWJwD7SHr9erwUF2rLJNN5/0AWSJAmWPX/vqIw2T38d64wa/ia/F8RslRZXd3UGBdBDF5qY72nUvMQ/+xFNxJgvFNSzFoZm+xvsfQWYOed1uO2S+qRpjluXz+Y4G+YzCs6jmTYedX8BltDhLES7dpI3H1676/Lo4= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WDILeC9_1724147380) by smtp.aliyun-inc.com; Tue, 20 Aug 2024 17:49:41 +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 v2 1/5] mm: khugepaged: expand the is_refcount_suitable() to support file folios Date: Tue, 20 Aug 2024 17:49:13 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 9m9wzr7stz1fiww1xun5zz9c8b6jtr5b X-Rspamd-Queue-Id: 7983540008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724147385-257243 X-HE-Meta: U2FsdGVkX197WIlIeLsDrGjMebNEwLImM3XPrbp2LoVIiSzHXnTJY7icm+QG0otFWSoryQYH+YGRft/i7xx7Ovoe2E75U4Iup5sZplusVAd7k7CGCzcUrXYAHXgLBb4FpJOKxE+Rnky2WjHFC+v7k3/uufvra99KAVIpw5aU4H6hjqNVkM4bhm3uq8kPuHOxzC73edjSGIEAP8kDUQM4+ShOGKUzH8n1BMAojXPJG72dvR2iVnQddmBY94AaqmNsOGH4gaFGgwnrkoJdCtJdQPnQ+Dn8dirHvEv6grKVL2S3jo4ReClCBHWsfMgxXRTCdO6o9WVSEuohKuJrLC0Z/dpvXkfHLJQ5E4+j6cYhGE82zrF1LryqxCCo63ekhMJpHF+IU79dGkkwuDITV9noK3iOySFw1HVTUtU8gEadcuZkP4+hEbK8NiziGBymy26LPArevyxV8yE83QCcdN1p0On+mwaiBKdotl+UIJjKGpxS4eS1SPT99JTk/ROr23YKWNkrD9fQLQYnI8KUwzol8o3wcBp0XZ2bVIZqIJYsrT8OfwMKRULrPZorhKmPeuso91erVOlCAep6qwUsB5LrQ88aKJ79vr81Jqsqt6d9iLceF3uM3tUzHx1ilKznvYLkCnqtrFD1HKxnN9zIpxVyu7UOGjUFa3q/bViYT4tcWwa11XyfTw7VfqQ85+59++UwoMHlDET/AYR7Evfxq1LsiJ68EOADWB9aVhIgOprrTzD5pYsTV+uxZ8g2yu9rsEnVyL8DuRb4QOmggUkwoaeRzIrllYT8QP7HLm1HWRirVSOoF+Yu7GpX7j7AE0K0j6hO0wtW7pKbK93g9onQnYClmObOgatsMrsBxQpUt69AyEoz0lOsy73a0CegdpBxtJ7e5vG22qxCkbyf906ONpSb+CYL7omjAGC9IrCaAfcTcSMy+9Nbz7822svefEoY8UT/fQNr88eA/8KmMwvYX8i GZajWPgx AYK5GRmT2+IkE6jOMYDuFzx3BbTzlu4hFcDRfZNCJ/oa9fj6xru7rB24EzeYy9h7vZJePdG2JvyDTHP24rdmzczinK9DzpnxfIedh2uOHBzWcRbyaSovmSGQPI6sZb9TWU4WtTEfIO9YpH0bCFExg8X4cwL1msleGUVwPquMuuFWwbz8RT2x8m3iAwJ06ACu3EImz99NHhJsu6KBdMZBQ9fWMzo4zU4J1RIsIVLo4VLV5E4NHI6ENRsZcyQ== 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 Acked-by: David Hildenbrand --- mm/khugepaged.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index cdd1d8655a76..76f05215ee87 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -546,12 +546,14 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, static bool is_refcount_suitable(struct folio *folio) { - int expected_refcount; + int expected_refcount = folio_mapcount(folio); - expected_refcount = folio_mapcount(folio); - if (folio_test_swapcache(folio)) + if (!folio_test_anon(folio) || folio_test_swapcache(folio)) expected_refcount += folio_nr_pages(folio); + if (folio_test_private(folio)) + expected_refcount++; + return folio_ref_count(folio) == expected_refcount; } @@ -2285,8 +2287,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; }