From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9983526C3A2 for ; Tue, 2 Sep 2025 09:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756803834; cv=none; b=QdcYAAXCXjIiT7hj6JLXvPUhYRmzoxuiDZ9M/874h/ieb3zFYLROK4JLI/lijs+CBEIvTEYMwuWxyeLxMP6BHAMVUjqLuDTUZc/cAooXsvhS5DDMWl+Tc+k7ChjqP9pidKn/qFmrZGARNf5uJEomWswhjHrjlInwZHywUic3zD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756803834; c=relaxed/simple; bh=gUm8nt5owzvSoN//+NzInxkUjoZRWW8bTmU0Te4htkA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oKzdGcVn8hjNmVMGQd+ehqWya8mTrRd2Mz8QpCb9BXerVEFle/WV/nWv/qh5h1ILt/hkdKMCjpw0k41EVmoe++8GHW9HEJ71x9Z1yZKiSYemycHRLz4i+A7SzUSC8r5fWxpo48blt3mW/t+wdOCslqHtMWUJegk5Du2hcwdyApI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dJUdAiug; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dJUdAiug" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756803831; 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=b0WxnR2FR7ip9N19Qks8VM7/RT25qXBqQIJIfmfk1b4=; b=dJUdAiugfWACaWr51T7WheimNXjzOIrF3HmfosYfq0BFETJDRiYjRg/UoO/GLNJr7D+JUL Y1fTAOwwHZewRYgAFcSQMtTCeIWN+YdSfb++na3v+2ZtypWVUPGxYtm6mucsf10hU1WR5/ iO+lOgHVxmDHMe1eFGSwv1swn0fMWl0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-3udjnhbVNxmMXFAPE19WRQ-1; Tue, 02 Sep 2025 05:03:50 -0400 X-MC-Unique: 3udjnhbVNxmMXFAPE19WRQ-1 X-Mimecast-MFC-AGG-ID: 3udjnhbVNxmMXFAPE19WRQ_1756803829 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-45b9ca27a11so261285e9.1 for ; Tue, 02 Sep 2025 02:03:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756803829; x=1757408629; h=content-transfer-encoding:in-reply-to: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=b0WxnR2FR7ip9N19Qks8VM7/RT25qXBqQIJIfmfk1b4=; b=es9zJxUr97LYbmwOwlRA/rNM/HAF8rp1S/wks2kS+jV2lkEI0tsI/PmHZq8HieDRRK zik1INyAdgc4K9+mkJzUWT3vJHhFciI2UfEdW35unqsUfquqGBn2kGijYeMTNc2W9yxx 6Oru33QRfIU9f3GaAsmYNr9cLGYMyM9hhGgIZh7U5y6YS6zPn3qaZHK9e8d7js5MYwC7 zOPvxpoupaW7qGqNSgok0lg16UiaWes1Os6r9mVLH1QEoeO81uyip3WVhE5fomL8P+m4 UK7+VbJOSZIKb10tO9oO2gnTr6q0Z8o29DRXFf+pI3vWnWQz/EhqEse3cb3qxOvGAKSO 3WCg== X-Forwarded-Encrypted: i=1; AJvYcCUCgTFSYrY8wV2tQ8KGPofmecbUUN4JHX+hOmk9XlhpmpZgAuD+mWK7StIhvgQhM82H0Bdmg1TIB90=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4xMIX4+43gFVMlu5IDgKEf8ISj3RGOiImU+4QDE8+6pimwriQ ARnkNpHItolWKjiMLxi71jEDVQBUo9/hhlqM/9CpiU7bATPrUxVhPgZaO0xLovAKpo9x5CgIaZy znZDodivDxxWTJqZhwgfy8XyhaRzGGaIm8NlCp37zsCYug95QiurhwIGD7BSpmw== X-Gm-Gg: ASbGncv8QGuNcT8GMh9syDivj9wVGv6Chciz1gODvrExVUy1fwnFLPf2t0WU6/LTBZU j8y3dOcOSk9aJckC6Ac05G++9FJF8PNKoPyR3FTPS2oTJQ40aOVgujm7/YwfqHulhSJD6V1O5xo 7yj3nwIhxgaFut2ecpeW5BuF20Et537H17ULzQPhWw6YHU8+n93/Iz22WwlDPdgqZKNKDxsPMWi rqoyIh81yx2LMRJj2UhbvOjEtBXOZWb4FHGiqb8SsyMDJeqJyvmNmsNri5a/UzrnF5U+aD0rheW nf4lhRXWt/AuKZqq/oVk1vpO7PHUvifQHV5YGOAUiQ4+G7FKD6g8Uf89+S8rXw/NrRPePWkiAlL ocEhYmhTfH1y1KIwAFEwCoJm7I2I5OpEctt52xg+67mgA8fT0aNv2aGLMRIq/71lBX+A= X-Received: by 2002:a05:6000:4313:b0:3d0:c6bf:60e1 with SMTP id ffacd0b85a97d-3d1b20d94f0mr9291848f8f.24.1756803828738; Tue, 02 Sep 2025 02:03:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHht42snrEs79iA+s2h/qI7OraYOWgxGTGcDie+mtZ0wLD5GtnIdk2F2nZntl4vgHTaHkpVuA== X-Received: by 2002:a05:6000:4313:b0:3d0:c6bf:60e1 with SMTP id ffacd0b85a97d-3d1b20d94f0mr9291795f8f.24.1756803828088; Tue, 02 Sep 2025 02:03:48 -0700 (PDT) Received: from ?IPV6:2003:d8:2f1f:3f00:731a:f5e5:774e:d40c? (p200300d82f1f3f00731af5e5774ed40c.dip0.t-ipconnect.de. [2003:d8:2f1f:3f00:731a:f5e5:774e:d40c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b88007a60sm70932175e9.8.2025.09.02.02.03.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Sep 2025 02:03:47 -0700 (PDT) Message-ID: <286e2cb3-6beb-4d21-b28a-2f99bb2f759b@redhat.com> Date: Tue, 2 Sep 2025 11:03:45 +0200 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 00/13] khugepaged: mTHP support To: Baolin Wang , Dev Jain , Lorenzo Stoakes Cc: Nico Pache , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, ziy@nvidia.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, baohua@kernel.org, willy@infradead.org, peterx@redhat.com, wangkefeng.wang@huawei.com, usamaarif642@gmail.com, sunnanyong@huawei.com, vishal.moola@gmail.com, thomas.hellstrom@linux.intel.com, yang@os.amperecomputing.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, raquini@redhat.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, tiwai@suse.de, will@kernel.org, dave.hansen@linux.intel.com, jack@suse.cz, cl@gentwo.org, jglisse@google.com, surenb@google.com, zokeefe@google.com, hannes@cmpxchg.org, rientjes@google.com, mhocko@suse.com, rdunlap@infradead.org, hughd@google.com References: <20250819134205.622806-1-npache@redhat.com> <38b37195-28c8-4471-bd06-951083118efd@arm.com> <0d9c6088-536b-4d7a-8f75-9be5f0faa86f@lucifer.local> <5bea5efa-2efc-4c01-8aa1-a8711482153c@lucifer.local> <95012dfc-d82d-4ae2-b4cd-1e8dcf15e44b@redhat.com> <2a141eef-46e2-46e1-9b0f-066ec537600d@linux.alibaba.com> From: David Hildenbrand Content-Language: en-US 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 UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURf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ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 02.09.25 04:28, Baolin Wang wrote: > > > On 2025/9/2 00:46, David Hildenbrand wrote: >> On 29.08.25 03:55, Baolin Wang wrote: >>> >>> >>> On 2025/8/28 18:48, Dev Jain wrote: >>>> >>>> On 28/08/25 3:16 pm, Baolin Wang wrote: >>>>> (Sorry for chiming in late) >>>>> >>>>> On 2025/8/22 22:10, David Hildenbrand wrote: >>>>>>>> Once could also easily support the value 255 (HPAGE_PMD_NR / 2- 1), >>>>>>>> but not sure >>>>>>>> if we have to add that for now. >>>>>>> >>>>>>> Yeah not so sure about this, this is a 'just have to know' too, and >>>>>>> yes you >>>>>>> might add it to the docs, but people are going to be mightily >>>>>>> confused, esp if >>>>>>> it's a calculated value. >>>>>>> >>>>>>> I don't see any other way around having a separate tunable if we >>>>>>> don't just have >>>>>>> something VERY simple like on/off. >>>>>> >>>>>> Yeah, not advocating that we add support for other values than 0/511, >>>>>> really. >>>>>> >>>>>>> >>>>>>> Also the mentioned issue sounds like something that needs to be >>>>>>> fixed elsewhere >>>>>>> honestly in the algorithm used to figure out mTHP ranges (I may be >>>>>>> wrong - and >>>>>>> happy to stand corrected if this is somehow inherent, but reallly >>>>>>> feels that >>>>>>> way). >>>>>> >>>>>> I think the creep is unavoidable for certain values. >>>>>> >>>>>> If you have the first two pages of a PMD area populated, and you >>>>>> allow for at least half of the #PTEs to be non/zero, you'd collapse >>>>>> first a >>>>>> order-2 folio, then and order-3 ... until you reached PMD order. >>>>>> >>>>>> So for now we really should just support 0 / 511 to say "don't >>>>>> collapse if there are holes" vs. "always collapse if there is at >>>>>> least one pte used". >>>>> >>>>> If we only allow setting 0 or 511, as Nico mentioned before, "At 511, >>>>> no mTHP collapses would ever occur anyway, unless you have 2MB >>>>> disabled and other mTHP sizes enabled. Technically, at 511, only the >>>>> highest enabled order would ever be collapsed." >>>> I didn't understand this statement. At 511, mTHP collapses will occur if >>>> khugepaged cannot get a PMD folio. Our goal is to collapse to the >>>> highest order folio. >>> >>> Yes, I’m not saying that it’s incorrect behavior when set to 511. What I >>> mean is, as in the example I gave below, users may only want to allow a >>> large order collapse when the number of present PTEs reaches half of the >>> large folio, in order to avoid RSS bloat. >> >> How do these users control allocation at fault time where this parameter >> is completely ignored? > > Sorry, I did not get your point. Why does the 'max_pte_none' need to > control allocation at fault time? Could you be more specific? Thanks. The comment over khugepaged_max_ptes_none gives a hint: /* * default collapse hugepages if there is at least one pte mapped like * it would have happened if the vma was large enough during page * fault. * * Note that these are only respected if collapse was initiated by khugepaged. */ In the common case (for anything that really cares about RSS bloat) you will just a get a THP during page fault and consequently RSS bloat. As raised in my other reply, the only documented reason to set max_ptes_none=0 seems to be when an application later (after once possibly getting a THP already during page faults) did some MADV_DONTNEED and wants to control the usage of THPs itself using MADV_COLLAPSE. It's a questionable use case, that already got more problematic with mTHP and page table reclaim. Let me explain: Before mTHP, if someone would MADV_DONTNEED (resulting in a page table with at least one pte_none entry), there would have been no way we would get memory over-allocated afterwards with max_ptes_none=0. (1) Page faults would spot "there is a page table" and just fallback to order-0 pages. (2) khugepaged was told to not collapse through max_ptes_none=0. But now: (A) With mTHP during page-faults, we can just end up over-allocating memory in such an area again: page faults will simply spot a bunch of pte_nones around the fault area and install an mTHP. (B) With page table reclaim (when zapping all PTEs in a table at once), we will reclaim the page table. The next page fault will just try installing a PMD THP again, because there is no PTE table anymore. So I question the utility of max_ptes_none. If you can't tame page faults, then there is only limited sense in taming khugepaged. I think there is vale in setting max_ptes_none=0 for some corner cases, but I am yet to learn why max_ptes_none=123 would make any sense. -- Cheers David / dhildenb