Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32055774rwd; Fri, 7 Jul 2023 08:06:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFpK6pTKIGQPDtRlFtJMtsljsuRHrnWtwdF3bmDc9afxNR9UTPFf+48hKNf/L8rd5k2qEpV X-Received: by 2002:a17:903:495:b0:1b8:8dbd:e1a0 with SMTP id jj21-20020a170903049500b001b88dbde1a0mr4507864plb.13.1688742402947; Fri, 07 Jul 2023 08:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688742402; cv=none; d=google.com; s=arc-20160816; b=Aro3MPlB7Lhnh/HFAb9se2B5V94lHXXsctRf4M/Tuzw4OGi6H68qL3sw3HvjQ5vdj2 fNv04gLo8KSvjPOKBCkCrPYgv2HNtwPaHmDzGtT6SiDaOsoYYQUOktVJUvxfyJbMMTKY CaJJmU75c5wP2KsrxlPQcDQHaACe/MRUhyAa9w+Zf7yQwxPUEBX7wf7hrJGfkcuTrcGi G226CiQGnJf+XCGcACE9AFH4uhGARQdvOwA13AVDneETElsYIN2S/PxP/mTVkRTlRh7Z U1IYcw6wfVzRTKKU4dysLIfqCMt7/PMu07sipYJ0jvJhwx1Zd43hXRyzDo83FmNcu47K G4CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=OlC2iXIzLQA3lWZwQgQsQkPg2mfqo3LAJWALzfWOUOw=; fh=2I37KkNTS+RmJ6M3ct1Fg2YrdMwmnlECrSSDOs8WPW0=; b=SGK31b5KAGj/tx8uJt9U4NmhQUz1UVo/DWSsilHC9juEnjL34tJvdCvrk54fIIyEra aMiRuikFO+7DRcLriCUQGDOdo9mj/jIjib5tZ0/qDHZcr9qB0bFTYMfLGMdBaeUGpTvB YEumZxCsE6YRRdG/zKCibz7pkgcXrVJLVXY7mUJFMoXP6sHoqfkJG6lTrG5i9IjbmmL2 G2I+PdbYP7OCuZI/G6SYkeaHEsXOwf6nliJJ50fvKW3Mp5JCA1e94AmFr3aWlrtckLsn HkeGs9F7X4mB6qb+JToJxOE4OWF3zk/fky48gJL5tGvLl9W0PGGMegYqBWfkj+UEZncC y35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FSOhCULs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q8-20020a17090311c800b001a6ade4c8c2si3951093plh.142.2023.07.07.08.06.29; Fri, 07 Jul 2023 08:06:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FSOhCULs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbjGGOKF (ORCPT + 99 others); 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-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 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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