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 A4BB5C433FE for ; Wed, 23 Nov 2022 05:06:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 345E26B0073; Wed, 23 Nov 2022 00:06:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F7006B0074; Wed, 23 Nov 2022 00:06:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E61A6B0075; Wed, 23 Nov 2022 00:06:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0F74D6B0073 for ; Wed, 23 Nov 2022 00:06:49 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D32CEAB9BB for ; Wed, 23 Nov 2022 05:06:48 +0000 (UTC) X-FDA: 80163522096.09.F2469A0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id E5FB540005 for ; Wed, 23 Nov 2022 05:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669180005; h=from:from:reply-to: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; bh=jGWcKl8qBYO1tbvPCd08CEn8cDcWUBz7kzb9tc09dPg=; b=aEuZp2vnqa8A6VvGoKZo9HgajeAMXthwQwtSH4DbHu7OkcexEDBSZc9Q44ihme/lF1o2xO FczadajDf4od3g1spPKCIzZjIopFeqgE7kOzRq5BYt/0pDDNG9Kj1vUmm4DYe+mNUqFi4m Ap9bZQRbMQ4My+huO3r4I/09J/6ulBs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-qb-JEGj8MaKQy4hu6zHiSQ-1; Wed, 23 Nov 2022 00:06:43 -0500 X-MC-Unique: qb-JEGj8MaKQy4hu6zHiSQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E95EA3C0D180; Wed, 23 Nov 2022 05:06:42 +0000 (UTC) Received: from [10.64.54.62] (vpn2-54-62.bne.redhat.com [10.64.54.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6ED2140EBF3; Wed, 23 Nov 2022 05:06:39 +0000 (UTC) Reply-To: Gavin Shan Subject: Re: [PATCH] mm: migrate: Fix THP's mapcount on isolation To: Alistair Popple Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, william.kucharski@oracle.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, david@redhat.com, zhenyzha@redhat.com, shan.gavin@gmail.com References: <20221123005752.161003-1-gshan@redhat.com> <87sfias2hd.fsf@nvidia.com> From: Gavin Shan Message-ID: <1a095dbe-0f9a-db49-8473-17552deccf75@redhat.com> Date: Wed, 23 Nov 2022 13:06:36 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <87sfias2hd.fsf@nvidia.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aEuZp2vn; spf=pass (imf01.hostedemail.com: domain of gshan@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669180006; a=rsa-sha256; cv=none; b=Exg3TnFICj/A7XamV/fT3oodwV2wec05yVBmbReRfBfm0xPZyHN2aGiBWN/htv4bQ/oCFp wkDRWUOPPtAV8Gse7GepHPqLLZr3hPnnCrBo94VBdWg1fmuZGCuYIxiUsH+npd9oeXgAVU Tx3JkXW7iFuPREx+yytl3tCYZT4LmVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669180006; h=from:from:sender:reply-to: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=jGWcKl8qBYO1tbvPCd08CEn8cDcWUBz7kzb9tc09dPg=; b=DhLgJVpWiG7YO6lHFj/pTSjr788grmxe93vUSwOBjGyqhFyIG+BheJfybDDrKoBkKlgxTh NJ9w+xmnuFMhW5tAkeZgB+PVA90ARtEe41lcloiFNjIErtmwaZYMDfRnLqf5hn8e6e9vmL ohyTUPAtEFifiaHZY1+r/l5JeXnwi4w= X-Stat-Signature: dzecd9atagp34bfx3hynqxjhmzp9bxpm X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E5FB540005 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aEuZp2vn; spf=pass (imf01.hostedemail.com: domain of gshan@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gshan@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-HE-Tag: 1669180005-876838 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: Hi Alistair, On 11/23/22 12:26 PM, Alistair Popple wrote: > Gavin Shan writes: > >> The issue is reported when removing memory through virtio_mem device. >> The transparent huge page, experienced copy-on-write fault, is wrongly >> regarded as pinned. The transparent huge page is escaped from being >> isolated in isolate_migratepages_block(). The transparent huge page >> can't be migrated and the corresponding memory block can't be put >> into offline state. >> >> Fix it by replacing page_mapcount() with total_mapcount(). With this, >> the transparent huge page can be isolated and migrated, and the memory >> block can be put into offline state. >> >> Fixes: 3917c80280c9 ("thp: change CoW semantics for anon-THP") >> Cc: stable@vger.kernel.org # v5.8+ >> Reported-by: Zhenyu Zhang >> Suggested-by: David Hildenbrand >> Signed-off-by: Gavin Shan >> --- >> mm/compaction.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/mm/compaction.c b/mm/compaction.c >> index c51f7f545afe..c408b5e04c1d 100644 >> --- a/mm/compaction.c >> +++ b/mm/compaction.c >> @@ -990,7 +990,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, >> * admittedly racy check. >> */ >> mapping = page_mapping(page); >> - if (!mapping && page_count(page) > page_mapcount(page)) >> + if (!mapping && page_count(page) > total_mapcount(page)) > > We have several versions of these checks for pinned pages open-coded > around the place. See for example migrate_vma_check_page() and > folio_expected_refs(). It looks like you could use a variant of > migrate_vma_check_page() which would also check non-anon pins, although > I don't know the compaction code well enough to know if that's useful. > > Either way it would be nice if we had a common helper for these kind of > checks. Guess that would be harder to backport, and the change itself > looks ok. But why isn't the fixes tag 119d6d59dcc0 ("mm, compaction: > avoid isolating pinned pages")? > Nice to see your comments. folio_expected_refs() only returns the mapcount for file-mapped pages. migrate_vma_check_page() doesn't cover THP and there is a 'FIXME' there. A unified helper is beneficial to maintainance. I think the issue can be fixed in place and have a followup patch to introduce the unified helper, to make the backporting happy. Right, I was thinking of 119d6d59dcc0, which was merged in early days back to v3.15. I doubt we even had THP support that time. 3917c80280c9 changed the behavior of THP COW handling, to split the THP. Without 3917c80280c9, no splitting is expected and the original condition is correct to check for anon pins. >> goto isolate_fail; >> >> /* > Thanks, Gavin