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 CFF9FC0502A for ; Fri, 26 Aug 2022 21:48:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51F37940007; Fri, 26 Aug 2022 17:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CFA16B0074; Fri, 26 Aug 2022 17:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36EF7940007; Fri, 26 Aug 2022 17:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 259BD6B0073 for ; Fri, 26 Aug 2022 17:48:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F2D46AB03C for ; Fri, 26 Aug 2022 21:48:25 +0000 (UTC) X-FDA: 79843082970.29.289A45C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id A24F31C0029 for ; Fri, 26 Aug 2022 21:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661550505; 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: in-reply-to:in-reply-to:references:references; bh=eK1xE8kkuyeKjR+hDiqozv/hHSl/MNp6EvhuqjxTQwk=; b=CkmMMhQUfivJBGUs7rYhF/G12eWk41qUDecH/lit3ylJ8ftyrB9LxNtKsvQn+0HhZt0vSk EWi92eIc3ACOp+f9f/PUun+t2RUybsX7uMkvk6fTOLDfH/d/YD/rMTjSJEPVrFRMpOV3tU lz5S9Zn+wAEOtzeV508v4fsbMbH9wsY= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-571-PNiWOtz0MQGaIDkTAwDq5Q-1; Fri, 26 Aug 2022 17:48:24 -0400 X-MC-Unique: PNiWOtz0MQGaIDkTAwDq5Q-1 Received: by mail-qk1-f198.google.com with SMTP id ay10-20020a05620a178a00b006bbcab9d554so2215020qkb.13 for ; Fri, 26 Aug 2022 14:48:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=eK1xE8kkuyeKjR+hDiqozv/hHSl/MNp6EvhuqjxTQwk=; b=2GmS0w/aje7nRLFxBkBmr4AS0rhQrEimENB4yNkLMI8MKYLsipc66mpDqGpg8jWVFv J4FAShOq8sVuDW6bhs/R85ikxD05AGkn3XFsG7Xj9kLk4tLx8hKMECwoK54oVYm+Foxi +00MvlTVlN3hGrESo6M+j+IE6ZoYakAjsmMoFl25EL0rrDCBhjcqc+Hh6qIt/lktwTnS uU1D6rlmq70k77k5AMzo5GPm3xAfz0SAM9Stbb/Eoxzy/D3Fy3728EXP8dSbe2FENCRb iuExwiYLK6KdDRUYWR+ajTYQmXKEO37Ywn6yu3mYh0M+aKU0VozwDmwM1eJ/BxwP2QRy Hsdw== X-Gm-Message-State: ACgBeo10OqPZs6q7FBG3Yt2mOlKRESsBRtdXqUMySELTBvgCo0dB7Jct s8b1pxBkDf8r5ugQogpJuv9kNNf5MSoFo2V5/7fGWPkQiRW+ww7A1JnBhuWfiJYgQ68k4vGOOU5 DbmCyOSLfu88= X-Received: by 2002:a05:620a:1343:b0:6bc:139:2fc4 with SMTP id c3-20020a05620a134300b006bc01392fc4mr1187469qkl.637.1661550503562; Fri, 26 Aug 2022 14:48:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4i+Ha08jrqWPJxntJOZsU9/Gt9018A1GEJEqq18O4wqEQN+wXiocQbL9/UD8YKIW3Pu37fZQ== X-Received: by 2002:a05:620a:1343:b0:6bc:139:2fc4 with SMTP id c3-20020a05620a134300b006bc01392fc4mr1187450qkl.637.1661550503283; Fri, 26 Aug 2022 14:48:23 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id j2-20020a05620a410200b006bc192d277csm599978qko.10.2022.08.26.14.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 14:48:22 -0700 (PDT) Date: Fri, 26 Aug 2022 17:48:21 -0400 From: Peter Xu To: David Hildenbrand Cc: Alistair Popple , linux-mm@kvack.org, Andrew Morton , peterx@redat.com, John Hubbard , Ralph Campbell Subject: Re: [PATCH] mm/migrate_device.c: Fix a misleading and out-dated comment Message-ID: References: <20220825014905.977168-1-apopple@nvidia.com> <877d2v7rhf.fsf@nvdebian.thelocal> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkmMMhQU; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661550505; a=rsa-sha256; cv=none; b=QweVDwy87G8fuSk8/rPwoyvKAqATpAn1sXhbTbGaWTTH2/UoQHZ0h4ANc4jr5ouRss10E/ XQE9D51HWcqcIQ1rnV2XR7mYU8CY7PGF5fU8OM9jMzb2b85Z9W6gNHwlQQibScoUGZOcax gutlpXfOVntlEm1PtIViXeGqrRU/9kQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661550505; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eK1xE8kkuyeKjR+hDiqozv/hHSl/MNp6EvhuqjxTQwk=; b=o+sjiIL71FAMU5TGoirvgFF+3KJOsxqFlwWpWl6QeclG486sHTpDSs9iA8AWR//+UIKUcT Cgnbh1vz36REDhmTEoBrr58Vfuy+kBStaNrNvKqprzLbHAjJmOf1nm9e6BnRXpKpn8z51D d7R0lY968hnRwglqSsnW8VWap87aKaU= X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CkmMMhQU; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam07 X-Stat-Signature: mmzfzu4wkif338dbspidipyh6sr8i6oi X-Rspamd-Queue-Id: A24F31C0029 X-HE-Tag: 1661550505-744312 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 Fri, Aug 26, 2022 at 07:17:06PM +0200, David Hildenbrand wrote: > 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(). Fair enough. I think it depends on what we want to do with the migration. I think not even all users of isolate_movable_page() only depend on trylock, and it can retry with lock_page later. E.g.: - soft_offline_in_use_page - isolate_page - isolate_movable_page <----- trylock here - (if isolate_page fails...) migrate_pages - unmap_and_move <----- lock_page here after 2 unsuccessful rounds And I also agree migration may always fail (e.g. by spurious page refcounts being taken), so feel free to ignore the "gut feeling" - that's indeed kind of subjective. Thanks, -- Peter Xu