From mboxrd@z Thu Jan 1 00:00:00 1970 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 C1A9DC3DA4A for ; Mon, 19 Aug 2024 10:05:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30A1D6B0082; Mon, 19 Aug 2024 06:05:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B8B96B0083; Mon, 19 Aug 2024 06:05:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8596B0088; Mon, 19 Aug 2024 06:05:11 -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 019496B0082 for ; Mon, 19 Aug 2024 06:05:10 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9FCB941109 for ; Mon, 19 Aug 2024 10:05:10 +0000 (UTC) X-FDA: 82468561980.27.4594409 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 A3D20100026 for ; Mon, 19 Aug 2024 10:05:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=iWu3Lnso; dmarc=pass (policy=none) header.from=linux.alibaba.com; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724061822; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MCjqsG6JtfvWAirwZ/LCpeLTqCVtGz+HtJHJeKy+33A=; b=S8NKp9xHo3JQytFHrzeXwCJsYGZQ1IERUgv+zmA7d2R/0Q4UVdM2x9dLLAVmUStmAINkOm L1FmaW8ja0gu2iBrbas9jJcA637jo4Irxp6LR17b4xpSvtWnY+JXSi4YUeEgyoeoIIbGsy q89mhd/8rIhDCRjJ3Ry3NVRDa3NIlhE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724061822; a=rsa-sha256; cv=none; b=hlXy7y9rGlv5PCfF24PbMTWbOJ0K6SaaFAKxxnSQbAAGB9f6oHNQl3kEdmHV0n/WCqunTv 5SIlWct2fYkXZmcCNj89An/aqxcdnlODs6Le9gtpANYfi1xBFXteIi39yY7QA37jDNclQQ 6NjgYeeJLY7s68gCp2EpQ+SZF6Owh38= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=iWu3Lnso; dmarc=pass (policy=none) header.from=linux.alibaba.com; 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 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1724061903; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=MCjqsG6JtfvWAirwZ/LCpeLTqCVtGz+HtJHJeKy+33A=; b=iWu3LnsoqLTo0fiTnZZsJkpAJvqLNyfMgpi0fzappdoKR/F+aGiC4XI18Pk0Ht02gI8oObhgT+sxrmN9UxNMd+H7OpMyjlhD41n342cyDqQupUkIIvs9ZsuMWluG4G6nYJZ9cgRkrEBYzsnIuN+vZtG5N7KO3EiAHXNXuWMagTk= Received: from 30.97.56.67(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WDA.YfX_1724061901) by smtp.aliyun-inc.com; Mon, 19 Aug 2024 18:05:02 +0800 Message-ID: <3802c50b-325e-491f-9f8d-8ab309121935@linux.alibaba.com> Date: Mon, 19 Aug 2024 18:05:01 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] mm: khugepaged: use the number of pages in the folio to check the reference count To: David Hildenbrand , akpm@linux-foundation.org Cc: hughd@google.com, willy@infradead.org, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <966bfe10-6123-48db-95b7-ade2f794700d@redhat.com> From: Baolin Wang In-Reply-To: <966bfe10-6123-48db-95b7-ade2f794700d@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A3D20100026 X-Stat-Signature: wjctuprs8pk5r4wxcb68q849ese99cre X-Rspam-User: X-HE-Tag: 1724061906-741155 X-HE-Meta: U2FsdGVkX18aGqNHOHo7cS5G7y/hBbFadut5RayF6HmDYr7sfnUgem14I2LImaZgxw1zoueXWgCcEue6nuVD8YHxLJv0TZoaoQa4eSBs22dDhyybEToM1UXyonycYiWpGJTKOUOOyzClJhbQm+xk5BWD299RUWJqBbDrJ+g8f0sYLd7c6Kfv/7UhSgzCx8knfe9YdCB3ud/HJLd6UaTpZgfxj/J8JQr3lFOmWwoHVdMlzjkcWpb92rvPS4cRhz//2nqY8+Q1x6d6xT2PC74hF4E8AF2pRxGtSO+ETgsnwAYl2YJsjn0GrtPVwICAoajkg42mQykdErj0njiq+m2KafCVgV9uOvz3L9EJVEkV8WPdMS+X3L6+oQ2gtfM4DSb5rIC5NEOJsxgmztBtWWI+KyuTwj3Qnxl0J6Sh4OQ9kbKGZG651h404DiZjGEtpbvVt/vf3qFP+/qmJXtI3CANjWKFPQtXLpaMahd8hY6fyt8CEaP6lQkkibiG/utgMNiyUq/qDghGgrPDD2QWfT3CCK5ZlhOxQLY2e/xLBIJVNOcSdnreAAQzxJQGpRZ9N7BhnFqN6V1/XGDD1a4E7lu0K5zF4dk0LGd8XPTWhdv4Rq17pJtxC0SsVBXbWhSjrjP3zn4ai+KtEm6i7lZQgxhJtJuAZgPchvnI9/yExFWItc579Z9FfWCmmFpH4UQwJpeWAZ4ZdBa8nmtvJbksvmKpS/oAFX09xrDobYIUzsFCtaGGm4B0vZ3sDjbscBEJeGsUQE48GBU+/93nGsWOEYw8RjZEnxkHRLgNDsCnzlNkFSJZ59taZ6j7A57r+WUcTmzk081gT6sRYBClkSpQCW6gyu4bz8m31p2CkcmGQEux45AP/4SaBqNZJcBcrKglByxuLCO+wOz208cmSpiIOOtbTtoWrszY5Fv0gc2dc8iHMagwCWiSUFTl6utMGdB1sDjeqisCBL6YkLwNN+osZWm gUo8AekB 3C6L8fPbwb/xX3CnqM9UHcoAdf/lcIi+ET83+0xaJLUxawCGLQ/O7lTxRnpGR/gSTCch4uEMMMlr3gIjtoOxpCJas2ag87H9eLVSb93WONEbStePBS7nRVzoWITG4eObaJ/XNiJ0+GL6CZGnrWkcRg35MYPXBDKCiZjvquIve9kbQY0jucwRqb+Ccc5R2r9Pf3eEaRdeQbpWY/F1P/Znxi+Nz8NA+22CC3mEdfn0b6MVS80NU9x/kzVl8znm2gpngUaEI7eGiDu2RK5F5rx2021JSxPa0hcRp0VPRwYY6MXO3/tItuH8gbUFKZixTluiJYWFWs8qrQqRCKMg= 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: On 2024/8/19 17:40, David Hildenbrand wrote: > On 19.08.24 10:14, Baolin Wang wrote: >> 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 >> --- >>   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: > > ^ "three" is wrong now. Ah, good catch. Will change to '2 + nr_pages'. > >>            *  - 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; > > Acked-by: David Hildenbrand Thanks for reviewing.