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 D7290C7618A for ; Mon, 20 Mar 2023 17:52:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6578C6B0074; Mon, 20 Mar 2023 13:52:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E0B26B0078; Mon, 20 Mar 2023 13:52:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45B536B007B; Mon, 20 Mar 2023 13:52:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 35D646B0074 for ; Mon, 20 Mar 2023 13:52:41 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EBF6D1A0F25 for ; Mon, 20 Mar 2023 17:52:40 +0000 (UTC) X-FDA: 80590021680.18.78FBED6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id B4F0312000D for ; Mon, 20 Mar 2023 17:52:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JnFqGxmC; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679334758; 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=0M2onYRimpS4fQHcg/GJxOJ+N2LxWQ9gB2aulwOb8zU=; b=IAsyjiFc1BZUZAjFxU54yko5eAclOfsvMywDcVKS/I2PQS9d8yZbybhZgNpgROAv0CxqL8 9beiPMJ28gUBn6vmTMl/opJfeCUVRldJchg35u7JHsYO4kIGCELGDcgPBwymQVMr2wI51Z 7bWsHO88607OzMZQ6B7gl5KJzWt1EJ4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JnFqGxmC; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679334758; a=rsa-sha256; cv=none; b=b+15CDf3w7AZl+MsY2/jiNcH6rmXPKu+rPblyFRzaZBXNIAgjhEwLBIp69XdXvDbXcIgXP PYgHketZ1gY48HhqTuIYUzVFVWzwyqd9ym3tbcdCjrcJvFlIwI/ZqMf3bDKaBosQH7LroO I68Wy5cRfFZ5pafPkPj+7ob5ZvcLmbw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679334758; 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=0M2onYRimpS4fQHcg/GJxOJ+N2LxWQ9gB2aulwOb8zU=; b=JnFqGxmCikqPVBcuTXH4ccgSpdBjbj5QogZMOSppLHH1KO4UNE1qmOOMC1bXUzV87kAIId r1BnCM+nw4r9/idAbr5u5QUUfJ99EQ+tbx2sMKtLzRaehUAQ/5E/exi6OyoRa2/yijE3xo 0d/P2M9qBO5jqm1JDWISYZnwATiPbC8= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-qmhR9qnFNjC8ZUk-8aqrJg-1; Mon, 20 Mar 2023 13:52:36 -0400 X-MC-Unique: qmhR9qnFNjC8ZUk-8aqrJg-1 Received: by mail-lf1-f69.google.com with SMTP id o17-20020a198c11000000b004e8706b0c72so4758501lfd.21 for ; Mon, 20 Mar 2023 10:52:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679334755; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0M2onYRimpS4fQHcg/GJxOJ+N2LxWQ9gB2aulwOb8zU=; b=J3G97J/rM64WyhyrkGn1XQVBOS0rpEeILwfRacKxNeURU15w0ZZFNCUeLAakE8yxPi J1vcVHAKgzcAU6tOrCZnktglojAAnc01pfWuP/DQIDo/Wqa7HRDsVTBdNVyrgPPCK9nR cybXBVtmhw8/HLHn8UKoRPTK2BI/YtR5/8PUhz9GnOLgFqgL+4MqSoFmBtAhMFQBRvlE vCDSEQW1WaOJbpUC7ntEPhWoBIfFec1syeBXrAstmybxKQ7QMBuO1OpUgUdlo+Tgqn4B ZKsW2TzKvXYM5If9ikmalC2LjKLbyXrGrH4t1vPkgp/XaGzOZPit5chBdBy+IG93fst8 h20Q== X-Gm-Message-State: AO0yUKXXgJx/11QOE7305b5kp0WOndd6Wa3mXJSRCqRXo0UYhg84C8hy 4GJrWU4nJlwL7er/42C9zlwrGHuS7KlXt+fgPAavhRT0VbFMDE8+28lUiL0i4WYUsfldwJbd8cq bufk2tWBZxKg= X-Received: by 2002:ac2:53aa:0:b0:4db:1b97:13 with SMTP id j10-20020ac253aa000000b004db1b970013mr234559lfh.54.1679334755336; Mon, 20 Mar 2023 10:52:35 -0700 (PDT) X-Google-Smtp-Source: AK7set/U9afes6kp2FQn3o+j3mAfQ6V4UcAbA0HnKvvF8tIfZ+eOE36u6nPlkKIZrUlBi6C8am7hyA== X-Received: by 2002:ac2:53aa:0:b0:4db:1b97:13 with SMTP id j10-20020ac253aa000000b004db1b970013mr234551lfh.54.1679334754978; Mon, 20 Mar 2023 10:52:34 -0700 (PDT) Received: from ?IPV6:2003:cb:c702:4100:a064:1ded:25ec:cf2f? (p200300cbc7024100a0641ded25eccf2f.dip0.t-ipconnect.de. [2003:cb:c702:4100:a064:1ded:25ec:cf2f]) by smtp.gmail.com with ESMTPSA id g5-20020a2e9385000000b002959d2cc975sm1844472ljh.37.2023.03.20.10.52.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Mar 2023 10:52:34 -0700 (PDT) Message-ID: <0d0fb7be-a886-bd05-b14a-a15633f60908@redhat.com> Date: Mon, 20 Mar 2023 18:52:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: THP backed thread stacks To: William Kucharski Cc: Mike Kravetz , Matthew Wilcox , Linux-MM , "linux-kernel@vger.kernel.org" References: <20230306235730.GA31451@monkey> <20230317184632.GA69459@monkey> <655ca9fd-ddc3-0bfa-b442-fc60cda02baa@redhat.com> <4A61B05E-62C6-4BC1-9301-CF12FC5A252F@oracle.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <4A61B05E-62C6-4BC1-9301-CF12FC5A252F@oracle.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: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B4F0312000D X-Rspam-User: X-Stat-Signature: ow97nyud65em3i6xp5fhdeenn7soxadb X-HE-Tag: 1679334758-94464 X-HE-Meta: U2FsdGVkX186+IHcG8aMp2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FnL65jE3y5MP+0ptBi2r/5Sy+LWDIXlJpeYJovvO5+3XZ32mpQDpeuRJjbSKJZCI8nMjEDkeCjtktUJjPpVjXxgc1Din4boUptgRw1vDd6QSPu/m6I/9eSDNNzKV7/ty7PQZqDtPasKoWRe5xoNeOZgNUhOfwLr6nurFGBWrwOMAF/Ttgt6yHRTnYfYuXRB4FDE6kvvwkjKpjO1/cTLtXKZ2doE7zK6/Ks9HJN/OHUn+/tHvBoDL08p2PtYHSa6oboUv53dcgnptXr6vAG4GV7knCMxRtmHJd+ZsIfu9MFPai5lDtH1hVtrfj6wQnnClA0pWi6aAbLV8ymchZqVS4seT1+CAHNKA2hRV5rawerqNwOucYuFCQooF+6fPpT0m1w== 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 20.03.23 18:46, William Kucharski wrote: > > >> On Mar 20, 2023, at 05:12, David Hildenbrand wrote: >> >> On 17.03.23 19:46, Mike Kravetz wrote: >>> On 03/17/23 17:52, Matthew Wilcox wrote: >>>> On Mon, Mar 06, 2023 at 03:57:30PM -0800, Mike Kravetz wrote: >>>>> One of our product teams recently experienced 'memory bloat' in their >>>>> environment. The application in this environment is the JVM which >>>>> creates hundreds of threads. Threads are ultimately created via >>>>> pthread_create which also creates the thread stacks. pthread attributes >>>>> are modified so that stacks are 2MB in size. It just so happens that >>>>> due to allocation patterns, all their stacks are at 2MB boundaries. The >>>>> system has THP always set, so a huge page is allocated at the first >>>>> (write) fault when libpthread initializes the stack. >>>> >>>> Do you happen to have an strace (or similar) so we can understand what >>>> the application is doing? >>>> >>>> My understanding is that for a normal app (like, say, 'cat'), we'll >>>> allow up to an 8MB stack, but we only create a VMA that is 4kB in size >>>> and set the VM_GROWSDOWN flag on it (to allow it to magically grow). >>>> Therefore we won't create a 2MB page because the VMA is too small. >>>> >>>> It sounds like the pthread library is maybe creating a 2MB stack as >>>> a 2MB VMA, and that's why we're seeing this behaviour? >>> Yes, pthread stacks create a VMA equal to stack size which is different >>> than 'main thread' stack. The 2MB size for pthread stacks created by >>> JVM is actually them explicitly requesting the size (8MB default). >>> We have a good understanding of what is happening. Behavior actually >>> changed a bit with glibc versions in OL7 vs OL8. Do note that THP usage >>> is somewhat out of the control of an application IF they rely on >>> glibc/pthread to allocate stacks. Only way for application to make sure >>> pthread stacks do not use THP would be for them to allocate themselves. >>> Then, they would need to set up the guard page themselves. They would >>> also need to monitor the status of all threads to determine when stacks >>> could be deleted. A bunch of extra code that glibc/pthread already does >>> for free. >>> Oracle glibc team is also involved, and it 'looks' like they may have >>> upstream buy in to add a flag to explicitly enable or disable hugepages >>> on pthread stacks. >>> It seems like concensus from mm community is that we should not >>> treat stacks any differently than any other mappings WRT THP. That is >>> OK, just wanted to throw it out there. >> >> I wonder if this might we one of the cases where we don't want to allocate a THP on first access to fill holes we don't know if they are all going to get used. But we might want to let khugepaged place a THP if all PTEs are already populated. Hm. >> >> -- >> Thanks, >> >> David / dhildenb > > Unless we do decide to start honoring MAP_STACK, we would be setting an interesting precedent here in that stacks would be the only THP allocation that would be denied a large page until it first proved it was actually going to use all the individual PAGESIZE pages comprising one. Should mapping a text page using a THP be likewise deferred until each PAGESIZE page comprising it had been accessed? IMHO, it's a bit different, because text pages are not anon pages. I suspect is_stack_mapping() -> VM_STACK -> VM_GROWSUP/VM_GROWSDOWN is not always reliable? -- Thanks, David / dhildenb