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=-13.8 required=3.0 tests=BAYES_00, 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 9FB29C433DB for ; Thu, 25 Mar 2021 12:29:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2552C61A13 for ; Thu, 25 Mar 2021 12:29:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2552C61A13 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 94AC06B0070; Thu, 25 Mar 2021 08:29:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9217D6B0071; Thu, 25 Mar 2021 08:29:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8102F6B0072; Thu, 25 Mar 2021 08:29:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 6880A6B0070 for ; Thu, 25 Mar 2021 08:29:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2C03F882F465 for ; Thu, 25 Mar 2021 12:29:47 +0000 (UTC) X-FDA: 77958328014.25.ECED814 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf24.hostedemail.com (Postfix) with ESMTP id A5B76A000253 for ; Thu, 25 Mar 2021 12:29:44 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6B21FAC16; Thu, 25 Mar 2021 12:29:45 +0000 (UTC) Date: Thu, 25 Mar 2021 13:29:40 +0100 From: Oscar Salvador To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Roman Gushchin , Michal Hocko , Shakeel Butt , David Hildenbrand , Muchun Song , David Rientjes , Miaohe Lin , Peter Zijlstra , Matthew Wilcox , HORIGUCHI NAOYA , "Aneesh Kumar K . V" , Waiman Long , Peter Xu , Mina Almasry , Hillf Danton , Andrew Morton Subject: Re: [PATCH 3/8] hugetlb: add per-hstate mutex to synchronize user adjustments Message-ID: References: <20210325002835.216118-1-mike.kravetz@oracle.com> <20210325002835.216118-4-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210325002835.216118-4-mike.kravetz@oracle.com> X-Stat-Signature: 5mqfmise9uo3g7a5h8ipbia5uiwd66ua X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A5B76A000253 Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1616675384-326565 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 Wed, Mar 24, 2021 at 05:28:30PM -0700, Mike Kravetz wrote: > The helper routine hstate_next_node_to_alloc accesses and modifies the > hstate variable next_nid_to_alloc. The helper is used by the routines > alloc_pool_huge_page and adjust_pool_surplus. adjust_pool_surplus is > called with hugetlb_lock held. However, alloc_pool_huge_page can not > be called with the hugetlb lock held as it will call the page allocator. > Two instances of alloc_pool_huge_page could be run in parallel or > alloc_pool_huge_page could run in parallel with adjust_pool_surplus > which may result in the variable next_nid_to_alloc becoming invalid > for the caller and pages being allocated on the wrong node. Is this something you have seen happening? If so, it is easier to trigger? I doubt so as I have not seen any bug report, but just wondering whether a Fixes tag is needed, or probably not worth, right? > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -566,6 +566,7 @@ HPAGEFLAG(Freed, freed) > #define HSTATE_NAME_LEN 32 > /* Defines one hugetlb page size */ > struct hstate { > + struct mutex mutex; I am also with Michal here, renaming the mutex to something closer to its function might be better to understand it without diving too much in the code. > int next_nid_to_alloc; > int next_nid_to_free; > unsigned int order; > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index f9ba63fc1747..404b0b1c5258 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2616,6 +2616,8 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, > else > return -ENOMEM; > > + /* mutex prevents concurrent adjustments for the same hstate */ > + mutex_lock(&h->mutex); > spin_lock(&hugetlb_lock); I find above comment a bit misleading. AFAIK, hugetlb_lock also protects from concurrent adjustments for the same hstate (hugepage_activelist, free_huge_pages, surplus_huge_pages, etc...). Would it be more apropiate saying that mutex_lock() only prevents from simultaneously sysfs/proc operations? Reviewed-by: Oscar Salvador -- Oscar Salvador SUSE L3