Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp143640rdb; Sun, 21 Jan 2024 22:17:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZ+gU1WHvrkJDcp5DsuOGcmuDxQBWv+lpAW+oBcJbNssFDkCT092fyv2sFkwv3FgRh+Ly4 X-Received: by 2002:a05:622a:244:b0:42a:441b:ca93 with SMTP id c4-20020a05622a024400b0042a441bca93mr299404qtx.36.1705904237500; Sun, 21 Jan 2024 22:17:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705904237; cv=pass; d=google.com; s=arc-20160816; b=A+XhEP8IXIDao23TBHW6vZ2eZQHsgQghaYPCxaEDpgNgJaqigmNel1ikVEu/uIGALS E5kK3h5JGeT+Ap5UD2L9jBQuhc80/B0wn4zv/ItRu4vbHl4E5QmsHLDdp76LUGp6YEEn LCJgHj4yd4GvMsXwdu1yMUBSN326x0l7mm2mUcPmbC2s7uXlbfoG+VZ7oZ35bHbzz58R GsL4my1n77+k7379fSM8Bb725EnnAcV1GfOWuBQkKP6UKjZRZ6sTW9cL2GxsNZOk78/3 O/YcuL+lEZk2dmP4qpHU8/VXPC1w1bIa6m4N15bLPvCVlsoQaxXpm088LOiCbOvOKhE7 CSQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:dkim-signature:message-id; bh=8Pb80DoRWEyZoi0wqPXsfRRerxvgd/0OhZbYr/fDW1k=; fh=fe/c9hzSQFh7ilcieiwGGCtExCVyZxSDkymKHK6hSLM=; b=W3U58Xc1eufixvssbywrXXq2J7njqHpx8Y+LUHsq3H8069ohvu8D+MCBi3uRk26tKz +2eRVxgx9Ei10xRdVmbNrtAznNw2DgSGw7Xkd+oyBGd2XeKZHrxUcuFmKsTUb+ZYJMbD ACPajhJfz5CVt9sLH6zCCHS/VNWvD+OnYPMYz7um463fac4EFVzyc8sqseFmXzacZ0E/ H96VWiA6GfYE1LIgCn82Fxz6KOYGflwTLv8vwvF6sPk8kuZB/R6/IlTQqmZVm0CzfVFY ESCPKPsSix/GuVMz0rZ2Ce7ze83PKc1nxqcBJqAkWhDvP2qkcM0kp4/QYaXGAx9Jr+BE PG0Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Cv8EMnSK; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-32379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 9-20020ac85709000000b0042a32479b61si4120416qtw.556.2024.01.21.22.17.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 22:17:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Cv8EMnSK; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-32379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BB0831C2231F for ; Mon, 22 Jan 2024 06:16:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AE3463A6; Mon, 22 Jan 2024 06:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Cv8EMnSK" Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F70610C for ; Mon, 22 Jan 2024 06:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705904210; cv=none; b=FGneIkxqFzpg7GrIQdsrWBIfBmKv79DQuxswSqQ8329X0KlQIFp1+L5UiCdSm3DyK4tibg2aBiIAVbQVMUJ+2+MofsZMvvK2HieBn5dcwlhZdIX58evrQsqvaJVAJwOMzmuXXOfMvnQOoK5tqkVca5dG7+6m8/nTowChY4yesXI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705904210; c=relaxed/simple; bh=l6asL2N89M7lkNOnDBE2rHIir7CAoLNLt5T1osqgjv0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=OpzvsrkNbuT88GvOBd7bQkmTMmzyVNJ8Miq8nvzMR/ouiXhuzfGt96pOUA+jQBsPdJyyXSUD4/d1VO7BcHGghYzmodvcD5bMsb1CIRm99i6K5tH5D6vLpMG7WTN8o1jYwwQ2qz+rhfefBSvMl7ZtLgXVFN1JDQO5dUp3KlGcx7Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Cv8EMnSK; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705904205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Pb80DoRWEyZoi0wqPXsfRRerxvgd/0OhZbYr/fDW1k=; b=Cv8EMnSK34A8/z8rlXk13g6F0z8uk3JfdETFL7MOLnZgIcCjw4qv3uKqH8gA3DPi89fLWm kz+S8S+k58QCbd8m6mSfsPNA0gxiQDFtMTWT8QOj+34W6OGnudn9vUj0IGAiC0CwMFl+6g MQARgoJzjqEMSyHitrjFOE4E0nUVxkk= Date: Mon, 22 Jan 2024 14:16:30 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v4 4/7] hugetlb: pass *next_nid_to_alloc directly to for_each_node_mask_to_alloc To: Gang Li , David Hildenbrand , David Rientjes , Mike Kravetz , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com References: <20240118123911.88833-1-gang.li@linux.dev> <20240118123911.88833-5-gang.li@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20240118123911.88833-5-gang.li@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/1/18 20:39, Gang Li wrote: > With parallelization of hugetlb allocation across different threads, each > thread works on a differnet node to allocate pages from, instead of all > allocating from a common node h->next_nid_to_alloc. To address this, it's > necessary to assign a separate next_nid_to_alloc for each thread. > > Consequently, the hstate_next_node_to_alloc and for_each_node_mask_to_alloc > have been modified to directly accept a *next_nid_to_alloc parameter, > ensuring thread-specific allocation and avoiding concurrent access issues. > > Signed-off-by: Gang Li > Tested-by: David Rientjes > --- > mm/hugetlb.c | 22 ++++++++++++---------- > 1 file changed, 12 insertions(+), 10 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 98ae108e1fac..effe5539e545 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1464,15 +1464,15 @@ static int get_valid_node_allowed(int nid, nodemask_t *nodes_allowed) > * next node from which to allocate, handling wrap at end of node > * mask. > */ > -static int hstate_next_node_to_alloc(struct hstate *h, > +static int hstate_next_node_to_alloc(int *next_node, > nodemask_t *nodes_allowed) > { > int nid; > > VM_BUG_ON(!nodes_allowed); > > - nid = get_valid_node_allowed(h->next_nid_to_alloc, nodes_allowed); > - h->next_nid_to_alloc = next_node_allowed(nid, nodes_allowed); > + nid = get_valid_node_allowed(*next_node, nodes_allowed); > + *next_node = next_node_allowed(nid, nodes_allowed); > > return nid; > } > @@ -1495,10 +1495,10 @@ static int hstate_next_node_to_free(struct hstate *h, nodemask_t *nodes_allowed) > return nid; > } > > -#define for_each_node_mask_to_alloc(hs, nr_nodes, node, mask) \ > +#define for_each_node_mask_to_alloc(next_node, nr_nodes, node, mask) \ > for (nr_nodes = nodes_weight(*mask); \ > nr_nodes > 0 && \ > - ((node = hstate_next_node_to_alloc(hs, mask)) || 1); \ > + ((node = hstate_next_node_to_alloc(next_node, mask)) || 1); \ > nr_nodes--) > > #define for_each_node_mask_to_free(hs, nr_nodes, node, mask) \ > @@ -2350,12 +2350,13 @@ static void prep_and_add_allocated_folios(struct hstate *h, > */ > static struct folio *alloc_pool_huge_folio(struct hstate *h, > nodemask_t *nodes_allowed, > - nodemask_t *node_alloc_noretry) > + nodemask_t *node_alloc_noretry, > + int *next_node) > { > gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; > int nr_nodes, node; > > - for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { > + for_each_node_mask_to_alloc(next_node, nr_nodes, node, nodes_allowed) { A small question here, why not pass h->next_nid_to_alloc to for_each_node_mask_to_alloc()? What's the purpose of the third parameter of alloc_pool_huge_folio()? Thanks.