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 81506C001DE for ; Fri, 7 Jul 2023 14:08:23 +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:Subject:From:References:Cc:To: 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=Te/0thjsqu2Iu2O+9MuyebC6T2KxJngy7bSPmB6eYqo=; b=368u1NEJJ/urH3 xFWqZZkrC1rBdzUHE+nSiYrLe4HfNrX9MNpBg+whLdJVUNH11ZvcQEzVlTdX+QS7ISVw2WAdRJClo c7FVy5pGTaKsLxXkof01kB8A85z7BXAKgbJNxt0oz7YwGM87UBEAma4NLEH3CqQPXgsMsuOUVSdvn BII3FznU9JfWZkXUZmw71VAAbD+iBpsRyD5z6cfGuVknIJ//IM1ctnFt1t90YJ+k3EdJqZZAk4y8c mXb9viM8BdidzR9xO2kKzRlXelkMeEnPhv9jD50zclT1iAcfMO6bq0zOF3bXOwn3mJpGURaDiohNU haWMXn4dsZ9z2CKRgMzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qHm7n-004px6-2i; Fri, 07 Jul 2023 14:07:55 +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 1qHm7l-004pw3-1v for linux-arm-kernel@lists.infradead.org; Fri, 07 Jul 2023 14:07:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688738872; 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=OlC2iXIzLQA3lWZwQgQsQkPg2mfqo3LAJWALzfWOUOw=; b=CmVa39LtDP29UCI4xlN6D2Xj3hSyLknsqDZmdu/4p0viEGfx9quGKMMF0tdK9JvQO6ApxY B4uaLcKwzahyyNyxDY7Kw9h/JvA/a77gCm/kGwwqxb2bTiRgol3kJd4x6JoE7Y//x//Ydt dN4Cr/Hdh+hb89XFYX9nvs5ImxCPVt4= 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-82-x5cvs1EvNb-XCgMCr0lMZQ-1; Fri, 07 Jul 2023 10:07:51 -0400 X-MC-Unique: x5cvs1EvNb-XCgMCr0lMZQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fbdf34184eso11610255e9.1 for ; Fri, 07 Jul 2023 07:07:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688738867; x=1691330867; 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=OlC2iXIzLQA3lWZwQgQsQkPg2mfqo3LAJWALzfWOUOw=; b=BLzIw+epPWh99trInjZHna81gy5waagG1bSWbQ5JH1aHL4wGfnY84noM3k/Ya08N4p pm9NLmoGckaYSuMIl1NlszoXEr0aPvPDCQgPn28Z40P8eCIlrpRVrNrFBDwlap6ZtDzk yPU1yxLuLA1+tY8R3YnCPvKOBsuxeBQ5CT8SmnBsKoHge8g3T4XxbhbopqvdbxZkk16c v7pSMZtWiY9jvYx2ktX+pp5/Qrf0zzMwHHYdv94e+OrfG/R1IbANIW0fSHjcd+H4/hv1 hEA6dkGLdbFNhtH4sq4pJwRrV5F3j+P/TybRrS9ZffJb3s2kcB2CshKm841PNKjfgDus ElMw== X-Gm-Message-State: ABy/qLbRIxjP9E8u22g7WRbeDSdod04++Vo/CVvqzqkq5Dx8GTXvWe8o ySaYhgSzaJs0Gw51MqEjZBJk1qD8OBdKxpzujqWInExrSZYvmaSwO4TRlBLxBU1ns/IVPOwWktz zHHhRkdtGnV7ooCpNjCVujk6Y/kKkgwzMsfar3ZhRApI= X-Received: by 2002:a1c:4c09:0:b0:3f8:f1db:d206 with SMTP id z9-20020a1c4c09000000b003f8f1dbd206mr4038602wmf.25.1688738867023; Fri, 07 Jul 2023 07:07:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFyKYecEsefKx61xe08GTcuK37noRkMqXHT3eR9Z1Eg7QLfbEP9g0GcKdt4S/xrCRjDAxDhEg== X-Received: by 2002:a1c:4c09:0:b0:3f8:f1db:d206 with SMTP id z9-20020a1c4c09000000b003f8f1dbd206mr4038581wmf.25.1688738866619; Fri, 07 Jul 2023 07:07:46 -0700 (PDT) Received: from ?IPV6:2003:d8:2f04:3c00:248f:bf5b:b03e:aac7? (p200300d82f043c00248fbf5bb03eaac7.dip0.t-ipconnect.de. [2003:d8:2f04:3c00:248f:bf5b:b03e:aac7]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c020c00b003f819faff24sm2584225wmi.40.2023.07.07.07.07.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jul 2023 07:07:46 -0700 (PDT) Message-ID: <1e406f04-78ef-6573-e1f1-f0d0e0d5246a@redhat.com> Date: Fri, 7 Jul 2023 16:07:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: Matthew Wilcox Cc: Ryan Roberts , "Huang, Ying" , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230703135330.1865927-1-ryan.roberts@arm.com> <20230703135330.1865927-5-ryan.roberts@arm.com> <87edlkgnfa.fsf@yhuang6-desk2.ccr.corp.intel.com> <44e60630-5e9d-c8df-ab79-cb0767de680e@arm.com> <524bacd2-4a47-2b8b-6685-c46e31a01631@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 4/5] mm: FLEXIBLE_THP for improved performance In-Reply-To: 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-20230707_070753_702305_708142DC X-CRM114-Status: GOOD ( 27.87 ) 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 07.07.23 15:57, Matthew Wilcox wrote: > On Fri, Jul 07, 2023 at 01:29:02PM +0200, David Hildenbrand wrote: >> On 07.07.23 11:52, Ryan Roberts wrote: >>> On 07/07/2023 09:01, Huang, Ying wrote: >>>> Although we can use smaller page order for FLEXIBLE_THP, it's hard to >>>> avoid internal fragmentation completely. So, I think that finally we >>>> will need to provide a mechanism for the users to opt out, e.g., >>>> something like "always madvise never" via >>>> /sys/kernel/mm/transparent_hugepage/enabled. I'm not sure whether it's >>>> a good idea to reuse the existing interface of THP. >>> >>> I wouldn't want to tie this to the existing interface, simply because that >>> implies that we would want to follow the "always" and "madvise" advice too; That >>> means that on a thp=madvise system (which is certainly the case for android and >>> other client systems) we would have to disable large anon folios for VMAs that >>> haven't explicitly opted in. That breaks the intention that this should be an >>> invisible performance boost. I think it's important to set the policy for use of >> >> It will never ever be a completely invisible performance boost, just like >> ordinary THP. >> >> Using the exact same existing toggle is the right thing to do. If someone >> specify "never" or "madvise", then do exactly that. >> >> It might make sense to have more modes or additional toggles, but >> "madvise=never" means no memory waste. > > I hate the existing mechanisms. They are an abdication of our > responsibility, and an attempt to blame the user (be it the sysadmin > or the programmer) of our code for using it wrongly. We should not > replicate this mistake. I don't agree regarding the programmer responsibility. In some cases the programmer really doesn't want to get more memory populated than requested -- and knows exactly why setting MADV_NOHUGEPAGE is the right thing to do. Regarding the madvise=never/madvise/always (sys admin decision), memory waste (and nailing down bugs or working around them in customer setups) have been very good reasons to let the admin have a word. > > Our code should be auto-tuning. I posted a long, detailed outline here: > https://lore.kernel.org/linux-mm/Y%2FU8bQd15aUO97vS@casper.infradead.org/ > Well, "auto-tuning" also should be perfect for everybody, but once reality strikes you know it isn't. If people don't feel like using THP, let them have a word. The "madvise" config option is probably more controversial. But the "always vs. never" absolutely makes sense to me. >> I remember I raised it already in the past, but you *absolutely* have to >> respect the MADV_NOHUGEPAGE flag. There is user space out there (for >> example, userfaultfd) that doesn't want the kernel to populate any >> additional page tables. So if you have to respect that already, then also >> respect MADV_HUGEPAGE, simple. > > Possibly having uffd enabled on a VMA should disable using large folios, There are cases where we enable uffd *after* already touching memory (postcopy live migration in QEMU being the famous example). That doesn't fly. > I can get behind that. But the notion that userspace knows what it's > doing ... hahaha. Just ignore the madvise flags. Userspace doesn't > know what it's doing. If user space sets MADV_NOHUGEPAGE, it exactly knows what it is doing ... in some cases. And these include cases I care about messing with sparse VM memory :) I have strong opinions against populating more than required when user space set MADV_NOHUGEPAGE. -- Cheers, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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 7D853C001DE for ; Fri, 7 Jul 2023 14:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232744AbjGGOKF (ORCPT ); Fri, 7 Jul 2023 10:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233019AbjGGOJz (ORCPT ); Fri, 7 Jul 2023 10:09:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E7826A1 for ; Fri, 7 Jul 2023 07:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688738869; 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=OlC2iXIzLQA3lWZwQgQsQkPg2mfqo3LAJWALzfWOUOw=; b=FSOhCULsW1PoI8wt2luQAd936ggfa2iGBk/LUym4hEo6AU4lRUX0uWEzy9U/3FozfqPBwZ jGbki0t0yODQzaZPjRTGGULs3oXUd62mhYeDDlqzZGERxx5rbY39FxYwV4gz80Xa34jy4j OF6OcmVIgrBVfIREpWiKtfRMn2vCbL0= 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-674-eR8Kgra2OKS16E-aPA8L0w-1; Fri, 07 Jul 2023 10:07:48 -0400 X-MC-Unique: eR8Kgra2OKS16E-aPA8L0w-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3faabd8fd33so11611555e9.0 for ; Fri, 07 Jul 2023 07:07:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688738867; x=1691330867; 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=OlC2iXIzLQA3lWZwQgQsQkPg2mfqo3LAJWALzfWOUOw=; b=K3QMEAJNmT2SRSFWhJVm5ykBA3Hy3IS2YDLYlmiIFn9JbOEOwo5yT+EWbsCe3XC2g3 gT4EK3ghU3qyxFvsQ3oBl+za3o9EV40F0HBE/tZhPQKoJZSODMmBeP7YzNYzmN3ZR18m KXr5BYbDJSXxxhNAvJlpWmc5h/gS+6QJbmod+8a4CoLxz1t8xiQwDI0C2T5yNZR+4gQZ lidiqjDom9ym3zT7LabHL4eMU7BGp/Z9iJV1UStkyHHfGoXrQLOSDdIX/M8K8t7gmh8q 1wutOPK5y93cRjpTbJX88UrtTIsIXamTxzZl/fGainMk75B6gXQ8x/3ITM4QalRnoIui CNTw== X-Gm-Message-State: ABy/qLYyZoI/NkRarv/AkQ7YqwS8ownHYDvxhF6A8xyA3QaF5wgpXqN8 KcjZEuDLaeG+Vw9w+nYb04/Sghs8Mor1ndkOZD+0w97cYDZCk2xzF8Mx0mSEuhO7mxYWTY6BpNc 8LXNjJTbdUnylNM/Y2tWlw6AV X-Received: by 2002:a1c:4c09:0:b0:3f8:f1db:d206 with SMTP id z9-20020a1c4c09000000b003f8f1dbd206mr4038596wmf.25.1688738867022; Fri, 07 Jul 2023 07:07:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFyKYecEsefKx61xe08GTcuK37noRkMqXHT3eR9Z1Eg7QLfbEP9g0GcKdt4S/xrCRjDAxDhEg== X-Received: by 2002:a1c:4c09:0:b0:3f8:f1db:d206 with SMTP id z9-20020a1c4c09000000b003f8f1dbd206mr4038581wmf.25.1688738866619; Fri, 07 Jul 2023 07:07:46 -0700 (PDT) Received: from ?IPV6:2003:d8:2f04:3c00:248f:bf5b:b03e:aac7? (p200300d82f043c00248fbf5bb03eaac7.dip0.t-ipconnect.de. [2003:d8:2f04:3c00:248f:bf5b:b03e:aac7]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c020c00b003f819faff24sm2584225wmi.40.2023.07.07.07.07.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Jul 2023 07:07:46 -0700 (PDT) Message-ID: <1e406f04-78ef-6573-e1f1-f0d0e0d5246a@redhat.com> Date: Fri, 7 Jul 2023 16:07:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US To: Matthew Wilcox Cc: Ryan Roberts , "Huang, Ying" , Andrew Morton , "Kirill A. Shutemov" , Yin Fengwei , Yu Zhao , Catalin Marinas , Will Deacon , Anshuman Khandual , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230703135330.1865927-1-ryan.roberts@arm.com> <20230703135330.1865927-5-ryan.roberts@arm.com> <87edlkgnfa.fsf@yhuang6-desk2.ccr.corp.intel.com> <44e60630-5e9d-c8df-ab79-cb0767de680e@arm.com> <524bacd2-4a47-2b8b-6685-c46e31a01631@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 4/5] mm: FLEXIBLE_THP for improved performance In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07.07.23 15:57, Matthew Wilcox wrote: > On Fri, Jul 07, 2023 at 01:29:02PM +0200, David Hildenbrand wrote: >> On 07.07.23 11:52, Ryan Roberts wrote: >>> On 07/07/2023 09:01, Huang, Ying wrote: >>>> Although we can use smaller page order for FLEXIBLE_THP, it's hard to >>>> avoid internal fragmentation completely. So, I think that finally we >>>> will need to provide a mechanism for the users to opt out, e.g., >>>> something like "always madvise never" via >>>> /sys/kernel/mm/transparent_hugepage/enabled. I'm not sure whether it's >>>> a good idea to reuse the existing interface of THP. >>> >>> I wouldn't want to tie this to the existing interface, simply because that >>> implies that we would want to follow the "always" and "madvise" advice too; That >>> means that on a thp=madvise system (which is certainly the case for android and >>> other client systems) we would have to disable large anon folios for VMAs that >>> haven't explicitly opted in. That breaks the intention that this should be an >>> invisible performance boost. I think it's important to set the policy for use of >> >> It will never ever be a completely invisible performance boost, just like >> ordinary THP. >> >> Using the exact same existing toggle is the right thing to do. If someone >> specify "never" or "madvise", then do exactly that. >> >> It might make sense to have more modes or additional toggles, but >> "madvise=never" means no memory waste. > > I hate the existing mechanisms. They are an abdication of our > responsibility, and an attempt to blame the user (be it the sysadmin > or the programmer) of our code for using it wrongly. We should not > replicate this mistake. I don't agree regarding the programmer responsibility. In some cases the programmer really doesn't want to get more memory populated than requested -- and knows exactly why setting MADV_NOHUGEPAGE is the right thing to do. Regarding the madvise=never/madvise/always (sys admin decision), memory waste (and nailing down bugs or working around them in customer setups) have been very good reasons to let the admin have a word. > > Our code should be auto-tuning. I posted a long, detailed outline here: > https://lore.kernel.org/linux-mm/Y%2FU8bQd15aUO97vS@casper.infradead.org/ > Well, "auto-tuning" also should be perfect for everybody, but once reality strikes you know it isn't. If people don't feel like using THP, let them have a word. The "madvise" config option is probably more controversial. But the "always vs. never" absolutely makes sense to me. >> I remember I raised it already in the past, but you *absolutely* have to >> respect the MADV_NOHUGEPAGE flag. There is user space out there (for >> example, userfaultfd) that doesn't want the kernel to populate any >> additional page tables. So if you have to respect that already, then also >> respect MADV_HUGEPAGE, simple. > > Possibly having uffd enabled on a VMA should disable using large folios, There are cases where we enable uffd *after* already touching memory (postcopy live migration in QEMU being the famous example). That doesn't fly. > I can get behind that. But the notion that userspace knows what it's > doing ... hahaha. Just ignore the madvise flags. Userspace doesn't > know what it's doing. If user space sets MADV_NOHUGEPAGE, it exactly knows what it is doing ... in some cases. And these include cases I care about messing with sparse VM memory :) I have strong opinions against populating more than required when user space set MADV_NOHUGEPAGE. -- Cheers, David / dhildenb