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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA5DAC4167D for ; Tue, 12 Dec 2023 15:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376885AbjLLPc3 (ORCPT ); Tue, 12 Dec 2023 10:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376793AbjLLPc1 (ORCPT ); Tue, 12 Dec 2023 10:32:27 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9B04995 for ; Tue, 12 Dec 2023 07:32:33 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A394A143D; Tue, 12 Dec 2023 07:33:19 -0800 (PST) Received: from [10.1.39.183] (XHFQ2J9959.cambridge.arm.com [10.1.39.183]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8385B3F738; Tue, 12 Dec 2023 07:32:30 -0800 (PST) Message-ID: Date: Tue, 12 Dec 2023 15:32:29 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 03/10] mm: thp: Introduce multi-size THP sysfs interface Content-Language: en-GB To: David Hildenbrand , 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" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , Kefeng Wang , Barry Song <21cnbao@gmail.com>, Alistair Popple Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Barry Song References: <20231207161211.2374093-1-ryan.roberts@arm.com> <20231207161211.2374093-4-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/12/2023 14:54, David Hildenbrand wrote: > On 07.12.23 17:12, Ryan Roberts wrote: >> In preparation for adding support for anonymous multi-size 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 >> "inherit" (to inherit 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. The resulting functions are >> renamed to thp_vma_suitable_orders() and thp_vma_allowable_orders() >> respectively. Convenience functions that take a single, unencoded order >> and return a boolean are also defined as thp_vma_suitable_order() and >> thp_vma_allowable_order(). >> >> 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|inherit] >> bitfields since this reduces the amount of work required in >> thp_vma_allowable_orders() which is called for every page fault. >> >> See Documentation/admin-guide/mm/transhuge.rst, as modified by this >> commit, for details of how the new sysfs interface works. >> >> Reviewed-by: Barry Song >> Tested-by: Kefeng Wang >> Tested-by: John Hubbard >> Signed-off-by: Ryan Roberts >> --- > > [...] > >> + >> +static ssize_t thpsize_enabled_store(struct kobject *kobj, >> +                     struct kobj_attribute *attr, >> +                     const char *buf, size_t count) >> +{ >> +    int order = to_thpsize(kobj)->order; >> +    ssize_t ret = count; >> + >> +    if (sysfs_streq(buf, "always")) { >> +        spin_lock(&huge_anon_orders_lock); >> +        clear_bit(order, &huge_anon_orders_inherit); >> +        clear_bit(order, &huge_anon_orders_madvise); >> +        set_bit(order, &huge_anon_orders_always); >> +        spin_unlock(&huge_anon_orders_lock); >> +    } else if (sysfs_streq(buf, "inherit")) { >> +        spin_lock(&huge_anon_orders_lock); >> +        clear_bit(order, &huge_anon_orders_always); >> +        clear_bit(order, &huge_anon_orders_madvise); >> +        set_bit(order, &huge_anon_orders_inherit); >> +        spin_unlock(&huge_anon_orders_lock); >> +    } else if (sysfs_streq(buf, "madvise")) { >> +        spin_lock(&huge_anon_orders_lock); >> +        clear_bit(order, &huge_anon_orders_always); >> +        clear_bit(order, &huge_anon_orders_inherit); >> +        set_bit(order, &huge_anon_orders_madvise); >> +        spin_unlock(&huge_anon_orders_lock); >> +    } else if (sysfs_streq(buf, "never")) { >> +        spin_lock(&huge_anon_orders_lock); >> +        clear_bit(order, &huge_anon_orders_always); >> +        clear_bit(order, &huge_anon_orders_inherit); >> +        clear_bit(order, &huge_anon_orders_madvise); >> +        spin_unlock(&huge_anon_orders_lock); > > Why not perform lock/unlock only once in surrounding code? :) I was nervous that sysfs_streq() may be unhappy in atomic context... Unfounded? > > > Much better > > Acked-by: David Hildenbrand >