From patchwork Mon Aug 19 08:14:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13768057 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 1C060C3DA4A for ; Mon, 19 Aug 2024 08:14:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C21466B0083; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B210E6B0092; 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 9B4216B008A; Mon, 19 Aug 2024 04:14:53 -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 774F46B0083 for ; Mon, 19 Aug 2024 04:14:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E2A4C1056 for ; Mon, 19 Aug 2024 08:14:53 +0000 (UTC) X-FDA: 82468284066.06.0D413A6 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf13.hostedemail.com (Postfix) with ESMTP id DE03320016 for ; Mon, 19 Aug 2024 08:14:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=AsTaN93z; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 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=1724055214; 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=mYH71MdwFDoWK+6jyn77RluPuidTuLdZqV2Iscl7EWk=; b=3rj1NkAFtbAkwr6BgHmN0QE5oSCEqwrte339kzSVtQLTO+pcVTx46veN3gf06yqFTj4DyX KV31lXj5xR8x/VsqnYMiYxDqLbIXZ/yGkBLUUgPtpuoCURih3dF64OTiF6tPeBMV7feqxd /mmD+sPloIAXHJwpkMSPLvvOpwjHtNo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724055214; a=rsa-sha256; cv=none; b=TAyetosNGUw2JEKqy2Aw1P0JyevrSVelo9ljdhUMDtWSbpS2XYuRAmHcl4fa4pvrKW21fV U6ofZIF86RYyJbJFJyxfdUMRsYtOnMG4R2KlN5b84sKhXFsjWL43ORSyWK/tV+lcZr2pxj jeXQqt9VZGLDGvuRxGe2j2gqkMZZfGc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=AsTaN93z; spf=pass (imf13.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724055288; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=mYH71MdwFDoWK+6jyn77RluPuidTuLdZqV2Iscl7EWk=; b=AsTaN93zYybvHAy47unvLcLrxgtIGesYoZoB9oBIpS8vu6HwCaWfFKH3TntpCk8rDAuE3FSC0NGDtLZ5t1CMOMrYbZvOfeQIGa0drX/re7vr51eVHZ6oAEKTMbe66ppLDwgooSLIeUnl9zWupe2Gof/8RPnAuOYZ2Y2cX7c5noE= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WD8W7MM_1724055286) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 16:14:47 +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 2/5] mm: khugepaged: use the number of pages in the folio to check the reference count Date: Mon, 19 Aug 2024 16:14:03 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DE03320016 X-Stat-Signature: hoimp4in1rbdbyx6ncw5oi3a7abnko8x X-HE-Tag: 1724055290-761079 X-HE-Meta: U2FsdGVkX18YT5QKFiwQKDGu504lXMlIrLibZ8Y3HXkM/izyd7zRfGzgOqnM3zUazu1MWUDdlGZ5Yoo7nn7rFD1wi7SeThFKUaKZlVLIYtw14A5y4V+PoN7vst59DN9I61Ae8quKo/jhmIAyAemoWrZr4tdn0j6yOpjyFfAGFeRV9qnnf/YedM04nrhgZavlBZNv8c8i9XxUdUGYqvYyPdGnNTnuXCycHaqdF7KUHIlDGHtnTQ5+PqkBbzDfsRjx8TPNAyouJbEJ1UNsBsP1Om/8v8uUgU56rsiwp4ousvgeENf3w0h0mSLRiue/jWKfigRllH/Qzn8CZTD4cG5MZzDrH9hUcrBNqG8B+JU65u/zERT7ryVGy2jCo+a6LGdfVcAMk/JAuXYM+fwOeCMQ3UK/wujszZuIxfXxGZbU4PzN0nXryP2SV5VOb4QEhLjbPcAJMd3mZO4KR/icYGjZojyCPfzXL86Yc31OR028FCXEeDqYxFgWJTM8MhEoHXaYcerGiV6sP/N/jjlpz8BuB3AwZ9wH/vx+c7bVlCSpKPhY7yBR4IuP5yu0Kfus26xK8gB3+bPgEbvbHR9ir9dBid0GbFgi/t6MlTXzvKngByz3Bv896DMxyn9B238+ns1YoZt/iIUYvSvttqhlH7+FfpXwALEPbAPpM+pUaj+/N04D2XEESh12oLM8VpysTo5NoQ4/p95wdfIKdS7HCtGFTv+gxDOMd1Pu0u4ZvG6yzBy4oix6mnfAwzpJEgs4ZWrWBCm6UzXKA8MNG8Xm4uSn+TEqgUDJvchwEEaqVwa4vOXY/Flye6seVXcd4zT0NEJIpgyBvXsCAB1Ol4LuP3YLBe3artOS5rL54TDlcmmyUygMLytyYwY6C8Z9VVp5fNwvkgc9Oys1kporrdY6lrIPhu3vbyL6GUeL0r8kPONicbD0e5g8ZHeQKwVoGGRYca0mLRo/MfN5DdZE0vevBiS sLQdCsMR 6Tcs8me0AF6dM9YtcUYmLXHXxibWs31py7VdfSOuJ8m/8u4/NVDPJHSTcC5Och7D3IjtaSaMin68biyVFGOVZYu/VjGRxojMsuelSgXZzUR8/UJlFZtnfH1xmqS1pFJrTcFEU0wQ/K7NVqiShxz2BOtglWFo8SReV/1oQaFIWXmWaTguttvw51U6KIOxfnkxidGxthsnc4Qt9ANivHdwjZAjhWT6Us2n9wBC8l8kwn7WWOcQ= 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: Use the number of pages in the folio to check the reference count as preparation for supporting shmem mTHP collapse. Signed-off-by: Baolin Wang Acked-by: David Hildenbrand --- mm/khugepaged.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f11b4f172e61..60d95f08610c 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1994,7 +1994,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, /* * We control three references to the folio: * - we hold a pin on it; - * - one reference from page cache; + * - nr_pages reference from page cache; * - one from lru_isolate_folio; * If those are the only references, then any new usage * of the folio will have to fetch it from the page @@ -2002,7 +2002,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, * truncate, so any new usage will be blocked until we * unlock folio after collapse/during rollback. */ - if (folio_ref_count(folio) != 3) { + if (folio_ref_count(folio) != 2 + folio_nr_pages(folio)) { result = SCAN_PAGE_COUNT; xas_unlock_irq(&xas); folio_putback_lru(folio); @@ -2185,7 +2185,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, folio_clear_active(folio); folio_clear_unevictable(folio); folio_unlock(folio); - folio_put_refs(folio, 3); + folio_put_refs(folio, 2 + folio_nr_pages(folio)); } goto out;