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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A016EC4167B for ; Wed, 29 Nov 2023 08:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=S1RxaqICnAr0yTuqOGkG1Y4GnboIF1HOwiOlpNQ6FZI=; b=R94DBJuvpd68wx RWO6hPjofEvbMQLZGvO7QmbokwhJghtg1dhh3Mo4Q7qWRFasGHYe6SmUmAl0p2YvUHIWpfgkDARie qfXz+Mvb/h1f4EPPMZ6ocwDdEV4SyaaS4jj2R0SV2vq0rK/6xT/0i6jn6ZlE3jcim7SqcfN2qPGc+ EdOSpGJqe5+UHJ1z0s0MwT7bwY2t8IvmX5IGR0A28hhjM/xlDKJCLI+tF29pqfnK3AcwcDmipagT4 SDZfuHzcJKrjyByhTqn8vjhC4ebqrFHd3YfzX4KXD6symJPbeoVzYeHfJbDPZy9mFbDCk5SeUMtjz 99afYAFp1r2OObx/O0ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8FZo-007Q5M-0Z; Wed, 29 Nov 2023 08:05:44 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8FZj-007Q3w-2W for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 08:05:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701245136; 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=8v095EuMzzISmu5Y1f0aoY1vTTbA82jShxtCDF/8mD4=; b=jTOoLiRbHXxFJGL4eZQbZcrOTtkJt2jnZCUHLF4Lsus8TosaC9p+n5EJl2/P5U5Ke0qp4e qpykO1V2L3ouvSWwbQ3H92cLkCkDFn3Ys5puMnwd5atV226NHGRZblWHAJWBLjwyrkqpTS DMwvbKQXfoqENhvCegEZZSxNbKOU5jc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-GwZX9dwaMQqcpEFnyVsCHg-1; Wed, 29 Nov 2023 03:05:35 -0500 X-MC-Unique: GwZX9dwaMQqcpEFnyVsCHg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-332ee6c2a1aso3470197f8f.1 for ; Wed, 29 Nov 2023 00:05:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701245134; x=1701849934; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language: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=8v095EuMzzISmu5Y1f0aoY1vTTbA82jShxtCDF/8mD4=; b=DtFh+3aCUXmdXgSt9tHX1YwEC53sHISQYQK14P4LGJGm0QYOp2PoLWpzs2qPLhkbkt t4/Vg/aOi4Hs2NfkezOv+Yw9waKqh05uyMIinsRYYrqClhs6DotVtegD8rGmpFZfTAbu IyYPCNnogfrj78xUR4rabVEZy67uMZ5WOtL4Y2bzWB9pnIFaIXTrdqc05PZIOo9nPiBk f2Fibm330/sfWeKgkuX2p4Idhmeg70MqTY8Ny9UGwdVUYqBjn1qFcGKzq0ModdrLfR5c O9XMygjn8GrxPkCAgsUhTiEFDLGbIS00PHqVJ8RqUJJi0FDUqsAYS5ny5cn59W2/ytGT +iuw== X-Gm-Message-State: AOJu0YzPqbIpPBq/J7Uxj4QQCGuVZnCvlmJWGhSzVh0YfEmkBcSVOi6I qh5A3Im1rrhvBTJpZ2oe2/RJPiY+oLj6ygyh9rE5LFo0/CHdibrKOlnKSkIIcmjE5Qa0x2YwyDc aQJYKlgxAxm3WJGF7aBJSQ0d/PlFEZl0Vx8o= X-Received: by 2002:a5d:40c8:0:b0:332:ca80:a9ea with SMTP id b8-20020a5d40c8000000b00332ca80a9eamr15317548wrq.41.1701245134061; Wed, 29 Nov 2023 00:05:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEH+cIaBxAciCd2fsZSq+1PDb19SejhgJa0v9lNP3Bybizd9hcikvV8V3BG6r7q69GN1MF/Aw== X-Received: by 2002:a5d:40c8:0:b0:332:ca80:a9ea with SMTP id b8-20020a5d40c8000000b00332ca80a9eamr15317508wrq.41.1701245133531; Wed, 29 Nov 2023 00:05:33 -0800 (PST) Received: from ?IPV6:2003:cb:c710:f600:634b:35f:ffa8:475b? (p200300cbc710f600634b035fffa8475b.dip0.t-ipconnect.de. [2003:cb:c710:f600:634b:35f:ffa8:475b]) by smtp.gmail.com with ESMTPSA id df2-20020a5d5b82000000b0032fbe5b1e45sm16817600wrb.61.2023.11.29.00.05.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Nov 2023 00:05:33 -0800 (PST) Message-ID: Date: Wed, 29 Nov 2023 09:05:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RESEND PATCH v7 03/10] mm: thp: Introduce per-size thp sysfs interface To: John Hubbard , Ryan Roberts , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231122162950.3854897-1-ryan.roberts@arm.com> <20231122162950.3854897-4-ryan.roberts@arm.com> <1a738e0a-ac11-4cd3-be2f-6b6e7cb4980a@nvidia.com> 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 UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1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0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <1a738e0a-ac11-4cd3-be2f-6b6e7cb4980a@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_000539_982789_B7B0924B X-CRM114-Status: GOOD ( 37.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 29.11.23 04:42, John Hubbard wrote: > On 11/22/23 08:29, Ryan Roberts wrote: >> In preparation for adding support for anonymous small-sized THP, >> introduce new sysfs structure that will be used to control the new >> behaviours. A new directory is added under transparent_hugepage for each >> supported THP size, and contains an `enabled` file, which can be set to >> "global" (to inherrit the global setting), "always", "madvise" or >> "never". For now, the kernel still only supports PMD-sized anonymous >> THP, so only 1 directory is populated. >> >> The first half of the change converts transhuge_vma_suitable() and >> hugepage_vma_check() so that they take a bitfield of orders for which >> the user wants to determine support, and the functions filter out all >> the orders that can't be supported, given the current sysfs >> configuration and the VMA dimensions. If there is only 1 order set in >> the input then the output can continue to be treated like a boolean; >> this is the case for most call sites. >> >> The second half of the change implements the new sysfs interface. It has >> been done so that each supported THP size has a `struct thpsize`, which >> describes the relevant metadata and is itself a kobject. This is pretty >> minimal for now, but should make it easy to add new per-thpsize files to >> the interface if needed in future (e.g. per-size defrag). Rather than >> keep the `enabled` state directly in the struct thpsize, I've elected to >> directly encode it into huge_anon_orders_[always|madvise|global] >> bitfields since this reduces the amount of work required in >> transhuge_vma_suitable() which is called for every page fault. >> >> The remainder is copied from Documentation/admin-guide/mm/transhuge.rst, >> as modified by this commit. See that file for further details. >> >> Transparent Hugepage Support for anonymous memory can be entirely >> disabled (mostly for debugging purposes) or only enabled inside >> MADV_HUGEPAGE regions (to avoid the risk of consuming more memory >> resources) or enabled system wide. This can be achieved >> per-supported-THP-size with one of:: >> >> echo always >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> echo madvise >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> echo never >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> >> where is the hugepage size being addressed, the available sizes >> for which vary by system. Alternatively it is possible to specify that >> a given hugepage size will inherrit the global enabled setting:: >> >> echo global >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> >> The global (legacy) enabled setting can be set as follows:: >> >> echo always >/sys/kernel/mm/transparent_hugepage/enabled >> echo madvise >/sys/kernel/mm/transparent_hugepage/enabled >> echo never >/sys/kernel/mm/transparent_hugepage/enabled >> >> By default, PMD-sized hugepages have enabled="global" and all other >> hugepage sizes have enabled="never". If enabling multiple hugepage >> sizes, the kernel will select the most appropriate enabled size for a >> given allocation. >> >> Signed-off-by: Ryan Roberts >> --- >> Documentation/admin-guide/mm/transhuge.rst | 74 ++++-- >> Documentation/filesystems/proc.rst | 6 +- >> fs/proc/task_mmu.c | 3 +- >> include/linux/huge_mm.h | 100 +++++--- >> mm/huge_memory.c | 263 +++++++++++++++++++-- >> mm/khugepaged.c | 16 +- >> mm/memory.c | 6 +- >> mm/page_vma_mapped.c | 3 +- >> 8 files changed, 387 insertions(+), 84 deletions(-) >> >> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst >> index b0cc8243e093..52565e0bd074 100644 >> --- a/Documentation/admin-guide/mm/transhuge.rst >> +++ b/Documentation/admin-guide/mm/transhuge.rst >> @@ -45,10 +45,23 @@ components: >> the two is using hugepages just because of the fact the TLB miss is >> going to run faster. >> >> +As well as PMD-sized THP described above, it is also possible to >> +configure the system to allocate "small-sized THP" to back anonymous > > Here's one of the places to change to the new name, which lately is > "multi-size THP", or mTHP or m_thp for short. (I've typed "multi-size" > instead of "multi-sized", because the 'd' doesn't add significantly to > the meaning, and if in doubt, shorter is better. > > >> +memory (for example 16K, 32K, 64K, etc). These THPs continue to be >> +PTE-mapped, but in many cases can still provide similar benefits to >> +those outlined above: Page faults are significantly reduced (by a >> +factor of e.g. 4, 8, 16, etc), but latency spikes are much less >> +prominent because the size of each page isn't as huge as the PMD-sized >> +variant and there is less memory to clear in each page fault. Some >> +architectures also employ TLB compression mechanisms to squeeze more >> +entries in when a set of PTEs are virtually and physically contiguous >> +and approporiately aligned. In this case, TLB misses will occur less >> +often. >> + > > OK, all of the above still seems like it can remain the same. > >> THP can be enabled system wide or restricted to certain tasks or even >> memory ranges inside task's address space. Unless THP is completely >> disabled, there is ``khugepaged`` daemon that scans memory and >> -collapses sequences of basic pages into huge pages. >> +collapses sequences of basic pages into PMD-sized huge pages. >> >> The THP behaviour is controlled via :ref:`sysfs ` >> interface and using madvise(2) and prctl(2) system calls. >> @@ -95,12 +108,29 @@ Global THP controls >> Transparent Hugepage Support for anonymous memory can be entirely disabled >> (mostly for debugging purposes) or only enabled inside MADV_HUGEPAGE >> regions (to avoid the risk of consuming more memory resources) or enabled >> -system wide. This can be achieved with one of:: >> +system wide. This can be achieved per-supported-THP-size with one of:: >> + >> + echo always >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> + echo madvise >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> + echo never >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> + >> +where is the hugepage size being addressed, the available sizes >> +for which vary by system. Alternatively it is possible to specify that >> +a given hugepage size will inherrit the global enabled setting:: > > typo: inherrit > >> + >> + echo global >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled >> + >> +The global (legacy) enabled setting can be set as follows:: >> >> echo always >/sys/kernel/mm/transparent_hugepage/enabled >> echo madvise >/sys/kernel/mm/transparent_hugepage/enabled >> echo never >/sys/kernel/mm/transparent_hugepage/enabled >> >> +By default, PMD-sized hugepages have enabled="global" and all other >> +hugepage sizes have enabled="never". If enabling multiple hugepage >> +sizes, the kernel will select the most appropriate enabled size for a >> +given allocation. >> + > > This is slightly murky. I wonder if "inherited" is a little more directly > informative than global; it certainly felt that way my first time running > this and poking at it. > > And a few trivial examples would be a nice touch. > > And so overall with a few other minor tweaks, I'd suggest this: > > ... > where is the hugepage size being addressed, the available sizes > for which vary by system. > > For example: > echo always >/sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled > > Alternatively it is possible to specify that a given hugepage size will inherit > the top-level "enabled" value: > > echo inherited >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled > > For example: > echo inherited >/sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled > > The top-level setting (for use with "inherited") can be by issuing one of the > following commands:: > > echo always >/sys/kernel/mm/transparent_hugepage/enabled > echo madvise >/sys/kernel/mm/transparent_hugepage/enabled > echo never >/sys/kernel/mm/transparent_hugepage/enabled > > By default, PMD-sized hugepages have enabled="inherited" and all other > hugepage sizes have enabled="never". "inherited" works for me as well. -- Cheers, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel