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 270C7C433F5 for ; Tue, 17 May 2022 14:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA816B0072; Tue, 17 May 2022 10:00:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8628D6B0073; Tue, 17 May 2022 10:00:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B5BB6B0074; Tue, 17 May 2022 10:00:56 -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 570436B0072 for ; Tue, 17 May 2022 10:00:56 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2E9DC2118B for ; Tue, 17 May 2022 14:00:56 +0000 (UTC) X-FDA: 79475396112.25.F86929A Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf08.hostedemail.com (Postfix) with ESMTP id C170D1600F2 for ; Tue, 17 May 2022 14:00:35 +0000 (UTC) Received: by mail-qt1-f178.google.com with SMTP id p4so14312880qtq.12 for ; Tue, 17 May 2022 07:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/MwsWMteoBW+4/j8srpBSGX4SxYxtrIV85OC3p6eyjA=; b=SRItJRyDmSjb0OAm1/Lj+Tmcc0pWAEDI0PlR0ySs940MEM69mMnJz8xDpjW03V7A2f 5rrUNkOAJphHo45pfgZXBjaZcPXb/A4mferWbN3eusBlhhDMgp9ghXKbxKID/N2z5diO cNiJRsfmF12/OI8vuIPV6mNTt2TfF24j9zjpPGTm5AMjWs1PAaudbYVgxBVq/lS87sfV 0UbVb0THn66XMk+3fcmzQGb6OE1i0MZIQeWHoR/xlX04t2xol3YcFIMDq9XaZ/tIqQwY 3T0Zx4cPq5pyu8i/7m2hCWm0CMsXshb7sLGQUyYK1NkcGC0jGmZ1e84QaaBv9TjifQrs qWFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/MwsWMteoBW+4/j8srpBSGX4SxYxtrIV85OC3p6eyjA=; b=lglrVLORIGyW8PFroDkDPPX/ZO2uU3ly/MnlAc1T5rqx2ccMNBlHvCHQKYrFguNW5q Kf4wpu4BJeBQ8hritpO0p70THV27MvBdhn9i5pufqVsf/MOU2NQPG3NN9/WDMWCaQO+M kjwJyVUD7Aq5yrGOqlWNvn4D+SvdPaKVOzcUOJhh6ExnBxTJX55rQMp3LvGtpaigk6uD d2QU8esrXLvzCAOMJfigRV9zQF2GANKIHKrRWthqh6XsXsdMFrlLwYu0M7sWcyL6S0oA YI6dLPDLKmu/RuYMFWYlInQEYqmvZ/1b1DUDMXKlEJUzZP3vOd4gyq87shXLbxbRbtd9 FWCA== X-Gm-Message-State: AOAM531HLYCWi0KXc7d9bo5lEpHLidGGWKfyeVpunyV3Gyy7w3Jn91fU RbR55NBiQStnZ0gCkFqRtnLqjg== X-Google-Smtp-Source: ABdhPJweSJXOQL3TpRAb7UibqsGcu+1c3zZZyxmp7gBl2Tw5hA/HKnbgypl+VfW3Sv5BJdCnjrPXCQ== X-Received: by 2002:ac8:7f46:0:b0:2f3:cd89:8ee0 with SMTP id g6-20020ac87f46000000b002f3cd898ee0mr19622801qtk.498.1652796050708; Tue, 17 May 2022 07:00:50 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id bb30-20020a05622a1b1e00b002f39b99f6bfsm7916712qtb.89.2022.05.17.07.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 07:00:49 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1nqxkn-0083Q2-7j; Tue, 17 May 2022 11:00:49 -0300 Date: Tue, 17 May 2022 11:00:49 -0300 From: Jason Gunthorpe To: Minchan Kim Cc: John Hubbard , "Paul E. McKenney" , Andrew Morton , linux-mm , LKML , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: <20220517140049.GF63055@ziepe.ca> References: <0d90390c-3624-4f93-f8bd-fb29e92237d3@nvidia.com> <20220512002207.GJ1790663@paulmck-ThinkPad-P17-Gen-1> <20220512004949.GK1790663@paulmck-ThinkPad-P17-Gen-1> <0accce46-fac6-cdfb-db7f-d08396bf9d35@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: jqi4mwae8zzffap3t4w37h16m9ai3kc9 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=SRItJRyD; spf=pass (imf08.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.160.178 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C170D1600F2 X-HE-Tag: 1652796035-246825 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000381, 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 08:44:43PM -0700, Minchan Kim wrote: > On Wed, May 11, 2022 at 07:18:56PM -0700, John Hubbard wrote: > > On 5/11/22 18:08, John Hubbard wrote: > > > On 5/11/22 18:03, Minchan Kim wrote: > > > > > > > > > > Or there might be some code path that really hates a READ_ONCE() in > > > > > that place. > > > > > > > > My worry about chaning __get_pfnblock_flags_mask is it's called > > > > multiple hot places in mm codes so I didn't want to add overhead > > > > to them. > > > > > > ...unless it really does generate the same code as is already there, > > > right? Let me check that real quick. > > > > > > > It does change the generated code slightly. I don't know if this will > > affect performance here or not. But just for completeness, here you go: > > > > free_one_page() originally has this (just showing the changed parts): > > > > mov 0x8(%rdx,%rax,8),%rbx > > and $0x3f,%ecx > > shr %cl,%rbx > > and $0x7, > > > > > > And after applying this diff: > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 0e42038382c1..df1f8e9a294f 100644 > > +++ b/mm/page_alloc.c > > @@ -482,7 +482,7 @@ unsigned long __get_pfnblock_flags_mask(const struct > > page *page, > > word_bitidx = bitidx / BITS_PER_LONG; > > bitidx &= (BITS_PER_LONG-1); > > > > - word = bitmap[word_bitidx]; > > + word = READ_ONCE(bitmap[word_bitidx]); > > return (word >> bitidx) & mask; > > } > > > > > > ...it now does an extra memory dereference: > > > > lea 0x8(%rdx,%rax,8),%rax > > and $0x3f,%ecx > > mov (%rax),%rbx > > shr %cl,%rbx > > and $0x7,%ebx Where is the extra memory reference? 'lea' is not a memory reference, it is just some maths? > Thanks for checking, John. > > I don't want to have the READ_ONCE in __get_pfnblock_flags_mask > atm even though it's an extra memory dereference for specific > architecutre and specific compiler unless other callsites *do* > need it. If a callpath is called under locking or not under locking then I would expect to have two call chains clearly marked what their locking conditions are. ie __get_pfn_block_flags_mask_unlocked() - and obviously clearly document and check what the locking requirements are of the locked path. IMHO putting a READ_ONCE on something that is not a memory load from shared data is nonsense - if a simple == has a stability risk then so does the '(word >> bitidx) & mask'. Jason