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 CEE54EB64DC for ; Mon, 17 Jul 2023 13:57:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66F516B0072; Mon, 17 Jul 2023 09:57:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61F6A8D0001; Mon, 17 Jul 2023 09:57:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BFA96B0075; Mon, 17 Jul 2023 09:57:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 38C2D6B0072 for ; Mon, 17 Jul 2023 09:57:02 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 50CF114036E for ; Mon, 17 Jul 2023 13:57:01 +0000 (UTC) X-FDA: 81021255042.24.1CB2F8C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 6DD8F1C0016 for ; Mon, 17 Jul 2023 13:56:58 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DhFsQ1iN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689602218; 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=GsphTJYgogdZknx5waKvWjKpqYHQdCeCkx39zseZOjQ=; b=k3J01XiN+EgQYySmQYIZafUc4z4yIHJpnxx6zFX5E2LsSp2GSwM+U3Yv8o7C2ujcUfrDgO O4HzcMfiMq3fIodea2QlneyxNezgyIvZQcqi0fGXZ9a5XQn52YN5pbRs9nWsk+G4FSInRe /worurdBOu0WRyBe0YT3AurzyTwKGh8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DhFsQ1iN; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689602218; a=rsa-sha256; cv=none; b=tbk5MTVKM8wJzHtq4u4hcoY6Hgp4qG3rH9ckBsGoK9SziTV4iOkWOiGaiOgHGuGq/jWAXQ fKrBwr3zCA+UXxJgnDaUn/G9gJ999b6zxhO4QYWJyh2oRdr/eN1obnfwaIx1X4l/tpYlVz I2eLpCY5KlJZhY3uvTVnC8QGy1oCaT4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689602217; 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; bh=GsphTJYgogdZknx5waKvWjKpqYHQdCeCkx39zseZOjQ=; b=DhFsQ1iNadEfH3b7X8tLp4WK8wNk+zvhmnhwpxjZMWG/ntxqbnsCcEN/Oeoi0zEfo9/Jeb Vxnwbx//O5HeFYORjws0o1L+bvcoe0XYHeTPPdatQQNPmS7iNnNqSgGqlaMkkdsUzIOQW3 iTiavukeG4HEc4nqHleQWnwDHEj84UE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-XEVDw0C_M0ekkQsBtV085g-1; Mon, 17 Jul 2023 09:56:53 -0400 X-MC-Unique: XEVDw0C_M0ekkQsBtV085g-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3fbdd5d09b8so28382365e9.1 for ; Mon, 17 Jul 2023 06:56:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689602212; x=1692194212; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GsphTJYgogdZknx5waKvWjKpqYHQdCeCkx39zseZOjQ=; b=ZemtRQd7ec0iZPD1kJ5UAsvWGFUrs11UV0bRAlIw/Tygdu0hSodIiQr8YPfTF/YSbk eqZQ4Dumc1be0AQZYQAtg77FULsQX7hkc8OZMna6EAeJSuYyQO+F8BQAT5rb1os2d7tA 6dUP961ArBM2jnHuFcBceupprNDkM1IfWzCjh1orAIiQ5r8s4oVStsK0z8xJVwSeiQ9j UXFOKzVVMjgTzRx338litu+eeLjfPecjIt4gsqhaSewJRu7hiPbUj03MUf29lFs3KSLl REK8gZF7+GZF5+eDjGH0GJjA3q0aqvKKFUmjZ0anod/iDEksNIk0nkgz1KU4obh0RaCS R7Sg== X-Gm-Message-State: ABy/qLYxaAtxUYcBBXw8eNVVbcKDQjgUWnGfQCic7++A6mtcnKhgdHsp ZP/lI7jsKbU0h5PtyKGDszCwhksHzjqwA9O9JTmKOCaW3822tprL9OmqN44rvHtEYiESF6DEwgm 7z1NAYyRgy9Y= X-Received: by 2002:a7b:c4c7:0:b0:3fb:40ff:1cba with SMTP id g7-20020a7bc4c7000000b003fb40ff1cbamr10087300wmk.6.1689602212210; Mon, 17 Jul 2023 06:56:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlGR00c8fYjZJK7OqlcVNMfa3sJanSFFtaKVXGrRbtAQl7p9wWGRMrFWUR1qBk9j7m/yMWfr1g== X-Received: by 2002:a7b:c4c7:0:b0:3fb:40ff:1cba with SMTP id g7-20020a7bc4c7000000b003fb40ff1cbamr10087267wmk.6.1689602211769; Mon, 17 Jul 2023 06:56:51 -0700 (PDT) Received: from ?IPV6:2003:cb:c735:400:2501:5a2e:13c6:88da? (p200300cbc735040025015a2e13c688da.dip0.t-ipconnect.de. [2003:cb:c735:400:2501:5a2e:13c6:88da]) by smtp.gmail.com with ESMTPSA id t15-20020a1c770f000000b003fb40f5f553sm8112540wmi.31.2023.07.17.06.56.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jul 2023 06:56:51 -0700 (PDT) Message-ID: <2e7d5692-8ba7-1e56-a03f-449f1671b100@redhat.com> Date: Mon, 17 Jul 2023 15:56:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: Ryan Roberts , Yu Zhao Cc: Andrew Morton , Matthew Wilcox , "Kirill A. Shutemov" , Yin Fengwei , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230714160407.4142030-1-ryan.roberts@arm.com> <20230714161733.4144503-3-ryan.roberts@arm.com> <82c934af-a777-3437-8d87-ff453ad94bfd@redhat.com> <2c4b2a41-1c98-0782-ac30-80e65bdb2b0c@arm.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3 3/4] mm: FLEXIBLE_THP for improved performance In-Reply-To: <2c4b2a41-1c98-0782-ac30-80e65bdb2b0c@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: wof4e7jpwja8bd6uuco6i4do5bn1b15m X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6DD8F1C0016 X-HE-Tag: 1689602218-656449 X-HE-Meta: U2FsdGVkX182oZq6R/ea1UX35ZZeU/bsM5mzQXCaxFEceAPGmXv9J5I9unp0KuUoQDlrvQMXe6F3VazTbZWJWqyquoCkPLfGaSXItXS4hmp1iYwGKE7NTjPylmafCfTL0Bn7fnc7BmUP6VE0f7oiKFEFGdnvO/PNdN88hcYf6ViCEq5s1L8MKM8WpusweYneFJCWrB5V9w5pWPNr2vvti8C9IHTcV4LtHMoUNhcGSs8FZNHAGtFTgCuNVEjPjDL2T5hPgRjkQhxnbAF/F1HkfRkHrOWLjXw+f88De4//OFlheepWkQnTNy/AfpyMmD8nSl5He4XeBxT0QSF2zJlNRC+/RAuhpv5bBli6VY87VfJIG45YspH64I62fIcyMupQOxQrsWvE+hjACIarJ7ZtdRYl/nRBCODLv7y3aqefzNcTvDbkyX35psOvDRu0rHzBHUMyAmrRkzk9h7SOD+bHHSyEJ43dsqiY8gQKngL5XmZaHZBappnUkAuM1TecwmRP4i/3QvBfNvUO1FXkaDXgN/G3t00UzKSd4wQKHtHNwQJufcXlNlVwDvyhXOxuAQcw9xM8kUA4Kn1CemaF9GnvJKtTUUpPFKu1GncPtahC0SF9sqLYy6x/7HykomDSjFk6FNiDpU3DWoHdHAwIz+zfwaChgWnwkNEGnzjkQ+qzCuqVUpO45lOPi1FQ4HEbjb8kWObMzlNcr5vvW1lakSFiMnwsWO1ZdXJc5TW3JAU3py4ranfYmLiGV8MgkBAoonCXMo8BOBajOW6643PStYx9ZK3gX2Ib++TQwcn6U3ogL44WYqW3t6wLxaqPjiRNapyCnody5VMau3CSIIJndV6XuaAj4itpvTojaA+vsyfY+Vy2pkhDy0RjhnqZT5LehYIkzT2cXQ53V2QgUcfX/rZel43kr11Beg02B3/pk7o8fzluMT3z3sKYrJ/fukFKYoMRxui9AexAkeDD60b01tU +jz6SiPu vGsmsc67PKrUtReFImB8RQklvLATnSyKtP9SJewmO9TY9UqdoHJb5rqg2ZusH8lxnmVV/uJglMmYhfqeaDm6jzPEGjwD5dFgz8zFNrL5GzCPqGMfmq2z8/PYxUBsoELOUKzNlR6MLnPLGhwm2pCdU2MXSWQDlMY/Dh2gVzmL6XEYPBpUsJpfqngU8EpqX/nTwzj0p+8WMuEJ38DBIU2KeNQnk7zKlztJGM35/0M9UUySVhZ4d2tN14VMailMu9vu6zIz6MCfmuq4BT0voIiHd9IjfAEWz0BPPyZqhUVmp7H552VttKntIrSBl3i+zq44DtZHCYnJBVWGpE4FsxJiMZEUlposQSUyTVce6Kjl60dMBWVEGq1CU3xTMRUek5MKEhiseCzraUrXz4zQ0gLlOYnJyT23fg5BgdXADVvR+dAmO98h3jL1o0XCMPsm7/eHckXRFkCOJnOZusyQk/dO3ROvz1CkkjCy4mnlnQ9V4OPa7VOU= 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: On 17.07.23 15:20, Ryan Roberts wrote: > On 17/07/2023 14:06, David Hildenbrand wrote: >> On 14.07.23 19:17, Yu Zhao wrote: >>> On Fri, Jul 14, 2023 at 10:17 AM Ryan Roberts wrote: >>>> >>>> Introduce FLEXIBLE_THP feature, which allows anonymous memory to be >>>> allocated in large folios of a determined order. All pages of the large >>>> folio are pte-mapped during the same page fault, significantly reducing >>>> the number of page faults. The number of per-page operations (e.g. ref >>>> counting, rmap management lru list management) are also significantly >>>> reduced since those ops now become per-folio. >>>> >>>> The new behaviour is hidden behind the new FLEXIBLE_THP Kconfig, which >>>> defaults to disabled for now; The long term aim is for this to defaut to >>>> enabled, but there are some risks around internal fragmentation that >>>> need to be better understood first. >>>> >>>> When enabled, the folio order is determined as such: For a vma, process >>>> or system that has explicitly disabled THP, we continue to allocate >>>> order-0. THP is most likely disabled to avoid any possible internal >>>> fragmentation so we honour that request. >>>> >>>> Otherwise, the return value of arch_wants_pte_order() is used. For vmas >>>> that have not explicitly opted-in to use transparent hugepages (e.g. >>>> where thp=madvise and the vma does not have MADV_HUGEPAGE), then >>>> arch_wants_pte_order() is limited by the new cmdline parameter, >>>> `flexthp_unhinted_max`. This allows for a performance boost without >>>> requiring any explicit opt-in from the workload while allowing the >>>> sysadmin to tune between performance and internal fragmentation. >>>> >>>> arch_wants_pte_order() can be overridden by the architecture if desired. >>>> Some architectures (e.g. arm64) can coalsece TLB entries if a contiguous >>>> set of ptes map physically contigious, naturally aligned memory, so this >>>> mechanism allows the architecture to optimize as required. >>>> >>>> If the preferred order can't be used (e.g. because the folio would >>>> breach the bounds of the vma, or because ptes in the region are already >>>> mapped) then we fall back to a suitable lower order; first >>>> PAGE_ALLOC_COSTLY_ORDER, then order-0. >>>> >>>> Signed-off-by: Ryan Roberts >>>> --- >>>>   .../admin-guide/kernel-parameters.txt         |  10 + >>>>   mm/Kconfig                                    |  10 + >>>>   mm/memory.c                                   | 187 ++++++++++++++++-- >>>>   3 files changed, 190 insertions(+), 17 deletions(-) >>>> >>>> diff --git a/Documentation/admin-guide/kernel-parameters.txt >>>> b/Documentation/admin-guide/kernel-parameters.txt >>>> index a1457995fd41..405d624e2191 100644 >>>> --- a/Documentation/admin-guide/kernel-parameters.txt >>>> +++ b/Documentation/admin-guide/kernel-parameters.txt >>>> @@ -1497,6 +1497,16 @@ >>>>                          See Documentation/admin-guide/sysctl/net.rst for >>>>                          fb_tunnels_only_for_init_ns >>>> >>>> +       flexthp_unhinted_max= >>>> +                       [KNL] Requires CONFIG_FLEXIBLE_THP enabled. The maximum >>>> +                       folio size that will be allocated for an anonymous vma >>>> +                       that has neither explicitly opted in nor out of using >>>> +                       transparent hugepages. The size must be a power-of-2 in >>>> +                       the range [PAGE_SIZE, PMD_SIZE). A larger size improves >>>> +                       performance by reducing page faults, while a smaller >>>> +                       size reduces internal fragmentation. Default: max(64K, >>>> +                       PAGE_SIZE). Format: size[KMG]. >>>> + >>> >>> Let's split this parameter into a separate patch. >>> >> >> Just a general comment after stumbling over patch #2, let's not start splitting >> patches into things that don't make any sense on their own; that just makes >> review a lot harder. > > ACK > >> >> For this case here, I'd suggest first adding the general infrastructure and then >> adding tunables we want to have on top. > > OK, so 1 patch for the main infrastructure, then a patch to disable for > MADV_NOHUGEPAGE and friends, then a further patch to set flexthp_unhinted_max > via a sysctl? MADV_NOHUGEPAGE handling for me falls under the category "required for correctness to not break existing workloads" and has to be there initially. Anything that is rather a performance tunable (e.g., a sysctl to optimize) can be added on top and discussed separately. At least IMHO :) > >> >> I agree that toggling that at runtime (for example via sysfs as raised by me >> previously) would be nicer. > > OK, I clearly misunderstood, I thought you were requesting a boot parameter. Oh, sorry about that. I wanted to actually express "/sys/kernel/mm/transparent_hugepage/" sysctls where we can toggle that later at runtime as well. > What's the ABI compat guarrantee for sysctls? I assumed that for a boot > parameter it would be easier to remove in future if we wanted, but for sysctl, > its there forever? sysctl are hard/impossible to remove, yes. So we better make sure what we add has clear semantics. If we ever want some real auto-tunable mode (and can actually implement it without harming performance; and I am skeptical), we might want to allow for setting such a parameter to "auto", for example. > > Also, how do you feel about the naming and behavior of the parameter? Very good question. "flexthp_unhinted_max" naming is a bit suboptimal. For example, I'm not so sure if we should expose the feature to user space as "flexthp" at all. I think we should find a clearer feature name to begin with. ... maybe we can initially get away with dropping that parameter and default to something reasonably small (i.e., 64k as you have above)? /sys/kernel/mm/transparent_hugepage/enabled=never and simply not get any thp. -- Cheers, David / dhildenb