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.129.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 7F0431CC8AF for ; Thu, 31 Oct 2024 21:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730410791; cv=none; b=H1WyK0ICGyTW1kuuQBz3XIqyKwazIIqVW89bGmCpgOIbSNwAu+oXPJ3fe/fuZNTCsE0tWPtCZYM7LaumSJaVxCB/0Eo1d8l2jjOV1GPvjGEsuchIKtdBE96PeMpxMdS8UEkC1iF5HpONUankvVB9u20b1LTBYHT/fUcFSSRHCkc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730410791; c=relaxed/simple; bh=hmZEoE9F1KOcW36e3uTA3ZMp9t9/NxyYPFC1dw7nd2I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pOdw4G3dPV8/EI8KOpkxFweKwJFeJ/TAZNuKmOYhXj0FNE/j3V0WGhGxIXa9wVsICG3M2DCdP3knDZFUo/LXYEXqsVIsekYg6vMPhHQ+pWo3ORkafcqJEibTtKMhW4dQOjymqXV4uVqFJnoLywNq+SIQb8FNefWWgzeY1pw2tVE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=JS3pFYNB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="JS3pFYNB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730410784; 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=fS8gDTZFJocEezC83019NI02fuHlBLQO1gTHctRA88I=; b=JS3pFYNBvSpsoxoHz/0HR4o66NE8jFVBwv4IfHChfppjTe27WQq4SFnw4T2NZCAW0aDYFD AL17PRJ3B8hsZJIXn1uC6e0tNox5Oa9tD6+toXpSoyjIVUjIefN7mSSgEFFikZzJ9wvnSk Jisv9IYSf0f2+rAeehE4Qcmrtlg65cQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-dE5lZZkYMQeJVpTzv2fcGg-1; Thu, 31 Oct 2024 17:39:42 -0400 X-MC-Unique: dE5lZZkYMQeJVpTzv2fcGg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d52ca258eso682085f8f.3 for ; Thu, 31 Oct 2024 14:39:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730410780; x=1731015580; 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=fS8gDTZFJocEezC83019NI02fuHlBLQO1gTHctRA88I=; b=vdioqUMG7CjyHTkU5lUp2tTRyKHcM+/ZqCbxvimGTgK/wCJ+DY2Vpi/TeDOhVPHMzw p/7TVhEHq84ZbDfYJX3W2o15USjPdqR7JB9x48FwyzXr+1iSsNekW9u8Bb3yVjW5T+BC ws7NxqFQlNnsU4bmx0/17z8dYgnZ3pTgQrCVvsbNqxzUhLnBDBC2I7S89u2WFJCuK20I 1cCzty8FbrB+qWcszvC6E4Y7bWDrW3dHiq9haxIuyNY+/J938opzBMmFUErsiv/igjAX P2vhxssiv5ZcLuX+xsAp2xNT8sdKMKrnA6UAGv64GLo4gtFe9QDfLDBJiL7KDIp8GBL4 STrQ== X-Forwarded-Encrypted: i=1; AJvYcCXARGlChN9ypr8G6qL9T5YNKCjXBmYHLJ4DrgnqjKzlG1ETlFk+9ZyR4o205jkpWTNKINo1tV2bW4FvCx4=@vger.kernel.org X-Gm-Message-State: AOJu0YxSBiFPUodJiQs3KMIyqXvOWIEdGQFb9dO6b3jXN8zXLwV5jrer YZWnXT9ywvSnY8m1rnfTOIVOZcScM6BSdoij826XM5zMGyGtwwddcKBeN1US7yBPpeP1TY4T7hd EnEhRrR5i5kzTV1KhV7lBasFZhDVm9K+KSU3Zhc3G98w+JggmTqdsQJFQo+R6ag== X-Received: by 2002:adf:ee4d:0:b0:37d:45f0:b33 with SMTP id ffacd0b85a97d-381b7056d6amr6777251f8f.9.1730410780501; Thu, 31 Oct 2024 14:39:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENOxIGk6gyTscvzdN2IufYd95BCndSW0PH0URMhHpqGHW7gsAlNh6s+kWKbfa51JfOcQCEvQ== X-Received: by 2002:adf:ee4d:0:b0:37d:45f0:b33 with SMTP id ffacd0b85a97d-381b7056d6amr6777232f8f.9.1730410780072; Thu, 31 Oct 2024 14:39:40 -0700 (PDT) Received: from ?IPV6:2003:cb:c70a:ed00:7ddf:1ea9:4f7a:91fe? (p200300cbc70aed007ddf1ea94f7a91fe.dip0.t-ipconnect.de. [2003:cb:c70a:ed00:7ddf:1ea9:4f7a:91fe]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c113e51csm3203248f8f.79.2024.10.31.14.39.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Oct 2024 14:39:39 -0700 (PDT) Message-ID: Date: Thu, 31 Oct 2024 22:39:37 +0100 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: [PATCH v3 3/4] mm: shmem: override mTHP shmem default with a kernel parameter To: Barry Song <21cnbao@gmail.com>, =?UTF-8?Q?Ma=C3=ADra_Canal?= Cc: Jonathan Corbet , Andrew Morton , Hugh Dickins , Ryan Roberts , Baolin Wang , Lance Yang , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com References: <20241030130308.1066299-1-mcanal@igalia.com> <20241030130308.1066299-4-mcanal@igalia.com> <2c507326-3267-431e-936a-23e2ab6a3baf@redhat.com> <899284fa-953f-48a1-af29-222d0d55881c@igalia.com> <95c48a30-0696-4110-950e-e81afb4ffc2a@igalia.com> <5745d2ca-4d87-4d1f-b38f-734c7086f462@redhat.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+SYhmh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EQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 31.10.24 22:12, Barry Song wrote: > On Fri, Nov 1, 2024 at 3:20 AM Maíra Canal wrote: >> >> On 31/10/24 10:33, David Hildenbrand wrote: >>> On 31.10.24 14:24, Maíra Canal wrote: >>>> Hi David, >>>> >>>> On 31/10/24 09:57, David Hildenbrand wrote: >>>>> On 31.10.24 13:51, Maíra Canal wrote: >>>>>> Hi David, >>>>>> >>>>>> On 31/10/24 09:37, David Hildenbrand wrote: >>>>>>> On 30.10.24 13:58, Maíra Canal wrote: >>>>>>>> Add the ``thp_shmem=`` kernel command line to allow specifying the >>>>>>>> default policy of each supported shmem hugepage size. The kernel >>>>>>>> parameter >>>>>>>> accepts the following format: >>>>>>>> >>>>>>>> thp_shmem=[KMG],[KMG]:;[KMG]- >>>>>>>> [KMG]: >>>>>>>> >>>>>>>> For example, >>>>>>>> >>>>>>>> thp_shmem=16K-64K:always;128K,512K:inherit;256K:advise;1M-2M:never;4M-8M:within_size >>>>>>>> >>>>>>>> By configuring the default policy of several shmem hugepages, the >>>>>>>> user >>>>>>>> can take advantage of mTHP before it's been configured through sysfs. >>>>>>>> >>>>>>>> Signed-off-by: Maíra Canal >>>>>>>> --- >>>>>>>> .../admin-guide/kernel-parameters.txt | 10 ++ >>>>>>>> Documentation/admin-guide/mm/transhuge.rst | 17 +++ >>>>>>>> mm/shmem.c | 109 +++++++++++++ >>>>>>>> ++++- >>>>>>>> 3 files changed, 135 insertions(+), 1 deletion(-) >>>>>>>> >>>>>> >>>>>> [...] >>>>>> >>>>>>>> diff --git a/mm/shmem.c b/mm/shmem.c >>>>>>>> index dfcc88ec6e34..c2299fa0b345 100644 >>>>>>>> --- a/mm/shmem.c >>>>>>>> +++ b/mm/shmem.c >>>>>>>> @@ -136,6 +136,7 @@ static unsigned long huge_shmem_orders_always >>>>>>>> __read_mostly; >>>>>>>> static unsigned long huge_shmem_orders_madvise __read_mostly; >>>>>>>> static unsigned long huge_shmem_orders_inherit __read_mostly; >>>>>>>> static unsigned long huge_shmem_orders_within_size __read_mostly; >>>>>>>> +static bool shmem_orders_configured __initdata; >>>>>>>> #endif >>>>>>>> #ifdef CONFIG_TMPFS >>>>>>>> @@ -5027,7 +5028,8 @@ void __init shmem_init(void) >>>>>>>> * Default to setting PMD-sized THP to inherit the global >>>>>>>> setting and >>>>>>>> * disable all other multi-size THPs. >>>>>>>> */ >>>>>>>> - huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); >>>>>>>> + if (!shmem_orders_configured) >>>>>>>> + huge_shmem_orders_inherit = BIT(HPAGE_PMD_ORDER); >>>>>>>> #endif >>>>>>>> return; >>>>>>>> @@ -5180,6 +5182,26 @@ struct kobj_attribute >>>>>>>> thpsize_shmem_enabled_attr = >>>>>>>> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) >>>>>>>> +static inline int get_order_from_str(const char *size_str) >>>>>>>> +{ >>>>>>>> + unsigned long size; >>>>>>>> + char *endptr; >>>>>>>> + int order; >>>>>>>> + >>>>>>>> + size = memparse(size_str, &endptr); >>>>>>>> + >>>>>>>> + if (!is_power_of_2(size)) >>>>>>>> + goto err; >>>>>>>> + order = get_order(size); >>>>>>>> + if (BIT(order) & ~THP_ORDERS_ALL_FILE_DEFAULT) >>>>>>>> + goto err; >>>>>>>> + >>>>>>>> + return order; >>>>>>>> +err: >>>>>>>> + pr_err("invalid size %s in thp_shmem boot parameter\n", >>>>>>>> size_str); >>>>>>>> + return -EINVAL; >>>>>>>> +} >>>>>>> >>>>>>> Hm, mostly copy and paste. You could reuse existing >>>>>>> get_order_from_str() >>>>>>> simply by passing in the supported orders and moving error >>>>>>> reporting to >>>>>>> the caller. >>>>>>> >>>>>> >>>>>> Can I use functions from mm/huge_memory.c here? >>>>> >>>>> Yes, that's the idea. >>>>> >>>> >>>> Unfortunately, it isn't possible without adding the function to a >>>> header. >>> >>> Well ... sure, what's the problem with that? >> >> David & Barry, how do you feel about adding `get_order_from_str()` to >> lib/cmdline.c? > > I'd vote to leave it as is. If, at some point, the controls for shared memory > and anonymous memory are moved to a file, that would be the right time > to call the same get_order_from_str() for both. > > This is too trivial to warrant being an exposed API in huge_memory.h > or cmdline. I ... don't quite agree. cmdline.c is probably a bit excessive and I wouldn't suggest that at this point. This seems like a reasonable helper function to have as inline in mm/internal.h. ... unless I am missing something important and the obvious code duplication is warranted. -- Cheers, David / dhildenb