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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 250EFC433DB for ; Tue, 23 Mar 2021 07:50:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B21A7619BA for ; Tue, 23 Mar 2021 07:50:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B21A7619BA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 467476B0115; Tue, 23 Mar 2021 03:50:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 418A76B0118; Tue, 23 Mar 2021 03:50:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 291566B011B; Tue, 23 Mar 2021 03:50:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 0A8666B0115 for ; Tue, 23 Mar 2021 03:50:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C6C093650 for ; Tue, 23 Mar 2021 07:50:56 +0000 (UTC) X-FDA: 77950367712.18.4FE3240 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf30.hostedemail.com (Postfix) with ESMTP id 1B622E0011C0 for ; Tue, 23 Mar 2021 07:50:54 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616485855; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=em7Mh7/jQWzjXPLfUlB2ichd+yqNpORfvlzy4NL7PTA=; b=nt2HsBEutCp/U6FFk2o0sbIdvI7VjPWT7lXr9Ob/Z7aFG1mjuBouljptVTJBrt4rrsOxdP 4U8Q+tc/+QvsdzYycsbpXVKH3wabSciQ5xVDgs0UsWoc58tYtAM55bS010lDG1okEWExYy tF1vbLSEzVS4gWN7xSkcx4qXUi0ZmNk= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 185A8AB8A; Tue, 23 Mar 2021 07:50:55 +0000 (UTC) Date: Tue, 23 Mar 2021 08:50:53 +0100 From: Michal Hocko To: Mike Kravetz , Peter Zijlstra Cc: 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: kj59t75h8k8h6yccueoo7xgrbx6d5yyq X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1B622E0011C0 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616485854-473203 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 Mon 22-03-21 16:07:29, Mike Kravetz wrote: > On 3/22/21 7:07 AM, Michal Hocko wrote: > > On Fri 19-03-21 15:42:03, Mike Kravetz wrote: > >> The routine set_max_huge_pages reduces the number of hugetlb_pages, > >> by calling free_pool_huge_page in a loop. It does this as long as > >> persistent_huge_pages() is above a calculated min_count value. > >> However, this loop can conditionally drop hugetlb_lock and in some > >> circumstances free_pool_huge_page can drop hugetlb_lock. If the > >> lock is dropped, counters could change the calculated min_count > >> value may no longer be valid. > > > > OK, this one looks like a real bug fix introduced by 55f67141a8927. > > Unless I am missing something we could release pages which are reserved > > already. > > > >> The routine try_to_free_low has the same issue. > >> > >> Recalculate min_count in each loop iteration as hugetlb_lock may have > >> been dropped. > >> > >> Signed-off-by: Mike Kravetz > >> --- > >> mm/hugetlb.c | 25 +++++++++++++++++++++---- > >> 1 file changed, 21 insertions(+), 4 deletions(-) > >> > >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c > >> index d5be25f910e8..c537274c2a38 100644 > >> --- a/mm/hugetlb.c > >> +++ b/mm/hugetlb.c > >> @@ -2521,11 +2521,20 @@ static void __init report_hugepages(void) > >> } > >> } > >> > >> +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? -- Michal Hocko SUSE Labs