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 X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F41CC433DB for ; Tue, 23 Mar 2021 08:01:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DCC5D619BB for ; Tue, 23 Mar 2021 08:01:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCC5D619BB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2878E6B011F; Tue, 23 Mar 2021 04:01:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 237356B0121; Tue, 23 Mar 2021 04:01:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D8C26B0123; Tue, 23 Mar 2021 04:01:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id E62506B011F for ; Tue, 23 Mar 2021 04:01:19 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A249012D4 for ; Tue, 23 Mar 2021 08:01:19 +0000 (UTC) X-FDA: 77950393878.29.DFE1AF0 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf25.hostedemail.com (Postfix) with ESMTP id 013EC6000102 for ; Tue, 23 Mar 2021 08:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lx3J6Y5Q3le0nZDa4hURyeJThg9+xLXsxyVyB1tvv0U=; b=h+sXw7FNjiA7THYFgpctWo8GVv a0g9V03KoAnatTs0p68hMqbimfiJY5KD2IJxzSedlDb/cRXM5V7NzIIKZ37XXHDZFT4Z2OnhQNDNf V2Jiq8jRYE4llLIrHlQEWHZOIPNCgvqFli6upWuhw+mZlm7vcZ/hhVvNXgtuHJoZgHVJj0VlLcg/C e1laS1PPsC5sVIYLRgukn1ysJOb/1yPX1ThzPImbhxGn43E0U8DlP/64dG/2kbR8wQngDhefR3yNm cMz6RbI8wwOCQJX/PY18/tRE9CZKzix5OYMW+eE7hN14hWbsZo5X5TwHkuHZYzVyirRFPSrpP04po d1sPhz4A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lObyN-00EFl3-54; Tue, 23 Mar 2021 08:01:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5C63C3010C8; Tue, 23 Mar 2021 09:01:03 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F343A2053DA99; Tue, 23 Mar 2021 09:01:02 +0100 (CET) Date: Tue, 23 Mar 2021 09:01:02 +0100 From: Peter Zijlstra To: Michal Hocko Cc: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt , Oscar Salvador , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Andrew Morton Subject: Re: [RFC PATCH 2/8] hugetlb: recompute min_count when dropping hugetlb_lock Message-ID: References: <20210319224209.150047-1-mike.kravetz@oracle.com> <20210319224209.150047-3-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: csjyhwow587xzgbd9xwr86quubd7mkrh X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 013EC6000102 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from=""; helo=desiato.infradead.org; client-ip=90.155.92.199 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616486477-123653 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, Mar 23, 2021 at 08:50:53AM +0100, Michal Hocko wrote: > > >> +static inline unsigned long min_hp_count(struct hstate *h, unsigned long count) > > >> +{ > > >> + unsigned long min_count; > > >> + > > >> + min_count = h->resv_huge_pages + h->nr_huge_pages - h->free_huge_pages; > > >> + return max(count, min_count); > > > > > > Just out of curiousity, is compiler allowed to inline this piece of code > > > and then cache the value? In other words do we need to make these > > > READ_ONCE or otherwise enforce the no-caching behavior? > > > > I honestly do not know if the compiler is allowed to do that. The > > assembly code generated by my compiler does not cache the value, but > > that does not guarantee anything. I can add READ_ONCE to make the > > function look something like: > > > > static inline unsigned long min_hp_count(struct hstate *h, unsigned long count) > > { > > unsigned long min_count; > > > > min_count = READ_ONCE(h->resv_huge_pages) + READ_ONCE(h->nr_huge_pages) > > - READ_ONCE(h->free_huge_pages); > > return max(count, min_count); > > } > > Maybe just forcing to never inline the function should be sufficient. > This is not a hot path to micro optimize for no function call. But there > are much more qualified people on the CC list on this matter who could > clarify. Peter? I'm not sure I understand the code right. But inline or not doesn't matter, LTO completely ruins that game. Just like if it was a static function, then the compiler is free to inline it, even if the function lacks an inline attribute. Basically, without READ_ONCE() the compiler is allowed to entirely elide the load (and use a previous load), or to duplicate the load and do it again later (reaching a different result). Similarly, the compiler is allowed to byte-wise load the variable in any random order and re-assemble. If any of that is a problem, you have to use READ_ONCE().