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 10F70ECAAD4 for ; Fri, 26 Aug 2022 15:03:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 834196B0074; Fri, 26 Aug 2022 11:03:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E2A9940008; Fri, 26 Aug 2022 11:03:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 684C3940007; Fri, 26 Aug 2022 11:03:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5A2CA6B0074 for ; Fri, 26 Aug 2022 11:03:55 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2AE17120F27 for ; Fri, 26 Aug 2022 15:03:55 +0000 (UTC) X-FDA: 79842063630.26.0F6D059 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 D16114002E for ; Fri, 26 Aug 2022 15:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661526234; 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=sYYHQ2kkPbTF4sW5KSNy7BynkY7s0LKQiwkVYmpXyqw=; b=Nxo7MLh0wuf/ZlflUEAegySk3K20oDjh7dF8p/Qr+o/FkcHanQOSS5mImkyb4Ws/uiWnPy v+X3OjrV1miZatDpoFSFmlbu2vowyEKQniApy6izGZajQuOdVN5pONwJcyD9qxbr8mHv/m D4g8ZUrQ0MqBP3lJtFQPw1cgYywbCo8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-450-Bx2uGiK7MNa0xZ4vNMCv3w-1; Fri, 26 Aug 2022 11:03:53 -0400 X-MC-Unique: Bx2uGiK7MNa0xZ4vNMCv3w-1 Received: by mail-qt1-f200.google.com with SMTP id fc18-20020a05622a489200b00344b09d2578so1466266qtb.13 for ; Fri, 26 Aug 2022 08:03:53 -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=sYYHQ2kkPbTF4sW5KSNy7BynkY7s0LKQiwkVYmpXyqw=; b=yxfZLUUrgtPr3utQbumGbKzHTuY800CayMYJuYo7eg9JHZMzEFiSwzRxqiJxfhQfnk vQLqndxiXspKBDNxQfXD9laLthZcqrgplbftaGNDLQHDu8KgnA/gpU8o63UIUJFOudId +oSqq0slmV7NIywDheUDKMAP3aQlppsXLdR/iKnFvwfk6d50m5XVKVfoDjJeraJc3zuZ KSMzHle1UId/1Ls4lINqLj6B+RnsQ7RrfD0VdaGHZ/5faoME+weVdEuLeK7QMhjSz/bt CHKs0oEtmJTOBAWG4EwOTA0G1owG5zmYHTSyd2iPpz0pfTm9asjeV5X37vBPJFaRvY7n aKyQ== X-Gm-Message-State: ACgBeo2gnR6h794EvfepooR2eIudo6FX9Cy9/gDK50hRPIQM9w+NOZk4 0Nnl4DEpqWI7duM1xDYhPCJ+xYBP6Lrr0gBnTI6Z2UqFngeGlDymSlRbB7B+gSEd0CF+X5z/Z0U AhCTc+MnNXzc= X-Received: by 2002:a05:622a:190f:b0:344:f904:4092 with SMTP id w15-20020a05622a190f00b00344f9044092mr111812qtc.216.1661526232493; Fri, 26 Aug 2022 08:03:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR7MLaJUI/D5TbihrkpJSzqbLBv4AWKD7B5XQd6O9bZRBaocq2LAJ3UkdZFL3kanSUu0HYuuXw== X-Received: by 2002:a05:622a:190f:b0:344:f904:4092 with SMTP id w15-20020a05622a190f00b00344f9044092mr111780qtc.216.1661526232202; Fri, 26 Aug 2022 08:03:52 -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 w1-20020a05622a134100b00342b7e4241fsm1383092qtk.77.2022.08.26.08.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 08:03:51 -0700 (PDT) Date: Fri, 26 Aug 2022 11:03:50 -0400 From: Peter Xu To: Alistair Popple Cc: 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: <877d2v7rhf.fsf@nvdebian.thelocal> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526234; a=rsa-sha256; cv=none; b=LwxvtKKHh5VBoIxltQW6p/dX15gjZSy3VPfAUBQHKrKvVjnOoqe1f4hLZxAHn+ttd6bzW4 dmDNlwyLPWT1Q7v2bqKdR0cU5WhttFYrXLFWE2R3BRGpLZzRCia435G4bPZrbEKHH0Xgmi kkslTwD6kl91hkEwSkLBE64BaZJfig0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nxo7MLh0; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526234; 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=sYYHQ2kkPbTF4sW5KSNy7BynkY7s0LKQiwkVYmpXyqw=; b=N8mPZPr3wJWE+rv48R5PmM9aRRvFUunoXFVwUtptC18oij6LoaK1baTewowlA2PZyV1rLd UlYQ94KxyzXPeoAg6jHhYx1m/x6jxz38+5vqyqe6F+YggtyO+LdqFFahOkDem5sxlXjRP4 +pB4OJwmiD2EfNC+vNxT0d4uW666TlQ= X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nxo7MLh0; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam10 X-Stat-Signature: s48h5yaz1nduf7ciw58a1a31oijj3m8z X-Rspamd-Queue-Id: D16114002E X-HE-Tag: 1661526234-165271 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 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. > > And the fact that migration can fail is already covered in the existing > documentation. See for example the extensive comment on > migrate_vma_setup() about how the whole flow works. Eg: > > * Once migrate_vma_pages() returns the caller may inspect which pages were > * successfully migrated, and which were not. Successfully migrated pages will > * have the MIGRATE_PFN_MIGRATE flag set for their src array entry. IIUC trylock failure could be detected even earlier than that. E.g. the ppc code has: ret = migrate_vma_setup(&mig); if (ret) return -1; spage = migrate_pfn_to_page(*mig.src); if (!spage || !(*mig.src & MIGRATE_PFN_MIGRATE)) goto out_finalize; So afaict it won't even reach migrate_vma_pages() by missing of the flag MIGRATE_PFN_VALID in the src mpfn. Probably because the migrate_vma_*() API is extensive enough so it's hard to summarize its usage in a short paragraph. I'm probably asking too much.. No strong opinion on the rest as long as we can add back some explanation on why lock_page() is not used. Thanks again for doing this. -- Peter Xu