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 39A51C433EF for ; Thu, 12 May 2022 00:27:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DFF06B0074; Wed, 11 May 2022 20:26:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98C736B0075; Wed, 11 May 2022 20:26:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82D686B0078; Wed, 11 May 2022 20:26:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 73F536B0074 for ; Wed, 11 May 2022 20:26:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3519E20A6E for ; Thu, 12 May 2022 00:26:59 +0000 (UTC) X-FDA: 79455200958.08.0F02151 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf11.hostedemail.com (Postfix) with ESMTP id BB7D8400A3 for ; Thu, 12 May 2022 00:26:53 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id iq10so3732370pjb.0 for ; Wed, 11 May 2022 17:26:58 -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:content-transfer-encoding:in-reply-to; bh=lSOQOgP92/YiU5VAWj+NdXGc95/DnozpR5AdrSptpI4=; b=nj48KdFh+/sfMu3rISqNM01K4uo221UQg9EECYj9I1566x6pbwZ2im6XJF1nepDYAR rAS1n9HuNI+9hF04K4JpP2/eftkYUUNbN9BhUht3NRASeQ136OfBwoQBHzoCUD29mOXX c0P2aAmQdLPSObjwvEzC+qqDiOo9GskHVMz51V3OvVdhdrZFbUcw9YJJRHB7hUUNDMiK tSWV01HrIsISPKBi90rk4a7dgXhLP6d4mfqxDvBM9Y3gFGU0zfLhimu8NYEO2/SgyeVP ul/LtTlNBnN6zwuJz9kni2nCqJ0V8JnFtjWJPcfpdYuxqbeKnAGPl8/Lu1wwVAqxzyYl csTQ== 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 :content-transfer-encoding:in-reply-to; bh=lSOQOgP92/YiU5VAWj+NdXGc95/DnozpR5AdrSptpI4=; b=rxF6XzPuGuRiQkhpFZUTzInPxtvkrC2XE4c6l1glANcNXe6SuauApJ1kbru/1QRzaC zHSPCw39vF6RxPsWs+bf7kcK4GNbwSI+0icf6FZM2g94TsGFXjMjpKK323cQGbvgdiPA 0oqRWrsL9E7cDBOsljcMB6DvbyKx1MrUTTZ7WEzRALd1wueKVpjSP+revXlSxuxelBMg wllw05qT3VcGgxHcvUkk9IqPIAiLemGXjDMdWQtrSdlGsheRTx476bi2bz/CoBbR2jLv 0RlKmTEcmf4eBYTWSW5LBYy4iYA+tjn3XxL2azCpvWTGfjhr7kHwtVCaWsz5C5lmePI2 rP7w== X-Gm-Message-State: AOAM532QDMUG5N7BFSjbHzfjFVESzpTGlf+KA4EHrDWVrHo8p9vlr2FO ecQUcaGfnT/NcD5I9Uqv9HM= X-Google-Smtp-Source: ABdhPJyh51RrSZyzGueYZU+R57NkHQ8GfEjV+AaZcM12tnOzVv5rZ2hD+66yclGja+Q1K83BPJkE4Q== X-Received: by 2002:a17:90b:4a84:b0:1dc:67e9:a92c with SMTP id lp4-20020a17090b4a8400b001dc67e9a92cmr7878081pjb.141.1652315217763; Wed, 11 May 2022 17:26:57 -0700 (PDT) Received: from google.com ([2620:15c:211:201:69ef:9c87:7816:4f74]) by smtp.gmail.com with ESMTPSA id d6-20020a170902654600b0015f44241a31sm77278pln.110.2022.05.11.17.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 17:26:57 -0700 (PDT) Date: Wed, 11 May 2022 17:26:55 -0700 From: Minchan Kim To: "Paul E. McKenney" Cc: John Hubbard , Andrew Morton , linux-mm , LKML , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: References: <54b5d177-f2f4-cef2-3a68-cd3b0b276f86@nvidia.com> <8f083802-7ab0-15ec-b37d-bc9471eea0b1@nvidia.com> <20220511234534.GG1790663@paulmck-ThinkPad-P17-Gen-1> <0d90390c-3624-4f93-f8bd-fb29e92237d3@nvidia.com> <20220512002207.GJ1790663@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220512002207.GJ1790663@paulmck-ThinkPad-P17-Gen-1> X-Stat-Signature: okb7pcahw3unmgty6y4z8mrdyc4hegri X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BB7D8400A3 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nj48KdFh; spf=pass (imf11.hostedemail.com: domain of minchan.kim@gmail.com designates 209.85.216.47 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: 1652315213-819086 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000156, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, May 11, 2022 at 05:22:07PM -0700, Paul E. McKenney wrote: > On Wed, May 11, 2022 at 05:12:32PM -0700, John Hubbard wrote: > > On 5/11/22 16:57, John Hubbard wrote: > > > On 5/11/22 16:45, Paul E. McKenney wrote: > > > > > > > > > > Well no, because the "&" operation is a single operation on the CPU, and > > > > > isn't going to get split up like that. > > > > > > > > Chiming in a bit late... > > > > > > Much appreciated! > > > > > > > > > > > The usual way that this sort of thing causes trouble is if there is a > > > > single store instruction that changes the value from MIGRATE_ISOLATE > > > > to MIGRATE_CMA, and if the compiler decides to fetch twice, AND twice, > > > > > > Doing an AND twice for "x & constant" this definitely blows my mind. Is > > > nothing sacred? :) > > > > > > > and then combine the results.  This could give a zero outcome where the > > > > underlying variable never had the value zero. > > > > > > > > Is this sort of thing low probability? > > > > > > > > Definitely. > > > > > > > > Isn't this sort of thing prohibited? > > > > > > > > Definitely not. > > > > > > > > So what you have will likely work for at least a while longer, but it > > > > is not guaranteed and it forces you to think a lot harder about what > > > > the current implementations of the compiler can and cannot do to you. > > > > > > > > The following LWN article goes through some of the possible optimizations > > > > (vandalisms?) in this area: https://lwn.net/Articles/793253/ > > > > > > > > > > hmm, I don't think we hit any of those  cases, do we? Because here, the > > > "write" side is via a non-inline function that I just don't believe the > > > compiler is allowed to call twice. Or is it? > > > > > > Minchan's earlier summary: > > > > > > CPU 0                         CPU1 > > > > > > > > >                               set_pageblock_migratetype(MIGRATE_ISOLATE) > > > > > > if (get_pageblock_migrate(page) & MIGRATE_CMA) > > > > > >                               set_pageblock_migratetype(MIGRATE_CMA) > > > > > > if (get_pageblock_migrate(page) & MIGRATE_ISOLATE) > > > > > > ...where set_pageblock_migratetype() is not inline. > > > > > > thanks, > > > > Let me try to say this more clearly: I don't think that the following > > __READ_ONCE() statement can actually help anything, given that > > get_pageblock_migratetype() is non-inlined: > > > > + int __mt = get_pageblock_migratetype(page); > > + int mt = __READ_ONCE(__mt); > > + > > + if (mt & (MIGRATE_CMA | MIGRATE_ISOLATE)) > > + return false; > > > > > > Am I missing anything here? > > In the absence of future aggression from link-time optimizations (LTO), > you are missing nothing. A thing I want to note is Android kernel uses LTO full mode.