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 5D4E1ECAAA3 for ; Fri, 26 Aug 2022 17:17:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFCAD940007; Fri, 26 Aug 2022 13:17:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C854F6B0078; Fri, 26 Aug 2022 13:17:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFE10940007; Fri, 26 Aug 2022 13:17:11 -0400 (EDT) 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 9822F6B0075 for ; Fri, 26 Aug 2022 13:17:11 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7470216076D for ; Fri, 26 Aug 2022 17:17:11 +0000 (UTC) X-FDA: 79842399462.23.1DD5DF8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 1595240028 for ; Fri, 26 Aug 2022 17:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661534230; 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=0mp+NJXx34T6AFmwLLawtwnZ+zLbm7tB4q5wOQlbZ3g=; b=LGje0ou+Q/V/O/ifp8gzS4N9ECbwC1pOKFEU9hISahx1Z/aHlynTWgSt68lyAN9TyKjQ1E JZUKgdNPvqCA90I6Lw3//D+EfPe+pT8CBIy3sZ41zYI6XDWPTwU01V0Mw7RG7hyrtr4peA JruWzVmOHxcQN2fQZCLmElgAk2iNF+s= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-614-q1xBzgyqPjiO5YUq1eaq3Q-1; Fri, 26 Aug 2022 13:17:09 -0400 X-MC-Unique: q1xBzgyqPjiO5YUq1eaq3Q-1 Received: by mail-wm1-f71.google.com with SMTP id i132-20020a1c3b8a000000b003a537064611so1254435wma.4 for ; Fri, 26 Aug 2022 10:17:09 -0700 (PDT) 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; bh=0mp+NJXx34T6AFmwLLawtwnZ+zLbm7tB4q5wOQlbZ3g=; b=Hvp0PcBc4RVRffzTK60B0m3ciPtWXgpWTE88RARNuyhQM1Oq0qLm7TpdKfOSPbBQ0/ /jN+IEpKgXEwOmTVo7gH4QLfiI9Y2H1RAjXEW/rkxPstUfaUYkLb54T5bUrIXr9BUz6M S7pskyzlZlWV1KFBTr9WaG50ChsB4ZVQMP7Eb4Se1hZZC4gsOz6holD9VCZ/2NN619Nc aIY7WlcgYUQHqrDlwuvZTuea48anKDZZ/nyhDrMfndKvFUPT87wCasGFGCg23FQVV5Qo cixUSG+5DFTAENdqv24Al8LKxuQYVmkYnysjTJf3Z/+8kFTFijhM0f1X/BcF701tQsko FR9Q== X-Gm-Message-State: ACgBeo1+oGH80hvDDeWSBY60xIWQr3X+XTq9ZANW09p9oz6++//2Evl8 8C8U5GUC9lbZ2juQi53OSfTKCPsgiBEpsiSxPz5XURUlFZ9ainI5Xzb72guAZWH6zwrJRrj3FfV tuXgEToE6QSs= X-Received: by 2002:a1c:2b46:0:b0:3a7:ad1e:c24 with SMTP id r67-20020a1c2b46000000b003a7ad1e0c24mr317095wmr.7.1661534228121; Fri, 26 Aug 2022 10:17:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR63Q3+E0h0dJ/+NpfflCg5Vl9M30jyTXu4wvqBylgis9RIhLolGoG9H0ETUukMj5WA1zc2R/g== X-Received: by 2002:a1c:2b46:0:b0:3a7:ad1e:c24 with SMTP id r67-20020a1c2b46000000b003a7ad1e0c24mr317071wmr.7.1661534227796; Fri, 26 Aug 2022 10:17:07 -0700 (PDT) Received: from ?IPV6:2003:cb:c708:f600:abad:360:c840:33fa? (p200300cbc708f600abad0360c84033fa.dip0.t-ipconnect.de. [2003:cb:c708:f600:abad:360:c840:33fa]) by smtp.gmail.com with ESMTPSA id a12-20020a05600c348c00b003a5bd5ea215sm182078wmq.37.2022.08.26.10.17.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Aug 2022 10:17:07 -0700 (PDT) Message-ID: Date: Fri, 26 Aug 2022 19:17:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] mm/migrate_device.c: Fix a misleading and out-dated comment To: Peter Xu , Alistair Popple Cc: linux-mm@kvack.org, Andrew Morton , peterx@redat.com, John Hubbard , Ralph Campbell References: <20220825014905.977168-1-apopple@nvidia.com> <877d2v7rhf.fsf@nvdebian.thelocal> 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 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661534231; a=rsa-sha256; cv=none; b=SOOvQ7FnCpnWgKC1G3fBndZ5xwc5jkZiVolVxYFTxr9QLjmEjc+hRC1+WrA4+7SSShiY+G QCceHtrhg+pdOPkr0DCG6tZq+71dKhWF0jxcSW+Tb2bxwSszhMYgbeXLejwhDlYaXaw1yU Py33CHsBAkG3qOVGGyiRB8coiZAqjmU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LGje0ou+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1661534231; 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=0mp+NJXx34T6AFmwLLawtwnZ+zLbm7tB4q5wOQlbZ3g=; b=PjcNlfX2E4TQsY/rc5AmWEeQJ1hwTytJh/mTyVU/CzW3ZCRB3rnKSFq5YkCl7xZ5Nw83r+ A34t/x1VncFcQehbzkW0pfpiu8cDEwWQHVDHPcxbMByKQWV6EGyCkaM7IB2WGlig/YWSx1 8scXCcgFtUvQNh3bLwVlJOYZU42RrrU= Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LGje0ou+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6xi1n48z8nnra7unydnfr3chqzetb4ky X-Rspamd-Queue-Id: 1595240028 X-HE-Tag: 1661534230-705785 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 26.08.22 17:03, Peter Xu wrote: > On Fri, Aug 26, 2022 at 10:34:15AM +1000, Alistair Popple wrote: >> >> Peter Xu writes: >> >>> On Thu, Aug 25, 2022 at 11:49:05AM +1000, Alistair Popple wrote: >>>> Commit ab09243aa95a ("mm/migrate.c: remove MIGRATE_PFN_LOCKED") changed >>>> the way trylock_page() in migrate_vma_collect_pmd() works without >>>> updating the comment. Reword the comment to be less misleading and a >>>> better reflection of what happens. >>>> >>>> Signed-off-by: Alistair Popple >>>> Reported-by: Peter Xu >>>> Fixes: ab09243aa95a ("mm/migrate.c: remove MIGRATE_PFN_LOCKED") >>>> --- >>>> mm/migrate_device.c | 8 +++++--- >>>> 1 file changed, 5 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c >>>> index 5052093d0262..0736f846de0b 100644 >>>> --- a/mm/migrate_device.c >>>> +++ b/mm/migrate_device.c >>>> @@ -179,9 +179,11 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, >>>> get_page(page); >>>> >>>> /* >>>> - * Optimize for the common case where page is only mapped once >>>> - * in one process. If we can lock the page, then we can safely >>>> - * set up a special migration page table entry now. >>>> + * If we can't lock the page we can't migrate it. If we can it's >>>> + * safe to set up a migration entry now. In the common case >>>> + * where the page is mapped once in a single process setting up >>>> + * the migration entry now is an optimisation to avoid walking >>>> + * the rmap later with try_to_migrate(). >>>> */ >>> >>> IMHO the last sentence can still be a bit confusing - here we 100% rely on >>> the trylock() to proceed or we'll stop migration right away. IMHO that >>> means this is not an optimization, since optimizations should always be >>> optional but not the case here. >> >> We have to lock the page here, we don't have to install the migration >> entries. Installing the migration entries here is optional and is the >> optimisation. > > I see what you mean now. > >> >>> Meanwhile it'll be great to also mention about why trylock is needed and no >>> further attempt to use lock_page(). The comment in prepare() previously >>> was great but unfortunately that code clip was removed. >> >> Will add. >> >>> In short, do you think something like this might be clearer? >> >> I think it's important to mention the optimisation, otherwise the >> temptation is to remove the installation of migration entries here and >> rely on try_to_migrate() to do it later. I would actually like to be >> able to do that because it simplifies the code in many ways but based on >> my testing the optimisation turns out to be very worth while. >> >>> /* >>> * We rely on the trylock() to migrate the pte. If this >>> * fails, we'll fail the migration of this page. IOW, the >>> * migration is very much best-effort, just like we'll also >>> * bail out if we found page pinned by other users after >>> * page being locked. >> >> Honestly I think this describes what the code does rather than why and >> is likely to become outdated and confusing. IMHO it's quite clear from >> the code that the migration will fail here if we can't lock the page. > > If you see that's what I was struggling to understand previously, so not > clear at least to me. :) Since normally a function like page migration > should (from the gut feeling) not rely on trylock only. IIRC, ordinary page migration will also only trylock. See isolate_movable_page(). -- Thanks, David / dhildenb