Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp239413rdb; Mon, 22 Jan 2024 19:33:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0b4w3wZHwal5ScTAhPnCU3OSgdHVZBqXqOn/GVDcjk/tie/OQTVJdGlMIslmJ4PPKmh1U X-Received: by 2002:ad4:5e8b:0:b0:686:9658:996e with SMTP id jl11-20020ad45e8b000000b006869658996emr349486qvb.4.1705980805650; Mon, 22 Jan 2024 19:33:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705980805; cv=pass; d=google.com; s=arc-20160816; b=yJC2vMM6PGh2Hucb3/WSJFatmGH9CIV4NdxVPIRW4CMeW8b9xfjMfSJruor6hRHO9g +WiphT3h/YR6AA5zvQSbRW7+nRSgnljlC17c2Ba/26JEF6MCWn7dT27//uL1N7BMgg8O 8cWLLmeklOETF+E2aE4CxoZSaKGGIYhX9l8nRXJ77hPHp5gWwKewloHGbSUbzbaK7G+y +VfKg1OhM7GaTQD4L4K19lPSpzeFHaWv0vkXkKiTZAMmtRDfLEDjXRoQ8oOdtcnly+st NSEynGAo04z2DV0JZC0mI2YsyXVi3bkwrVSkM5wIfg3i7iuLy+3IrFWDMvkIJ47IT+JJ Nt/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=dGyLFiCSPKnOgt2WMLCtOYKgq5Jt8mMSuChCnDpw3sE=; fh=YoN4g1q2NL0rglg48ZvgeNaoNEl6wZNJLSli3RL3QUs=; b=wEAvBEhBU8ibJWCErN4FD4wxWD68k2IfXOoOK87GqUqPEOC5UnVBsujVbqbSbUD9nt hb+B6IS0fETO5WVqcDXy0gnwHcWK0scKhREcv9vU0X+um3e8Sx6U9GcvVWEJBPgMA87Q ELmhrQ83hK6cMa2BTft9PmnsKuTfJZ24SJ6fhQG+3ymRZppy9w/qge3ssTs1G8tSiKfi /KYz6wZ3rKr5iNEOsHutqh8/KelwsErQ/tT2zc6u/NKRaIq3Xd1Cn6X9YfQYdTGhaFEy w2MVegG5z+7xTkl23hsHpU/cNOd8j2/z3CYEv+s2MMSvxdKVcre+5FBgkBBhCjuGBWb1 AJ3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hDdILOnH; 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-34679-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34679-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 g18-20020a0cdf12000000b006816df533casi7126752qvl.307.2024.01.22.19.33.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:33:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34679-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=hDdILOnH; 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-34679-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34679-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 67EA11C24B3E for ; Tue, 23 Jan 2024 03:33:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEC202107; Tue, 23 Jan 2024 03:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hDdILOnH" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 03A0A1FAD for ; Tue, 23 Jan 2024 03:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980797; cv=none; b=MuIF7YNy4pO8QtnzsrFmcXqg+uySr1KuaXH4ngW1u8oOV5zGj0TeYKigHOUFg5xt9/9Su/dqTSX+C+rk+k+Xhj3XNBj1iagWoKkEyzYNhGSaHYZOsMjcOChus40bWoHzXcVqjlD7h2cIiD2mREa34vFcA5nf5xgTv3k/uXf5zSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980797; c=relaxed/simple; bh=dY0b4QbqepYoiunrDJoruXQx54evIQWDoFF8FO6Rtd8=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=GkPltXN/5rQlv+BTexdT5BTG91qzmnYlkEcMnuyoinOBpfbSTLF5YUlqn+rFcx2MOU4Jl3P+od/CsvClxZJF4M9s9+LEuH71iaMuX3+O0ph04Qpja9NL4aAl2l249tOjnUzEn71uppTQ7N7zrAKyRCEPd29aBK3hQWRwLb4+tAQ= 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=hDdILOnH; arc=none smtp.client-ip=95.215.58.185 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 Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705980793; 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=dGyLFiCSPKnOgt2WMLCtOYKgq5Jt8mMSuChCnDpw3sE=; b=hDdILOnHa8NAGzybj5naIfs7XhsW6yGVUI0mLp3wSur97OZeZCcTf+GNMtuTZh9YvMngVg jH6zVoGsuSW/BEOdpXQ62XSPAsc29ZSZAoayO48d+pFWjEx09xuqfulfmjMrTs6gFDJW82 zNGhPQjLUXBQ+TnbaAac7FitvyZV7dE= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Subject: Re: [PATCH v4 6/7] hugetlb: parallelize 2M hugetlb allocation and initialization X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <829fb129-f643-4960-a2da-cd38e5ee8f39@linux.dev> Date: Tue, 23 Jan 2024 11:32:28 +0800 Cc: David Hildenbrand , David Rientjes , Mike Kravetz , Andrew Morton , Tim Chen , Linux-MM , LKML , Gang Li Content-Transfer-Encoding: quoted-printable Message-Id: References: <20240118123911.88833-1-gang.li@linux.dev> <20240118123911.88833-7-gang.li@linux.dev> <14e38e95-2bc6-4571-b502-4e3954b4bcc4@linux.dev> <849D7EA4-BCF4-4587-8A78-F3B35B63EAE9@linux.dev> <829fb129-f643-4960-a2da-cd38e5ee8f39@linux.dev> To: Gang Li X-Migadu-Flow: FLOW_OUT > On Jan 23, 2024, at 10:12, Gang Li wrote: >=20 > On 2024/1/22 19:30, Muchun Song wrote: >>> On Jan 22, 2024, at 18:12, Gang Li wrote: >>>=20 >>> On 2024/1/22 15:10, Muchun Song wrote:> On 2024/1/18 20:39, Gang Li = wrote: >>>>> +static void __init hugetlb_alloc_node(unsigned long start, = unsigned long end, void *arg) >>>>> { >>>>> - unsigned long i; >>>>> + struct hstate *h =3D (struct hstate *)arg; >>>>> + int i, num =3D end - start; >>>>> + nodemask_t node_alloc_noretry; >>>>> + unsigned long flags; >>>>> + int next_node =3D 0; >>>> This should be first_online_node which may be not zero. >>>=20 >>> That's right. Thanks! >>>=20 >>>>> - for (i =3D 0; i < h->max_huge_pages; ++i) { >>>>> - if (!alloc_bootmem_huge_page(h, NUMA_NO_NODE)) >>>>> + /* Bit mask controlling how hard we retry per-node = allocations.*/ >>>>> + nodes_clear(node_alloc_noretry); >>>>> + >>>>> + for (i =3D 0; i < num; ++i) { >>>>> + struct folio *folio =3D alloc_pool_huge_folio(h, = &node_states[N_MEMORY], >>>>> + &node_alloc_noretry, &next_node); >>>>> + if (!folio) >>>>> break; >>>>> + spin_lock_irqsave(&hugetlb_lock, flags); >>>>> I suspect there will more contention on this lock when = parallelizing. >>>=20 >>> In the worst case, there are only 'numa node number' of threads in >>> contention. And in my testing, it doesn't degrade performance, but >>> rather improves performance due to the reduced granularity. >> So, the performance does not change if you move the lock out of >> loop? >>=20 >=20 > If we move the lock out of loop, then multi-threading becomes = single-threading, which definitely reduces performance. No. I mean batching the pages into pool list just like = prep_and_add_allocated_folios does. >=20 > ``` > + spin_lock_irqsave(&hugetlb_lock, flags); > for (i =3D 0; i < num; ++i) { > struct folio *folio =3D alloc_pool_huge_folio(h, = &node_states[N_MEMORY], > &node_alloc_noretry, = &next_node); > if (!folio) > break; > - spin_lock_irqsave(&hugetlb_lock, flags); > __prep_account_new_huge_page(h, folio_nid(folio)); > enqueue_hugetlb_folio(h, folio); > - spin_unlock_irqrestore(&hugetlb_lock, flags); > cond_resched(); > } > + spin_unlock_irqrestore(&hugetlb_lock, flags); > } > ```