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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 931E8C61CE8 for ; Thu, 12 Jun 2025 13:13:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 216CD6B007B; Thu, 12 Jun 2025 09:13:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EF516B0088; Thu, 12 Jun 2025 09:13:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B6C06B0089; Thu, 12 Jun 2025 09:13:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DEE286B007B for ; Thu, 12 Jun 2025 09:13:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 62038161402 for ; Thu, 12 Jun 2025 13:13:30 +0000 (UTC) X-FDA: 83546790180.03.5982726 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 5D6B814000F for ; Thu, 12 Jun 2025 13:13:27 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YK4cDdnc; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749734008; h=from:from:sender: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:dkim-signature; bh=doGApCfuzN9zuT6dgCoqzdNZcDtX0mj/1DflOCrs5dY=; b=FxuYLn2evdRTqiEVv8s5LnVsdqDMO51N9xOkklCl+z+uJ6mmVnQ9kV38XC6m2ZxaM81yTP GN6SvPtP0/0gA0LUwHTTPBfUJgiExIGQjnnkIt1nMdeCvmYyUSQ90JjKwyaBPOIgQbsgnE VVGUGWnBgKYTmLXot4wt2O4tinvbJQ0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YK4cDdnc; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749734008; a=rsa-sha256; cv=none; b=hOIzrY62DhO1AoLAmtVBkX0IH7sZrC2x/wSdJQHbeL8SSCJ8lnu5jLzYsit84fO+4ni9zh 31ClvtlMLGElqkUbFRACopPh8enTmbssINEbQSQmxIu/xz8IXI9ihzHCyJhDxBqKsvY4hp +hpzriKPauKvas3UZTc0glKamq/I7Mc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749734006; 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:autocrypt:autocrypt; bh=doGApCfuzN9zuT6dgCoqzdNZcDtX0mj/1DflOCrs5dY=; b=YK4cDdncQ8RQijRXqXWVCirVgWumboYUyf1QeMCCm6AC+dqE3m9kLX+sY+sOoqmlw1MNwd 7MgggMxyZXWWRlaDJhakYN6KhgneP9Xxrlta81IfXS6IMdgGjJeV+aH3mKOK0ScBj5usk4 sxi15+Db0lP8GyjY869FSd9gJZJNVeg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-428-iqE5x9TrPbS_x84c3h3SkQ-1; Thu, 12 Jun 2025 09:13:23 -0400 X-MC-Unique: iqE5x9TrPbS_x84c3h3SkQ-1 X-Mimecast-MFC-AGG-ID: iqE5x9TrPbS_x84c3h3SkQ_1749734002 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a54a8a0122so482159f8f.2 for ; Thu, 12 Jun 2025 06:13:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749734002; x=1750338802; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=doGApCfuzN9zuT6dgCoqzdNZcDtX0mj/1DflOCrs5dY=; b=LLAKq6abUDKA+CR72ABFgTzmzZCezPbk7NX7Y9eHS9VxD0yIt5+JZGAurzmgLyFONo viTexDGWOqZhdv2donkL7B6TXji33CJhTubKjw9fO39sm66YUW71zvTSoiROomUOXOZH aW73GgYj6uTS3Ly6fzDrIZG5lOuNO4CyXzOGofmVz9SjCH8/OqqWCmuabm1BiXpR5ZHi 2n+RoLyigC7cQg85+KLZtADSa0wZO6KuUr6KdcP5RpKZeqbsStgvS8MlVkYZq2zmpGzL FdJDOQ8TneGLDHRW78WJRsW6lFFuIqImtFhFX6qdMnO2VfHqn+zjip9uhe4OZUkw4gqQ K9nA== X-Forwarded-Encrypted: i=1; AJvYcCU6nlFYk3MKjmjmzDFQK5FRz7zFLr1G9B2SedKbQtoV3GNGzf3Z0W0lVoeWSvrWIVZ/nMmd/C/MYw==@kvack.org X-Gm-Message-State: AOJu0Yxxo35Nyf1gNLg+nM6IEFg7m5s6Zdw8u6gfJm7QHPYOKXShooX4 1pCT2U6yYxM1HOjOe03oMfjUZ4GJt0sXHdJoAyTZzdKHt0hHTOkJaIBWcZT/HnF4J+1DxhKLkQE 3IwtzpgkaBVK/mUXCghS0uoXSxo+OKfJdDBXW9yDY3w5ISxebEVkH X-Gm-Gg: ASbGncuARszYd/7AYpeEBAP3+iFqMSr1NAGmst8H8Re3AZ4hLXm+oTuVvDqfPO+md5V W4Z9kieg+MiCFORabEd3delFoWIxjBRxaxkvvTh65VoaAukFhUCU1ktpAVjL7+xxCiAk7ZFZgXk TfQ6f9QFJbaQjxiAzrSDWHvopnzt7kaFA4A+6sHlC+i9BOsO5QWjOmToNuNRlKXgwfy+O7ExPLT xTWXOUoBZXEShbKc5JwsB5ZpBP8ncLLhCPWFwjJMvYNhbk2WRGkvQUIeojXXLuLGqSypelZrZ0y +0LlxrneEebZRFHGBcEIv9SxH4+3oMziD43q3BgCW1O2IDhz1FC2TMM7Fb/mAnkJyTFg8FLK5YB fyM54Uz8fC6SYBPlGqwXKq650NdVfFO8qjuIpYvGq1Oyl2uz3ow== X-Received: by 2002:a05:6000:1acc:b0:3a4:dde7:ee12 with SMTP id ffacd0b85a97d-3a56078232cmr3475184f8f.53.1749734002247; Thu, 12 Jun 2025 06:13:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/GEeX1MhfNFuJGizXhPgS93Fpg4t5jWtBsPn3LlYKpQl7fMIZ5s2DtNJvHLjMNgF58ZU26Q== X-Received: by 2002:a05:6000:1acc:b0:3a4:dde7:ee12 with SMTP id ffacd0b85a97d-3a56078232cmr3475136f8f.53.1749734001630; Thu, 12 Jun 2025 06:13:21 -0700 (PDT) Received: from ?IPV6:2003:d8:2f2c:1e00:1e1e:7a32:e798:6457? (p200300d82f2c1e001e1e7a32e7986457.dip0.t-ipconnect.de. [2003:d8:2f2c:1e00:1e1e:7a32:e798:6457]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e241b70sm20210105e9.18.2025.06.12.06.13.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Jun 2025 06:13:20 -0700 (PDT) Message-ID: Date: Thu, 12 Jun 2025 15:13:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/2] mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabled To: Lorenzo Stoakes Cc: Baolin Wang , akpm@linux-foundation.org, hughd@google.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <8eefb0809c598fadaa4a022634fba5689a4f3257.1749109709.git.baolin.wang@linux.alibaba.com> <1ec368c4-c4d8-41ea-b8a3-7d1fdb3ec358@redhat.com> <2ff65f37-efa9-4e96-9cdf-534d63ff154e@linux.alibaba.com> <953596b2-8749-493d-97eb-a5d8995d9ef8@redhat.com> <3a3f6f69-f0f4-41a0-b960-e76423fb6dc9@lucifer.local> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27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5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <3a3f6f69-f0f4-41a0-b960-e76423fb6dc9@lucifer.local> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NjiCu5DkHGLfx5OCbzDg4iZy5K9Chl80HNlHlRg137w_1749734002 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5D6B814000F X-Stat-Signature: 6jr7rmqsuquioh3c5igziy978yau9f45 X-Rspam-User: X-HE-Tag: 1749734007-943336 X-HE-Meta: U2FsdGVkX1/LeGfTz1VoR2T+u46haX6Gqi9XbeMVEzZ0LJ7zhdEFQzdqN7wc/PmA/isVDbUolMEZJHleQr5hvFKFerfDGgafc6AWuX9chiALO+SeId9gO30QS7yvCqyuJ7xIbW7F9v5qI7ByeBlURtMD8j+vx4IIR4SdpUmXYAEr2ap27kupADkMvT0uAPMWRa4LKT+nDP3w9nm3kLeFbYj+A5vZT1Z0MF5CIYypmdrjQYwrq3FCccE/Kgu31L0nkBcY2PF+gtACH35uxMLO/0Ph5M9Au2adoV5UvP5NSulzlVEwUEPKsgnRJoh4M1Ku86BMQaEoE/mK3LV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WUIJkh5B17QSNErQ7i4NnqRXKI5Pz27GrimANxvLvpJx1vFczibq0P2qbDnKs4PnLGTSKG4bNf5g3eGGGLgXMUbNxFIpSjqrnurntmPLDpQAFHbQrU5FQQqC1Hugz9pezuVDJnoJz9gU/yBIc1LrD3HULn4Wi2wC3THSXY8K87fHvMeC5+NJuNVmziI1TLY235t/BRHcqrCgjocaFSZnaVXpTEZFNSncxpw8Jrk9e5DEk= 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: List-Subscribe: List-Unsubscribe: On 12.06.25 15:07, Lorenzo Stoakes wrote: > On Thu, Jun 12, 2025 at 10:51:17AM +0200, David Hildenbrand wrote: >> On 12.06.25 09:51, Baolin Wang wrote: >>> >>> >>> On 2025/6/11 20:34, David Hildenbrand wrote: >>>> On 05.06.25 10:00, Baolin Wang wrote: >>>>> The MADV_COLLAPSE will ignore the system-wide Anon THP sysfs settings, >>>>> which >>>>> means that even though we have disabled the Anon THP configuration, >>>>> MADV_COLLAPSE >>>>> will still attempt to collapse into a Anon THP. This violates the rule >>>>> we have >>>>> agreed upon: never means never. >>>>> >>>>> Another rule for madvise, referring to David's suggestion: “allowing >>>>> for collapsing >>>>> in a VM without VM_HUGEPAGE in the "madvise" mode would be fine". >>>>> >>>>> To address this issue, should check whether the Anon THP configuration >>>>> is disabled >>>>> in thp_vma_allowable_orders(), even when the TVA_ENFORCE_SYSFS flag is >>>>> set. >>>>> >>>>> In summary, the current strategy is: >>>>> >>>>> 1. If always & orders == 0, and madvise & orders == 0, and >>>>> hugepage_global_enabled() == false >>>>> (global THP settings are not enabled), it means mTHP of that orders >>>>> are prohibited >>>>> from being used, then madvise_collapse() is forbidden for that orders. >>>>> >>>>> 2. If always & orders == 0, and madvise & orders == 0, and >>>>> hugepage_global_enabled() == true >>>>> (global THP settings are enabled), and inherit & orders == 0, it means >>>>> mTHP of that >>>>> orders are still prohibited from being used, thus madvise_collapse() >>>>> is not allowed >>>>> for that orders. >>>>> >>>>> Reviewed-by: Zi Yan >>>>> Signed-off-by: Baolin Wang >>>>> --- >>>>>   include/linux/huge_mm.h | 23 +++++++++++++++++++---- >>>>>   1 file changed, 19 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >>>>> index 2f190c90192d..199ddc9f04a1 100644 >>>>> --- a/include/linux/huge_mm.h >>>>> +++ b/include/linux/huge_mm.h >>>>> @@ -287,20 +287,35 @@ unsigned long thp_vma_allowable_orders(struct >>>>> vm_area_struct *vma, >>>>>                          unsigned long orders) >>>>>   { >>>>>       /* Optimization to check if required orders are enabled early. */ >>>>> -    if ((tva_flags & TVA_ENFORCE_SYSFS) && vma_is_anonymous(vma)) { >>>>> -        unsigned long mask = READ_ONCE(huge_anon_orders_always); >>>>> +    if (vma_is_anonymous(vma)) { >>>>> +        unsigned long always = READ_ONCE(huge_anon_orders_always); >>>>> +        unsigned long madvise = READ_ONCE(huge_anon_orders_madvise); >>>>> +        unsigned long inherit = READ_ONCE(huge_anon_orders_inherit); >>>>> +        unsigned long mask = always | madvise; >>>>> + >>>>> +        /* >>>>> +         * If the system-wide THP/mTHP sysfs settings are disabled, >>>>> +         * then we should never allow hugepages. >>>> > +         */> +        if (!(mask & orders) && >>>> !(hugepage_global_enabled() && (inherit & orders))) >>>>> +            return 0; >>>> >>>> I'm still trying to digest that. Isn't there a way for us to work with >>>> the orders, >>>> essentially masking off all orders that are forbidden globally. Similar >>>> to below, if !orders, then return 0? >>>> /* Orders disabled directly. */ >>>> orders &= ~TODO; >>>> /* Orders disabled by inheriting from the global toggle. */ >>>> if (!hugepage_global_enabled()) >>>>     orders &= ~READ_ONCE(huge_anon_orders_inherit); >>>> >>>> TODO is probably a -1ULL and then clearing always/madvise/inherit. Could >>>> add a simple helper for that >>>> >>>> huge_anon_orders_never >>> >>> I followed Lorenzo's suggestion to simplify the logic. Does that look >>> more readable? >>> >>> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h >>> index 2f190c90192d..3087ac7631e0 100644 >>> --- a/include/linux/huge_mm.h >>> +++ b/include/linux/huge_mm.h >>> @@ -265,6 +265,43 @@ unsigned long __thp_vma_allowable_orders(struct >>> vm_area_struct *vma, >>> unsigned long tva_flags, >>> unsigned long orders); >>> >>> +/* Strictly mask requested anonymous orders according to sysfs settings. */ >>> +static inline unsigned long __thp_mask_anon_orders(unsigned long vm_flags, >>> + unsigned long tva_flags, unsigned long >>> orders) >>> +{ >>> + unsigned long always = READ_ONCE(huge_anon_orders_always); >>> + unsigned long madvise = READ_ONCE(huge_anon_orders_madvise); >>> + unsigned long inherit = READ_ONCE(huge_anon_orders_inherit); >>> + bool inherit_enabled = hugepage_global_enabled(); >>> + bool has_madvise = vm_flags & VM_HUGEPAGE; >>> + unsigned long mask = always | madvise; >>> + >>> + mask = always | madvise; >>> + if (inherit_enabled) >>> + mask |= inherit; >>> + >>> + /* All set to/inherit NEVER - never means never globally, abort. */ >>> + if (!(mask & orders)) >>> + return 0; >> >> Still confusing. I am not sure if we would properly catch when someone >> specifies e.g., 2M and 1M, while we only have 2M disabled. > > I did wonder if we should call 'orders' something like 'requested_orders' > or something. > > This check is always against the input orders which we might conceivably > want. > > For instance in madvise_collapse(): > > if (!thp_vma_allowable_order(vma, vma->vm_flags, 0, PMD_ORDER)) > return -EINVAL; > > I don't think, if it's only possible for PMD order collapse, and that is > disabled, but mTHP 64 KB let's say is enabled, it'd be fine for > MADV_COLLAPSE to succeed at the PMD order. > > >> >> >> I would rewrite the function to only ever substract from "orders". > > Hm. > >> >> ... >> >> /* Disallow orders that are set to NEVER directly ... */ >> order &= (always | madvise | inherit); > ^s > > I think you mean (always | madvise) here. > >> >> /* ... or through inheritance. */ >> if (inherit_enabled) >> orders &= ~inherit; > > order & (inherit & ~inherit) is going to always be zero :) > > So this should be > > orders &= inherit. > > The problem is, when you come to the next stage where you are done checking > the 'are we in a NEVER situation regardless of TVA_ENFORCE_SYSFS' you've > now corrupted orders. > > Because you've included inherit even if !(tva_flags & TVA_ENFORCE_SYSFS). > > And there's no way to recover that information. > >> >> /* >> * Otherwise, we only enforce sysfs settings if asked. In addition, >> * if the user sets a sysfs mode of madvise and if TVA_ENFORCE_SYSFS >> * is not set, we don't bother checking whether the VMA has VM_HUGEPAGE >> * set. >> */ >> if (!orders || !(tva_flags & TVA_ENFORCE_SYSFS)) >> return orders; > > I don't think this is much delta to what we have now. > > I do wonder if we should return mask & orders here, actually, to account > for the fact that, in theory, orders could set > PMD for > !TVA_ENFORCE_SYSFS) (not currently the case). > >> >>> + >>> + /* >>> + * Otherwise, we only enforce sysfs settings if asked. In addition, >>> + * if the user sets a sysfs mode of madvise and if TVA_ENFORCE_SYSFS >>> + * is not set, we don't bother checking whether the VMA has >>> VM_HUGEPAGE >>> + * set. >>> + */ >>> + if (!(tva_flags & TVA_ENFORCE_SYSFS)) >>> + return orders; >>> + >>> + mask = always; >>> + if (has_madvise) >>> + mask |= madvise; >>> + if (hugepage_global_always() || (has_madvise && inherit_enabled)) >>> + mask |= inherit; >> >> Similarly, this can maybe become (not 100% sure if I got it right, the >> condition above is confusing) >> >> if (!has_madvise) { >> /* >> * Without VM_HUGEPAGE, only allow orders that are set to >> * ALWAYS directly ... >> */ >> order &= (always | inherit); > > Obviously orders is corrupted at this point so this won't work, but I'm not > sure this is right? > > If no madvise, only then obey always/inherit? Hm? > > >> /* ... or through inheritance. */ >> if (!hugepage_global_always()) >> orders &= ~inherit; > > I'm not sure about this ~inherit again, that means we ignore inherit no? > >> } > > And we need a branch for madvise too no? > > I think all of this is a _clear_ example of what a mess all this is. > > I think we need a deeper refactor, but I think my suggested changes make at > least what we have here less horrid to get through. > > I think maybe a better refactoring that's in the spirit of this is: > > if (has_madvise) { > mask |= madvise; > if (inherit_enabled) > mask |= inherit; > } else if (hugepage_global_always()) { > mask |= inherit; > } > > What do you think? The masks are just disgusting :( While you were writing that reply, I just sent out something else. Not sure if that makes sense. I'm having a hard time figuring out what we even want here in the existing code. -- Cheers, David / dhildenb