Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp191910lfo; Tue, 17 May 2022 21:54:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgD1lcuHG94L/z9l3D7AMMpgjX01WKkgxgDJpt0IKNRrYXPYVZysKGFd2lE0f6f2ev6P+B X-Received: by 2002:a17:90b:380f:b0:1dc:596c:bb0 with SMTP id mq15-20020a17090b380f00b001dc596c0bb0mr40067251pjb.212.1652849665938; Tue, 17 May 2022 21:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652849665; cv=none; d=google.com; s=arc-20160816; b=UMXc30Z3mVxWWVY5si7d9KfbeXvxTtZ5/YEYkoi4KGnVuO76+QrNSTzSghrwFbJgbK gqquQMtpjpvroWmysvwBuY3olTEVufiG6B9QqpHExPeZy03z5fKCOrhtJwhVkG1gnRQp LDW+1W8Lp2XnNw0Mn04dvWIflDfvvZWfFo7I/oAwiW5SB60R0nGskIP6p31IfngU/U7S hk36bJ8DuxTW29z7V/8WwIYpNPvKc3Ot21rKuilYhqTMEJIlDRQqN4tz0jTsB84GRWmM G3MIZBeu/azskUZceGBLc+KXFpfaWI1pTXuTgnZi3oNtzlzZO10mv3CMk10cvf5Zl8Lk 7N/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/MwsWMteoBW+4/j8srpBSGX4SxYxtrIV85OC3p6eyjA=; b=NavtD4ruHib/Pkt3Ye695QR/p7lNZg5ETp0oBfF3Dc7exRNIMLw2JiplX5QJ0mLnH/ tmFoz2LKKcsTeFHw+V1ZKoRyPzILXY5CkLfe7EhQ+OwJodfVdDZF1HPWxDBnPIT+O7Re x1sCOvt9ZNtbJfOtVve+ivyLEOErEd2ogOjCWmU/85NjJNZv0eRBPIXgy+zsefMuaFnq f+M2AdlGdl+FPf2fGs4+fYeM01saTsshS4g6hdtVly1ByPWerzD50hI73JY84iDlNthD 4Pm3G7+V4s+P2XVbPo1lzNCJ5zXoeoPd56t4aY6BaCzQkrMdq4zO2odus1cPGfKtjTqR efHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=SRItJRyD; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d130-20020a633688000000b003db6063f3d3si1521578pga.366.2022.05.17.21.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:54:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=SRItJRyD; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B77E13FD4C; Tue, 17 May 2022 21:03:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243432AbiEQOA6 (ORCPT + 99 others); Tue, 17 May 2022 10:00:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243926AbiEQOAx (ORCPT ); Tue, 17 May 2022 10:00:53 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA6CFE6 for ; Tue, 17 May 2022 07:00:51 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id x9so14347969qts.6 for ; Tue, 17 May 2022 07:00:51 -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=iGflCfgnTIHf3yIFYlWTn1KlkdcqT0Hhqw0YW24TnSLqBD2Z98ywQTYOCiiM9vvaAI gltJG9l7KgsHB0uNeNdz+3sJo1gq0TLfWpoaWYDsUThop0VKfqHXi/ZOikf+qNtVv6+D xZqxiGWq9pd294MdFy2FMNsNWXWVPlRRl4IaB32ug0UuFl/oRuHpHlBOugMm/RkfIlQo BwlLvHKy4Rx7XppPH1XFGAknzUcoNap6v59xB68/3MK3p5lfZ1PF42ydZwePS8mAQCE6 8xq7sfJ+w31Mp5TfUp9wuQfGGa+r5RrnQI+rA+kZpS+vCJLxpen7DgYVZ5avlQJ2EBK6 wwuA== X-Gm-Message-State: AOAM5304uKSqKj201IvCpQeN6sKDIag0Jbh6WbuzcAO6sD8moiQLBlNW LqKqIc7SlYSMn5pOBEcg6pPjUQ== 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-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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