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=-1.0 required=3.0 tests=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 5C233C54EEB for ; Tue, 24 Mar 2020 09:14:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 262DB206F6 for ; Tue, 24 Mar 2020 09:14:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 262DB206F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C064F6B0007; Tue, 24 Mar 2020 05:14:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB7396B0008; Tue, 24 Mar 2020 05:14:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACC206B000A; Tue, 24 Mar 2020 05:14:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 96D026B0007 for ; Tue, 24 Mar 2020 05:14:56 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1407218337A39 for ; Tue, 24 Mar 2020 09:14:57 +0000 (UTC) X-FDA: 76629696234.22.test97_2b339aa689253 X-HE-Tag: test97_2b339aa689253 X-Filterd-Recvd-Size: 5629 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Mar 2020 09:14:56 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id 31so14413710wrs.3 for ; Tue, 24 Mar 2020 02:14:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2V7xweY74fXBr8Kb4wq/sXApQxiWmjhJdGlJK1jrhDk=; b=sBrSBKjgmqFlYOmbO2WQIqTbO1tTZQM2uOSjDCemZQGrLiw9ZgvazwbSObsI7iUPNN BVRqBNsGeRusKKXYClvItqqLF9zfXRmJPZboMUPMN6UyG6EGPP+e+tzVw+n0NIWvH1EW E51SQW/xoeVa2qRgmFsQd5EdTFOqcDvv7pkYjrr4tyBpgQAIyXJp7ytKRcDtpCHftc1X MVCVt6PDIfGyIwmcWOTsunEOLTDLl0V1cd2mfLJSEjiHBkuje3PUgmgQ+SD9ELsuYffn +zGsm4ftAq65Srg+7V+c5SLXK3LjC8JdeNHYSkErmMlBeW+7QlRlupYoh29LWXzPGxMw Td8g== X-Gm-Message-State: ANhLgQ1MsfDy4iHXmD5x20wj0Zii2ZWekSUKpcx4SPYGdLTnEEj2y4Yq JnzyJfk43yU68tJfaGhXmag= X-Google-Smtp-Source: ADFU+vsh3X/SnEIY8EiSAhazJgzaS/7Gg1W5hu3H7i+tP9mIgBn/GJLpHbO50Omdhw/sznrg1yzghw== X-Received: by 2002:adf:e948:: with SMTP id m8mr12493401wrn.193.1585041294846; Tue, 24 Mar 2020 02:14:54 -0700 (PDT) Received: from localhost (ip-37-188-135-150.eurotel.cz. [37.188.135.150]) by smtp.gmail.com with ESMTPSA id w9sm5336077wrk.18.2020.03.24.02.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 02:14:54 -0700 (PDT) Date: Tue, 24 Mar 2020 10:14:53 +0100 From: Michal Hocko To: Pingfan Liu Cc: Linux-MM , =?iso-8859-1?B?Suly9G1l?= Glisse , John Hubbard , "Kirill A . Shutemov" , Aneesh Kumar , Andrew Morton Subject: Re: [PATCH] mm/rmap: fix the handling of device private page in try_to_unmap_one() Message-ID: <20200324091453.GF19542@dhcp22.suse.cz> References: <1584885427-4952-1-git-send-email-kernelfans@gmail.com> <20200323073408.GA7524@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. The rmap walk and callbacks would benefit from a proper documentation. Hint... -- Michal Hocko SUSE Labs