Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8681853rwb; Thu, 24 Nov 2022 02:57:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6t/5y0pJpyWP6EBO3VkiboeXp0Saqur+tGR7V81iNJ2qugTmPDQnr410age7aw7gz4q4H+ X-Received: by 2002:a63:f406:0:b0:477:cc1f:204 with SMTP id g6-20020a63f406000000b00477cc1f0204mr2928708pgi.592.1669287420765; Thu, 24 Nov 2022 02:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669287420; cv=none; d=google.com; s=arc-20160816; b=P/yNboGmVc8QH67vqkZxzsM3OELPFLUl/RQ7oT1n29xE0PiFvv7nzgR2vFwAw3xQwb 9lmLYsoGRpXJLaGlMGuLLOnknLBnJpOduxGQVwbNugnU5mePIvY5++AQzXnr1rfscrWR lhoVTNWabyNIu+8QhgHiu569TEwW/ms8Ar0QdfUk9Y/HFdATxjtMM0/8rHI1AIHCTmxG 9V0Hn45MRu5+H1jmTokyabOqwkuOW/DTRRoQOI9ytEnTQWlfx4FkkClTmjnWQM5C2oRV 7Ov6kBlatEwrNQkcT68MzPlrLyg/mB/UVEDp8alj5YuEMFEk2fyaHvfDRTVg7K8ULNEa qLMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=3kAYquvyXCoEwzo0E+846zCjz/I/oFJHnxyQt8aQxnE=; b=G61NbSv3rErjgcYJQRAQrwkEgMWBszhuJ1kXIGDwqJpMWS3I42+UZg8N3/M4onmGbV L3lyj4jxamrPngynRLpxlJJpGwsNcau4ivo4JbpIcRocJ7kNxJ22QWPUw3WAXDInqTHF uGFbtLEkcK643YBM87R+CX7mi4i/iFKngVc3AnX1b0jqbB0zW7b+kRa58n4w2wHMOgez 0C5tLKhT7KzSOJiH8QKR3RgEMNDYBrMDARJz7R3nBDmOcm/yBxX2dMM/hjjc7zNpWQrN 2bBQ2hPn/39n4u4Y2e7goZkOO3RHc5wLnYGyF+Rm2PjsjugBGJhNQDLb7CGzg3PP6Hy1 VpTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CZ0k5cyC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a170902db0d00b0018701d000bfsi742736plx.403.2022.11.24.02.56.49; Thu, 24 Nov 2022 02:57:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CZ0k5cyC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbiKXKKt (ORCPT + 87 others); Thu, 24 Nov 2022 05:10:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbiKXKKn (ORCPT ); Thu, 24 Nov 2022 05:10:43 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D0FBB9607 for ; Thu, 24 Nov 2022 02:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669284584; h=from:from: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=3kAYquvyXCoEwzo0E+846zCjz/I/oFJHnxyQt8aQxnE=; b=CZ0k5cyC/4fESQvmDVkX+yXUSL1tCDwzWdtlDL8JtIN7avTIklpMuDWGQPi7TybI47H2ZZ oid1KiY9mZfCz/s8EbpDLMCVp5zrwjP/U/jfx4KEVTfxy+IfgMKIRvdYyX7CXdOWDj+jgO wQgyCacr6KUwmR7yazD6N5bXtwLxfYI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-652-StVpu-4DPdKYW7pFIIwKKg-1; Thu, 24 Nov 2022 05:09:42 -0500 X-MC-Unique: StVpu-4DPdKYW7pFIIwKKg-1 Received: by mail-wm1-f69.google.com with SMTP id c126-20020a1c3584000000b003cfffcf7c1aso2424474wma.0 for ; Thu, 24 Nov 2022 02:09:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3kAYquvyXCoEwzo0E+846zCjz/I/oFJHnxyQt8aQxnE=; b=tpS89gg4tatPXYIEkY8mbVXp6+azRmdzM/US6RwteHt2NZtlPn8tz6SL6/YwKz1QTn 88CItqwzeZu6iNCBEz4On47V1wfJlv7HsIwz9scOHfSPyaZfOTvWW/vs8IkCCEF7BFnj YRpKb0/tAKBBQTZaJD1VeNpbNWZWoa9/NPCQhNS/iyVh+jzzViOAVFdIIXpGYG8G8wDe 037Hio3j/a+xGjrXhsPRiwQ+guKHXQZOIee242a7mnLsbHuXjGr3dcNICFmgJQnntPv+ MLN8czUWKJ810zCgril5iiXLnt933Iv29d65Rn7n+gAn4wd+hYkfxzCLz5rN+qFHTjYH OZ+w== X-Gm-Message-State: ANoB5pmrIwKhg999737TVqYN2PmU+grNn1t6Xdi9IFZZ+BybkGklbVwx D25h/UDBA3NLS+H/+LD/nDQk9CLyRuC6yWDzJ7sji3s0KNiJVmHZZo6zzjA43H7tjWBgWTd1Ozj znawbUzNHfPL55LZnazDgWN7q X-Received: by 2002:a05:600c:5541:b0:3cf:8896:e1d0 with SMTP id iz1-20020a05600c554100b003cf8896e1d0mr12515852wmb.177.1669284581735; Thu, 24 Nov 2022 02:09:41 -0800 (PST) X-Received: by 2002:a05:600c:5541:b0:3cf:8896:e1d0 with SMTP id iz1-20020a05600c554100b003cf8896e1d0mr12515823wmb.177.1669284581266; Thu, 24 Nov 2022 02:09:41 -0800 (PST) Received: from ?IPV6:2003:cb:c704:2200:bfcb:7212:1370:de13? (p200300cbc7042200bfcb72121370de13.dip0.t-ipconnect.de. [2003:cb:c704:2200:bfcb:7212:1370:de13]) by smtp.gmail.com with ESMTPSA id k17-20020a05600c1c9100b003c6b874a0dfsm1582715wms.14.2022.11.24.02.09.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Nov 2022 02:09:40 -0800 (PST) Message-ID: <3c584ce6-dc8c-e0e4-c78f-b59dfff1fc13@redhat.com> Date: Thu, 24 Nov 2022 11:09:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Content-Language: en-US To: Gavin Shan , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, william.kucharski@oracle.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, zhenyzha@redhat.com, apopple@nvidia.com, hughd@google.com, willy@infradead.org, shan.gavin@gmail.com References: <20221124095523.31061-1-gshan@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2] mm: migrate: Fix THP's mapcount on isolation In-Reply-To: <20221124095523.31061-1-gshan@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24.11.22 10:55, Gavin Shan wrote: > 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. Besides, The page's refcount is > increased a bit earlier to avoid the page is released when the check > is executed. Did you look into handling pages that are in the swapcache case as well? See is_refcount_suitable() in mm/khugepaged.c. Should be easy to reproduce, let me know if you need inspiration. > > Fixes: 1da2f328fa64 ("mm,thp,compaction,cma: allow THP migration for CMA allocations") > Cc: stable@vger.kernel.org # v5.7+ > Reported-by: Zhenyu Zhang > Suggested-by: David Hildenbrand > Signed-off-by: Gavin Shan > --- > v2: Corrected fix tag and increase page's refcount before the check > --- > mm/compaction.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index c51f7f545afe..1f6da31dd9a5 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -984,29 +984,29 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > goto isolate_fail; > } > > + /* > + * Be careful not to clear PageLRU until after we're > + * sure the page is not being freed elsewhere -- the > + * page release code relies on it. > + */ > + if (unlikely(!get_page_unless_zero(page))) > + goto isolate_fail; > + > /* > * Migration will fail if an anonymous page is pinned in memory, > * so avoid taking lru_lock and isolating it unnecessarily in an > * admittedly racy check. > */ > mapping = page_mapping(page); > - if (!mapping && page_count(page) > page_mapcount(page)) > - goto isolate_fail; > + if (!mapping && (page_count(page) - 1) > total_mapcount(page)) > + goto isolate_fail_put; > > /* > * Only allow to migrate anonymous pages in GFP_NOFS context > * because those do not depend on fs locks. > */ > if (!(cc->gfp_mask & __GFP_FS) && mapping) > - goto isolate_fail; > - > - /* > - * Be careful not to clear PageLRU until after we're > - * sure the page is not being freed elsewhere -- the > - * page release code relies on it. > - */ > - if (unlikely(!get_page_unless_zero(page))) > - goto isolate_fail; > + goto isolate_fail_put; > > /* Only take pages on LRU: a check now makes later tests safe */ > if (!PageLRU(page)) -- Thanks, David / dhildenb