Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1213528rbb; Mon, 26 Feb 2024 02:20:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVipCuVy7Bhj3RMmUNjxtQDAUq97pzWXzDAZ1hQhxGpGx2y2LVN0crR0g1azuaXd/kAPE9yhirB0KXIUiDXpBEo5ieAyHd9OOoxgFb8+Q== X-Google-Smtp-Source: AGHT+IH1uavuL/YqXmsdoa9kfenNMDPiLi4lKIb6uj+C04Uwki43HwG3yam0dSxsA6DEIC2Vdp88 X-Received: by 2002:a05:6358:8015:b0:178:20ea:abb5 with SMTP id g21-20020a056358801500b0017820eaabb5mr7772519rwn.26.1708942809560; Mon, 26 Feb 2024 02:20:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708942809; cv=pass; d=google.com; s=arc-20160816; b=t62jCzHt2zoxStX5X2B8m4k80gyytuYJNx41iZJLHkUGwg6R4jbCXG3MpXzBa50q68 x42c7i04uM+oD3u9POUQFEMQVUkk/KvSniB2m1hZxbuM0ylqOLRQPADEghmALqDqpKdL NYjeb0BwqHd/765JRkZ9ax1ltP+rnqk9WiC5NpZPE/OFUqZZPwyXUe0M9qV13JGWKhNp oovesNTzDb14jZaoMbsVT8lEsryN2Y3eJSMHvJHnEBWJWobmzXiMWE0RTkLUB09Y5bez xdXeQAVyhEDD0+FmUqCoQ6cOQ2stbgpJlMyRrRlOp1EkxBZ/0JPCx9+CgRUzUeuSAIzz 2Gig== 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 :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=U3Y9+BuA9RX74PXr7GyTAAvmUXsvUnfoxwYUqPDTdvc=; fh=YPTNcFsvZ+O9XI4A4iW7fK5wftZqh1P5JrCFNuJgSaA=; b=kLJvB6EaoCYqWMuJ0kqaWU13M+B/p09mIW3kSuAMxRmCiXJsrTly0hFXSGw6CpiSo2 9vueaok14jY/7n/X83Yt2ksM1x5EeyFy1iYeEdrNROxFLbej4SeHEtNwJstUfBdr6zFa Cyv0Icry/L9ZbcGiuNGCQQx5Rz2CLUmWNmn1viKbEHM+dmy42iJaGPk70X5M/wqLWC96 w0nh6EVABqQRTBk7l/dKEvL4rklZnSMMa7vFawvtV2JL/i61WKz0R6t0Suvq4ZKpTkdh 3fIwluq504ofi858//tyeEwKVmQoKfis4crgn9b8NbnixePpuEyEH0yXbnBrPWciu5Kk 0EMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=FwzPtilE; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-81123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81123-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 73-20020a63004c000000b005dc927ee328si3392968pga.662.2024.02.26.02.20.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 02:20:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=FwzPtilE; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-81123-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81123-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3B9D9289880 for ; Mon, 26 Feb 2024 10:20:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 078E453372; Mon, 26 Feb 2024 09:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="FwzPtilE" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 1ED0C52F8F for ; Mon, 26 Feb 2024 09:59:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708941584; cv=none; b=Mb7szJBOBIRoibTC56Qyq0oTVlYCLdQNlA8raOUEyJgxRTXvmW5qGUY7zrzqHrB6+mygHmdnyIN2zogpTPbU6YAtKIJtFI5+GPUPkYdee1Gc/np+HxR3Agr/wKa2oW8VDGylWV3S8Qvl7n1AZO4/Yd0Ef2iAAsmZbNHzEShWHHM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708941584; c=relaxed/simple; bh=NbcJIQ6YYumQeXmUBBsEZnRlGvlqBA09BuKqxSIsv8g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bJu8hostXp434Zx8IGEt6XAEciIy1e629I5LdwHQ99XFFO2m26uBdJdMJ+2kBudIpewJPCmAcgSQErTBFx9IN2IUS5M+p9TLiJuXQ3sVcAUaX/ueLNAvBsn5XoViHcLDzk1k7le17xC5aJLgFVMDXrNskxLxlY7BQzOLPZ3iAIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=FwzPtilE; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708941579; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=U3Y9+BuA9RX74PXr7GyTAAvmUXsvUnfoxwYUqPDTdvc=; b=FwzPtilE6UbMmAD1qpWUfNCoWULBRosQZIpkVrBcDd7YI3kepd9L4ziLsrqMiJPMQik0jieTaHE6trMJFn7x4kdnkVPMGZk36aEwpFPaAjmSZuFtLjFi1vwwaAZR0WtvZ96LofFuhACndqgX5nhVSoGWXIDjWm96srWeCPfX864= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0W1GlKCY_1708941577; Received: from 30.97.56.44(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W1GlKCY_1708941577) by smtp.aliyun-inc.com; Mon, 26 Feb 2024 17:59:38 +0800 Message-ID: Date: Mon, 26 Feb 2024 17:59:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 2/3] mm: hugetlb: make the hugetlb migration strategy consistent To: Oscar Salvador Cc: akpm@linux-foundation.org, muchun.song@linux.dev, david@redhat.com, linmiaohe@huawei.com, naoya.horiguchi@nec.com, mhocko@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <0514e5139b17ecf3cd9e09d86c93e586c56688dc.1708507022.git.baolin.wang@linux.alibaba.com> <0a06dc7f-3a49-42ba-8221-0b4a3777ac0b@linux.alibaba.com> <9b49d2c8-4ace-4095-8610-8becf96eb023@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/2/26 17:17, Oscar Salvador wrote: > On Mon, Feb 26, 2024 at 11:34:51AM +0800, Baolin Wang wrote: >> IMO, I'm not sure whether it's appropriate to decouple >> dequeue_hugetlb_folio_nodemask() from alloc_hugetlb_folio_nodemask() into >> two separate functions for the users to call, because these details should >> be hidden within the hugetlb core implementation. >> >> Instead, I can move the gfp_mask fiddling into a new helper, and move the >> helper into alloc_migrate_hugetlb_folio(). Temporary hugetlb allocation has >> its own gfp strategy seems reasonable to me. > > An alternative would be to do the following, which does not futher carry > the "reason" argument into hugetlb code. > (Not even compile tested, just a PoC) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index c1ee640d87b1..8a89a1007dcb 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -970,6 +970,24 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) > return modified_mask; > } > > +static inline bool htlb_allow_fallback(int reason) > +{ > + bool allowed_fallback = false; > + > + switch (reason) { > + case MR_MEMORY_HOTPLUG: > + case MR_MEMORY_FAILURE: > + case MR_SYSCALL: > + case MR_MEMPOLICY_MBIND: > + allowed_fallback = true; > + break; > + default: > + break; > + } > + > + return allowed_fallback; > +} > + Thanks for providing an alternative implementation. However, I still prefer to hide these details into hugetlb core, since users do not need to pay excessive attention to these hugetlb details. So something like: diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 418d66953224..e8eb08bbc688 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2567,13 +2567,38 @@ static struct folio *alloc_surplus_hugetlb_folio(struct hstate *h, } static struct folio *alloc_migrate_hugetlb_folio(struct hstate *h, gfp_t gfp_mask, - int nid, nodemask_t *nmask) + int nid, nodemask_t *nmask, int reason) { struct folio *folio; + bool allowed_fallback = false; if (hstate_is_gigantic(h)) return NULL; + if (gfp_mask & __GFP_THISNODE) + goto alloc_new; + + /* + * Note: the memory offline, memory failure and migration syscalls will + * be allowed to fallback to other nodes due to lack of a better chioce, + * that might break the per-node hugetlb pool. While other cases will + * set the __GFP_THISNODE to avoid breaking the per-node hugetlb pool. + */ + switch (reason) { + case MR_MEMORY_HOTPLUG: + case MR_MEMORY_FAILURE: + case MR_MEMORY_FAILURE: + case MR_SYSCALL: + case MR_MEMPOLICY_MBIND: + allowed_fallback = true; + break; + default: + break; + } + + if (!allowed_fallback) + gfp_mask |= __GFP_THISNODE; + +alloc_new: folio = alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL); if (!folio) return NULL; @@ -2621,7 +2646,7 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(struct hstate *h, /* folio migration callback function */ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) return NULL; @@ -2621,7 +2646,7 @@ struct folio *alloc_buddy_hugetlb_folio_with_mpol(struct hstate *h, /* folio migration callback function */ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, - nodemask_t *nmask, gfp_t gfp_mask) + nodemask_t *nmask, gfp_t gfp_mask, int reason) { spin_lock_irq(&hugetlb_lock); if (available_huge_pages(h)) { @@ -2636,7 +2661,7 @@ struct folio *alloc_hugetlb_folio_nodemask(struct hstate *h, int preferred_nid, } spin_unlock_irq(&hugetlb_lock); - return alloc_migrate_hugetlb_folio(h, gfp_mask, preferred_nid, nmask); + return alloc_migrate_hugetlb_folio(h, gfp_mask, preferred_nid, nmask, reason); } /* @@ -6653,7 +6678,13 @@ static struct folio *alloc_hugetlb_folio_vma(struct hstate *h, gfp_mask = htlb_alloc_mask(h); node = huge_node(vma, address, gfp_mask, &mpol, &nodemask); - folio = alloc_hugetlb_folio_nodemask(h, node, nodemask, gfp_mask); + /* + * This is used to allocate a temporary hugetlb to hold the copied + * content, which will then be copied again to the final hugetlb + * consuming a reservation. Set the migrate reason to -1 to indicate + * that breaking the per-node hugetlb pool is not allowed in this case. + */ + folio = alloc_hugetlb_folio_nodemask(h, node, nodemask, gfp_mask, -1); mpol_cond_put(mpol); return folio; What do you think? Thanks.