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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B55D2C1975A for ; Wed, 25 Mar 2020 10:54:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6039D20663 for ; Wed, 25 Mar 2020 10:54:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HNt89NwF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6039D20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B06A76B006C; Wed, 25 Mar 2020 06:54:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB6016B006E; Wed, 25 Mar 2020 06:54:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F3456B0071; Wed, 25 Mar 2020 06:54:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 845156B006C for ; Wed, 25 Mar 2020 06:54:25 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 15EA9181AD0A3 for ; Wed, 25 Mar 2020 10:54:25 +0000 (UTC) X-FDA: 76633575690.10.noise36_60c2ee2cf6313 X-HE-Tag: noise36_60c2ee2cf6313 X-Filterd-Recvd-Size: 6347 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 10:54:24 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id f16so1381093ilj.9 for ; Wed, 25 Mar 2020 03:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qr9eFHIfJe9TcqOA8AHQ3KrNi35p+85MAtcx8hKZT0w=; b=HNt89NwF9FCDobTAR7XSWQh9s6+ZQZBB1Ks6AeC8SkonFe3h3jo5CwBvZJzWsvG27e gEu73En9sa75r1qftV9IZb8rvoUxK1dzGSIzM7guXVNARAEBXgBa4x/saLJR1drj5F2x D3CwgnxTwwuqxkXU2hV7v9ONyKd51vRcCF6gPOOB6PuPs1LDsZaxuC51qzHTv9jCzQ+m 2yrBfQqvpLvas36eyMNKl3dWj3BwxbdQNz2yP6CaS5msmqdi48KfsJkaJyjo+23tqpU+ iqnXQ3hUTIy8NLmNXsvzgJ0dbLdRtRdjJmZ0k3pWdPHHQ+OFkAGRRbHzQT7HxAB654ee EmjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qr9eFHIfJe9TcqOA8AHQ3KrNi35p+85MAtcx8hKZT0w=; b=VB8DFEp6ilm1uBAq/TgUl6vOlJ/0zeNcnBSX8/iI1v+F//LSAoi+sBhaqtLbUXAul5 UtIEyswRYxuuqBmV4VIynvPErCdqDSC5N+uT99hYHm+vfVfw1CsixuZe0eId1wCLOtUa tNDoHGUSfwcA5vTY/vqbuFX2v+pf6TiYZHPW04e4IXDFCE2QT3GToqZH6jIwKVPIQ0/u yuaUT006LlxYllDM6aPzl65IhRV4APW+iqZ5O/VEtTOpCCUSJ6ONOU+cKiXaMuVupxfO f0Osa9mP/N6Ae7OxN1WMhlEB0ejIqO3z64Sp3VCyVOwU7d+SxsIw0nO111VutAK2vpTg G7eA== X-Gm-Message-State: ANhLgQ1KCdTEYPcnR4vVmxH3jwKbzVG2elz1GuNj7AJLo/LaDgmIN3ZT RyHqaKiWJv6pTaIN83BOvs68OFjHKDkgoY4Jgw== X-Google-Smtp-Source: ADFU+vtn+l9mpPakcW1Qgl5UD7X5rKJa21hBX6NbJnQuswiRleRFOI24D2C0Y4VuEfAcMibKtu3QEFgo8bt9GqxZUPg= X-Received: by 2002:a92:5fc1:: with SMTP id i62mr2586863ill.15.1585133664192; Wed, 25 Mar 2020 03:54:24 -0700 (PDT) MIME-Version: 1.0 References: <1584885427-4952-1-git-send-email-kernelfans@gmail.com> <20200323073408.GA7524@dhcp22.suse.cz> <20200324091453.GF19542@dhcp22.suse.cz> In-Reply-To: <20200324091453.GF19542@dhcp22.suse.cz> From: Pingfan Liu Date: Wed, 25 Mar 2020 18:54:12 +0800 Message-ID: Subject: Re: [PATCH] mm/rmap: fix the handling of device private page in try_to_unmap_one() To: Michal Hocko Cc: Linux-MM , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , "Kirill A . Shutemov" , Aneesh Kumar , Andrew Morton Content-Type: text/plain; charset="UTF-8" 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 Tue, Mar 24, 2020 at 5:14 PM Michal Hocko wrote: > > On Tue 24-03-20 11:47:20, Pingfan Liu wrote: > > On Mon, Mar 23, 2020 at 3:34 PM Michal Hocko wrote: > > > > > > On Sun 22-03-20 21:57:07, Pingfan Liu wrote: > > > > For zone_device, migration can only happen on is_device_private_page(page). > > > > Correct the logic in try_to_unmap_one(). > > > > > > Maybe it is just me lacking knowledge in the zone_device ZOO. But > > > this really deserves a much more detailed explanation IMHO. It seems > > > a5430dda8a3a ("mm/migrate: support un-addressable ZONE_DEVICE page in > > > migration") deliberately made the decision to allow unmapping these > > > pages? Is the check just wrong, inncomplete? Why? > > I am not quite sure about zone_device, but I will try to explain it later. > > > > But first of all, I think the code conflicts with the logic behind it. > > If try_to_unmap_one() success to unmap a page, then it should kill the > > pte, and return true. But the original code return true before the > > code like "ptep_clear_flush()" > > > > Now, I try to say about !device_private zone device. (Please pardon > > and correct me if I make a mistake) > > memmap_init_zone_device() raises an extra _refcount on all zone > > device. And private-device should lifts the count later, otherwise it > > can not migrate. But I did not find the exact place yet. > > > > While this extra _refcount will block migration, it is not the whole > > reason if a zone device page is mapped. > > > > If a zone device page is mapped, then I think the original code > > happen to work due to it skip the call of page_remove_rmap(), and in > > try_to_unmap(){ return !page_mapcount(page) ? true : false;}. > > OK, you made me look more closely. > > The lack of documentation and therefore the expected semantic doesn't > really help. So we can only deduce from the existing code which is a > recipe for cargo cult programming :/ > > The only difference betweena rmap_one returning true and false is that > the VMA walk stops for the later and done() callback is not called. > Does rmap_one success means the mapping for the vma has been torn down? > No. As we can see for the munlock case which just shows hot vague the > semantic of this callback might be. > > I believe the zone device path was just copying it. Is that wrong? > Well, it is less optimal than necessary because the property we are > checking is not VMA specific so all other VMAs (if there are any at all) > will have the same to say. > > So the only last remaining point is the done() callback. That one is > documented as a check. There is no note about potential side effects but > the current implementation is really only a check so skipping it doesn't > make any real difference. > > > > What is the real user visible problem here? > > As explained, the original code happens to work, but it conflicts with > > the logic. > > Your changelog should be explicit about this being a pure code > refinement/cleanup without any functional changes. OK, I will do that. > > The rmap walk and callbacks would benefit from a proper documentation. > Hint... I will add some note around try_to_unmap_one(), and update the commit log. (Hope my understanding of zone device is right, and will cc more people for comment) Thanks, Pingfan