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 E5B5CC43219 for ; Thu, 24 Nov 2022 10:43:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A3F86B0071; Thu, 24 Nov 2022 05:43:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 453276B0072; Thu, 24 Nov 2022 05:43:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31AC56B0074; Thu, 24 Nov 2022 05:43:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 20B686B0071 for ; Thu, 24 Nov 2022 05:43:21 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E9B891A1373 for ; Thu, 24 Nov 2022 10:43:20 +0000 (UTC) X-FDA: 80167998960.02.FB4E440 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 5F32B10000D for ; Thu, 24 Nov 2022 10:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669286599; 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=2Y4Whve7954lqLzvpAWCYgQmo37A2Kkr5rk2IyTQcoE=; b=h07OQk9RtHOv7iJHY0JKKcK5BNowbveHx0nujhza85VzYzZ7jCqVt22r9qr4atsMwwFiCf UJhfXBfP6zgKThUGk60el4ySEf/8gtwxtjjggbjperBSoISkodm2R6IOE3egDi+YmV65Gr WFLCdmp1pKA0+C7097YkBYhwGO9W0WI= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-481-p1lelwkOObWpS_urfYFAKw-1; Thu, 24 Nov 2022 05:43:10 -0500 X-MC-Unique: p1lelwkOObWpS_urfYFAKw-1 Received: by mail-wm1-f72.google.com with SMTP id m17-20020a05600c3b1100b003cf9cc47da5so766687wms.9 for ; Thu, 24 Nov 2022 02:43:10 -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=2Y4Whve7954lqLzvpAWCYgQmo37A2Kkr5rk2IyTQcoE=; b=y6HBwHCOT5mU77a193y+5a/68v/uO9V6M0C5sz6rPQ+4bDdKFna/7KJ+CLISzkUiD2 s838L7h230EblBdHvr5aeZC8Si9IW8ftOfi4cbLAqMWGGGAebcKUMLNahVU5DGPpWoRD EJ5dO5GaoUJ9oAldnNGX9t1JrjSTGDWENs0V6gEGFHLoSG86cR0PlYk15sN/wwgnqueu J42aKglCYw6YpJN0A+zdPtZLRX6NNCIHKR8/5fabyKGcfCrKVvFf6tABlqfaFIs1+Iga 0CUOt0tDW6ImyuMyec+/BefBrTb7Rdfv2kR2yQ7NU/8FDmtaXe82gQk+pW/dT70fgVXM 8nbw== X-Gm-Message-State: ANoB5pkYEunKsbHyzHpNWoVwDBj2qP4Jnn/eztCdJrzxk4wFREbi9ABQ wN3K10dkoF1Kqn7tweMus2hov/3LL/1N9stEHnJj5SNWqbkLlqUQm0jOCxKGK51O9TCLnhx/zdg DAlVRJ35aRH8= X-Received: by 2002:a1c:7219:0:b0:3cf:77b7:61e6 with SMTP id n25-20020a1c7219000000b003cf77b761e6mr11909979wmc.162.1669286589466; Thu, 24 Nov 2022 02:43:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf4yATwvqcAiRSd2ogA9zvNkwcQpJPUOYsq2REuxCRQmJ2yu8iducuNJCkm3pbdnmx9zR7q5cQ== X-Received: by 2002:a1c:7219:0:b0:3cf:77b7:61e6 with SMTP id n25-20020a1c7219000000b003cf77b761e6mr11909958wmc.162.1669286589138; Thu, 24 Nov 2022 02:43:09 -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 q10-20020a05600c46ca00b003c6bd91caa5sm1397502wmo.17.2022.11.24.02.43.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Nov 2022 02:43:08 -0800 (PST) Message-ID: <31bda0ab-a185-340d-b96b-b1cfed7c3910@redhat.com> Date: Thu, 24 Nov 2022 11:43:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 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> <3c584ce6-dc8c-e0e4-c78f-b59dfff1fc13@redhat.com> <22407f18-0406-6ede-ef1e-592f03d3699e@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2] mm: migrate: Fix THP's mapcount on isolation In-Reply-To: <22407f18-0406-6ede-ef1e-592f03d3699e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669286600; a=rsa-sha256; cv=none; b=gtNhVNkFXSH8fWssDse9T0sLOTtKhAt2Tifls5c+BxP1fm9R83K3wueU5DKJqrrAYi2I9r eZsjNXSlKtjSpOOKGhhqmypTRNRvaU5l/3AHfnvQiInkBvVYif/iv4vuWlnnvpAuVYuBMR iQzCbD9q1Ikjyf3Hp4ICA5IhLJ7kqEY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h07OQk9R; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669286600; 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=2Y4Whve7954lqLzvpAWCYgQmo37A2Kkr5rk2IyTQcoE=; b=UptxYfEhNJyTbc/nGuaYaDYt/1ZTfOYq23YnIWtxP+G2KKUf4z5qI5uoWiiFVFXlpoBL4T JhFZsngnzZFj3X1nBAC0wnEu2P/AHFQ1vqq8ygkiLQgIDXY/1KXrtV6+gsoffFcNh2k9I/ 52J3Dc6aYTH2e0lRGNoW1TpP3E5IuXM= X-Stat-Signature: cszeqmumd6m17ctxzh4pehspqse67sxn X-Rspamd-Queue-Id: 5F32B10000D X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=h07OQk9R; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam10 X-HE-Tag: 1669286600-679952 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: On 24.11.22 11:21, Gavin Shan wrote: > On 11/24/22 6:09 PM, David Hildenbrand wrote: >> 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. >> > > Nope, I didn't look into the case. Please elaborate the details so that > I can reproduce it firstly. A simple reproducer would be (on a system with ordinary swap (not zram)) 1) mmap a region (MAP_ANON|MAP_PRIVATE) that can hold a THP 2) Enable THP for that region (MADV_HUGEPAGE) 3) Populate a THP (e.g., write access) 4) PTE-map the THP, for example, using MADV_FREE on the last subpage 5) Trigger swapout of the THP, for example, using MADV_PAGEOUT 6) Read-access to some subpages to fault them in from the swapcache Now you'd have a THP, which 1) Is partially PTE-mapped into the page table 2) Is in the swapcache (each subpage should have one reference from the swapache) Now we could test, if alloc_contig_range() will still succeed (e.g., using virtio-mem). -- Thanks, David / dhildenb