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 77FECC433F5 for ; Wed, 11 May 2022 21:46:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6B8F6B0075; Wed, 11 May 2022 17:46:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1BB88D0002; Wed, 11 May 2022 17:46:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABC7F8D0001; Wed, 11 May 2022 17:46:16 -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 9EBA16B0075 for ; Wed, 11 May 2022 17:46:16 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6EA0B20593 for ; Wed, 11 May 2022 21:46:16 +0000 (UTC) X-FDA: 79454795952.15.7C034A8 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf28.hostedemail.com (Postfix) with ESMTP id 8D080C00A2 for ; Wed, 11 May 2022 21:45:55 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id x12so2891071pgj.7 for ; Wed, 11 May 2022 14:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fmAQGXykxhi3NepF05zy14Lr44K9yKjrDKoSJAz3/FY=; b=JBqMvOVBN2rq0FFfHUFV1lH1c5cMiSL4usNhYXtUzFbudxKFr2HaFM5NBw15FMmZUh Ter7iPSqzb3NC1djJOjvaG7MuwkULz9LF6jXij8HFiTi861C/PXgJR9ewcrjdKwUEn6B GfIP+XhnBY3DfMFyMK9RlfwMomDKCjtLznNeqpElUkYWYTkcYZ8F2M+3eyQr8ACUC2MM +VE0n7soq5lesWTF9FQ86gGacuwnK0LMNHS8BpRLu1lQpc0B4RUUnV3WxsiRu3ENkFBo VBJBE5fu8hj9w2JxBu1OsvZbcaX44HrTnvrxlui7Lkaiw2s2GRAlzzf1L4aBlb7F76rX 3Uyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=fmAQGXykxhi3NepF05zy14Lr44K9yKjrDKoSJAz3/FY=; b=hA6H+4JnZfahAdp1L5xkyI7R/UQ2IofKthiBp0qCFFV/axT5bvMImZag5/rVJP/KQw gra+FO/z4BZpJDi03c1Iy8GN59FUwNY5ZjMp4HaQa9ckb8d7gAEqbWQisgtKEc2SJEi3 MzWcOTbeVKYEY1CEWJJKgkxg5kzL8VMS85eoB2MOqPFsL7gy4RIrpQpwHDnDQFIKCOMZ MX1dX03IteKRHvqR0bGAKuNc+YTtuKqwlwUAAqTzpnH3ixka4ukWSXC0iSFWmBB170oS rh7Ph9zB2XbEVFZLGCAxMZG33kDU/jGOrlumYpnYpFw0WO6s1Wu1V/qtVdJc3M51UL/H puyQ== X-Gm-Message-State: AOAM530HBznWuINjwSXm6Hq/bIzM2l3eBtMQSbBI2thth7T86wObyxzL /qGDmIgcbU/ft0+Qvl6Xm9k= X-Google-Smtp-Source: ABdhPJzltmz0RDNNi+ko+midxpZBcyYw7TrYspnUZofQpPSidhOETlVnZ7Lgi9ltztlvJicJhn5sYQ== X-Received: by 2002:a63:381e:0:b0:3c6:d5e4:fed9 with SMTP id f30-20020a63381e000000b003c6d5e4fed9mr11305562pga.553.1652305574817; Wed, 11 May 2022 14:46:14 -0700 (PDT) Received: from google.com ([2620:15c:211:201:69ef:9c87:7816:4f74]) by smtp.gmail.com with ESMTPSA id x18-20020a170902b41200b0015e8d4eb26asm2345293plr.180.2022.05.11.14.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 14:46:14 -0700 (PDT) Date: Wed, 11 May 2022 14:46:12 -0700 From: Minchan Kim To: John Hubbard Cc: Andrew Morton , linux-mm , LKML , "Paul E . McKenney" , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: References: <20220510211743.95831-1-minchan@kernel.org> <857d21da-5de2-fa3e-b1ce-41cc1cfb0191@nvidia.com> <2ffa7670-04ea-bb28-28f8-93a9b9eea7e8@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2ffa7670-04ea-bb28-28f8-93a9b9eea7e8@nvidia.com> X-Stat-Signature: wy7mxkkkgs8upbz8hd96ceu8rxo765tc X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8D080C00A2 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JBqMvOVB; spf=pass (imf28.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=minchan.kim@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Rspam-User: X-HE-Tag: 1652305555-915871 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, May 10, 2022 at 09:32:05PM -0700, John Hubbard wrote: > On 5/10/22 17:09, Minchan Kim wrote: > > On Tue, May 10, 2022 at 04:58:13PM -0700, John Hubbard wrote: > > > On 5/10/22 4:31 PM, Minchan Kim wrote: > > > > > > + int __mt = get_pageblock_migratetype(page); > > > > > > + int mt = __READ_ONCE(__mt); > > > > > > > > > > Although I saw the email discussion about this in v2, that discussion > > > > > didn't go far enough. It started with "don't use volatile", and went > > > > > on to "try __READ_ONCE() instead", but it should have continued on > > > > > to "you don't need this at all". > > > > > > > > That's really what I want to hear from experts so wanted to learn > > > > "Why". How could we prevent refetching of the mt if we don't use > > > > __READ_ONCE or volatile there? > > > > > > > > > > > > > > Because you don't. There is nothing you are racing with, and adding > > > > > __READ_ONCE() in order to avoid a completely not-going-to-happen > > > > > compiler re-invocation of a significant code block is just very wrong. > > > > > > > > > > So let's just let it go entirely. :) > > > > > > > > Yeah, once it's clear for everyone, I am happy to remove the > > > > unnecessary lines. > > > > > > > > > > > > > > > + > > > > > > + if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) > > > > > > > > > > > With or without __READ_ONCE() or volatile or anything else, > > > this code will do what you want. Which is: loosely check > > > for either of the above. > > > > > > What functional problem do you think you are preventing > > > with __READ_ONCE()? Because I don't see one. > > > > I discussed the issue at v1 so please take a look. > > > > https://lore.kernel.org/all/YnFvmc+eMoXvLCWf@google.com/ > > I read that, but there was never any real justification there for needing > to prevent a re-read of mt, just a preference: "I'd like to keep use the local > variable mt's value in folloing conditions checks instead of refetching > the value from get_pageblock_migratetype." > > But I don't believe that there is any combination of values of mt that > will cause a problem here. > > I also think that once we pull in experts, they will tell us that the > compiler is not going to re-run a non-trivial function to re-fetch a > value, but I'm not one of those experts, so that's still arguable. But > imagine what the kernel code would look like if every time we call > a large function, we have to consider if it actually gets called some > arbitrary number of times, due to (anti-) optimizations by the compiler. > This seems like something that is not really happening. Maybe, I might be paranoid since I have heard too subtle things about how compiler could changes high level language code so wanted be careful especially when we do lockless-stuff. Who cares when we change the large(?) function to small(?) function later on? I'd like to hear from experts to decide it.