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 535BFC43217 for ; Thu, 24 Nov 2022 13:22:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E682F6B0071; Thu, 24 Nov 2022 08:22:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E17A66B0072; Thu, 24 Nov 2022 08:22:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB8246B0074; Thu, 24 Nov 2022 08:22:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BD1F56B0071 for ; Thu, 24 Nov 2022 08:22:12 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 922221A071D for ; Thu, 24 Nov 2022 13:22:12 +0000 (UTC) X-FDA: 80168399304.25.8CD9A5B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 26ABE80014 for ; Thu, 24 Nov 2022 13:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669296131; 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=Af+/dAibosKqrfLx5kNJxNqzWHdIAvebWVY3liLga6Q=; b=heHVCGs8YsBGMDpqQkMfNXSE+B/NxuFuhVnMbMdiMLz5mMnUbiiIBrJ+RxS/SmiPr2i7Jw ubovf0SgzK9rv50MKQLejcelFs8ByxQBHzd4gKaDxzrvw3KT0GedEG3GIhIJj8ahmtLgkf JRYWY9MOpal8MwoIOolVtqnjyuw2rdQ= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-149-1Qj38l93O-6jeo4myXZKkQ-1; Thu, 24 Nov 2022 08:22:10 -0500 X-MC-Unique: 1Qj38l93O-6jeo4myXZKkQ-1 Received: by mail-wr1-f70.google.com with SMTP id j30-20020adfa55e000000b00241b49be1a3so403103wrb.4 for ; Thu, 24 Nov 2022 05:22:09 -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:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Af+/dAibosKqrfLx5kNJxNqzWHdIAvebWVY3liLga6Q=; b=Y3gjo0Mz4uoZGiuAh8OK2ImS5cuL9YczPP7+qCHRD45qTOHCu2jQC/Z0W6kklHZYzy loxSMvtWQxZo8RpmZEN8uK/Rm/BHEgxtVHLWul+jvz1kXWLdSlKVl+dJoe5P1pm1J+mI utGAkl17hyLcqOBs7NDjsd17wqS1JMshI+pTURkn5VsicrY6Mkz7DKmt/+NBweyNl6v3 6HhHaSpWQvRHLbYXN81nGCoPyZGBgNkwHzRav3N06XFrQsARxlKXVJjWfNHD5rdT09IV pMNnXDnB0839uGFIyZYPAkY3E9CLnGt3glI/ctt+E2+quT4/o0x4lE5OoQ7kyjwj0Nho mmRg== X-Gm-Message-State: ANoB5pm8buOBZgKU7niS19ssW3w1QzZ/lONrQjYU1mISw4MEkF56ReNU 3DEP8YJ3hzAz8MfOCOjKkBB84QPmJA3XBFmN820DqReZi7oZ6IlqDe0t8jS6oqtOB6f6m4RIqss uPnNzISxZHkE= X-Received: by 2002:a5d:51ce:0:b0:236:78cd:f3e7 with SMTP id n14-20020a5d51ce000000b0023678cdf3e7mr19408569wrv.140.1669296128844; Thu, 24 Nov 2022 05:22:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TQUNmfgh7Sqy+ZunwQXBpN+8GFhklx6qTEjDOXChgxzsOtIJbZHo8TL9fwJbGKfMfkrSfhQ== X-Received: by 2002:a5d:51ce:0:b0:236:78cd:f3e7 with SMTP id n14-20020a5d51ce000000b0023678cdf3e7mr19408553wrv.140.1669296128515; Thu, 24 Nov 2022 05:22:08 -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 s11-20020a5d69cb000000b002366f9bd717sm1694091wrw.45.2022.11.24.05.22.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Nov 2022 05:22:08 -0800 (PST) Message-ID: <759a17cf-e234-2601-bf42-7a40a4d89466@redhat.com> Date: Thu, 24 Nov 2022 14:22:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v2] mm: migrate: Fix THP's mapcount on isolation 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> <31bda0ab-a185-340d-b96b-b1cfed7c3910@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: 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=1669296132; a=rsa-sha256; cv=none; b=KC/7lE3SH4W3ecrbLCFDa8tbEBMiI3ir1tVSoPAAEADT0kUEA2FanoNA60vJOMoZ5f1fn1 XtgAmQDoLs3bAIscqsEoiLjBu0fxTDRS3pZl3bbO3ACJxwbRjD9xPFZ8ZdpwqsESvgoS1L dhOOkn1T8nFftfK9P8HEC4v3KW3ATwY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=heHVCGs8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669296132; 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=Af+/dAibosKqrfLx5kNJxNqzWHdIAvebWVY3liLga6Q=; b=11dH7vqquF58as+NClxEk1kPK8kv9MLalwPgTTukG7uQGkPFLnEFgiFdYD7Yb5hBLGBe5r Ot8DelsJZiyuoSSospEUsQSydHljYrem9aRotZpxe95hIw687vX44DTByg30OkX25nobbl vqOavGxnLVf1v6xoU4EPooJ1o08YaGU= X-Rspamd-Queue-Id: 26ABE80014 X-Stat-Signature: 4ohsaw75kaymurdscpoyocjuxpussefg X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=heHVCGs8; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam09 X-HE-Tag: 1669296131-158614 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 13:55, Gavin Shan wrote: > On 11/24/22 6:43 PM, David Hildenbrand wrote: >> 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 for the details. Step (4) and (5) can be actually combined. To swap part of > the THP (e.g. one sub-page) will force the THP to be split. > > I followed your steps in the attached program, there is no issue to do memory hot-remove > through virtio-mem with or without this patch. Interesting. But I don't really see how we could pass this check with a page that's in the swapcache, maybe I'm missing something else. I'll try to see if I can reproduce it. -- Thanks, David / dhildenb