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 E7725C6FD1D for ; Mon, 20 Mar 2023 11:12:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 721E96B0075; Mon, 20 Mar 2023 07:12:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D2286B0078; Mon, 20 Mar 2023 07:12:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 574036B007B; Mon, 20 Mar 2023 07:12:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 451DA6B0075 for ; Mon, 20 Mar 2023 07:12:28 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2073E1C5C63 for ; Mon, 20 Mar 2023 11:12:28 +0000 (UTC) X-FDA: 80589013176.02.12A00FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id C021AC0009 for ; Mon, 20 Mar 2023 11:12:25 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A12RTTwU; spf=pass (imf28.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=1679310745; a=rsa-sha256; cv=none; b=JYO6kyDAjM7Ywe/5LVcaZO/uwB20DzheqR2nEa8pl3MWkz0eMPy6Yzac7Kwyo3BKkILucB 16dt2C44bpfNXZ9uxqWEvE+ljp+qaYbYMhohp4RLmBcd+mjm1yOkqyx5oSncadHjUsTCGd vHq/6Z+pzjnGD9cbnHD054ydsiIP4/Y= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A12RTTwU; spf=pass (imf28.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=1679310745; 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=TJ15X8eEBoReGB3C7dgMotTyQB0TWQzRlQNvijJlTog=; b=rX4f6NgzZBOQ2J2kAeKBF36llCO11gx53YMKxtgQfFg6wYsMgOP/dEgm6Dzkxgj8bNgtu/ gunnwj8NyQHhXvmfIvxYSqYVeIToUYF2GL3m/qX9Jv7EoBD6jhkU0Qm+NLgo5+v70o1byW ZhXcO1Pqd77xGOH3suhj/VJUxozxZpg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679310745; 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=TJ15X8eEBoReGB3C7dgMotTyQB0TWQzRlQNvijJlTog=; b=A12RTTwUSmNAOSyBGLFvl5q3ZCRJsH0iXlZlADgPJF3S+ISBtXIC2pyTyac7g38YCXmXss GtkV5+PlC1zaS53vJAl5HOREzVNzHdYMmfNBwOmNurZmd7VEXK5SPdKAi0UPiCHDXCJDZC B1cjjxi5gBxnaZFkKnIsTpEft6ydv54= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-k6zx4p31OOKDvpcUgCha0Q-1; Mon, 20 Mar 2023 07:12:23 -0400 X-MC-Unique: k6zx4p31OOKDvpcUgCha0Q-1 Received: by mail-wm1-f71.google.com with SMTP id i3-20020a05600c354300b003edfa408811so1140978wmq.1 for ; Mon, 20 Mar 2023 04:12:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679310742; 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=TJ15X8eEBoReGB3C7dgMotTyQB0TWQzRlQNvijJlTog=; b=kiMC3MLZ2yZt/sqle5ex4g2RI2wXbw2b8/mc5wKG0HWTda8VlR2vSCpWgi3z45wxAN iN9HptqOFanLU3n18I18J+/VdLo9/iKoYNB5gHx9iCnKx6S6gXkpPvdZmyKJa1TCd7tY d2n+EJqenTD5wrN3WmJk9vZgzqaUv5xxk62yTugT8i1FgosSvMR2pQN+BI3Sgf+xyY6M aAM3Xg4shrUe3+uFS0ADxDhd1jgHGgRYr6BkffX4AN3jNUzpJPu++mC50Kfzy8m2QfAD digXmTvUCUHLd5I2fvOxKoJuxUcNuMMeTH9+HUMiK96hxy80ZC3zWiCbTaM6ztPy86fp E41A== X-Gm-Message-State: AO0yUKUIeq2vwri5aPbYrpfKtqyMG5SU68EQE09BG8o9InVRlPG/fGu0 3H6g7cmcXjMpx1kVSLl5ACFemWXKy/+BHLP/YgD0X9wCeRoJjEaYSONiyqlXL1Qivub/kiVKIqE 3Z5vgX9Ff1rw= X-Received: by 2002:a5d:5259:0:b0:2cf:eed0:f6fb with SMTP id k25-20020a5d5259000000b002cfeed0f6fbmr14079815wrc.32.1679310742727; Mon, 20 Mar 2023 04:12:22 -0700 (PDT) X-Google-Smtp-Source: AK7set/QgW3xbA+eM9GpmqPmpL+xxrC+Ghr2e5Lw+gQQJPunHxEQKtVdh0x1jsB99FFjG5tziq1xFg== X-Received: by 2002:a5d:5259:0:b0:2cf:eed0:f6fb with SMTP id k25-20020a5d5259000000b002cfeed0f6fbmr14079797wrc.32.1679310742435; Mon, 20 Mar 2023 04:12:22 -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 f11-20020a5d4dcb000000b002cfe3f842c8sm8575853wru.56.2023.03.20.04.12.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Mar 2023 04:12:21 -0700 (PDT) Message-ID: <655ca9fd-ddc3-0bfa-b442-fc60cda02baa@redhat.com> Date: Mon, 20 Mar 2023 12:12:21 +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: Mike Kravetz , Matthew Wilcox Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230306235730.GA31451@monkey> <20230317184632.GA69459@monkey> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230317184632.GA69459@monkey> 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-Rspam-User: X-Rspamd-Queue-Id: C021AC0009 X-Rspamd-Server: rspam01 X-Stat-Signature: 1fu8131hfay1b7z3yjkd4e4878bowrda X-HE-Tag: 1679310745-367324 X-HE-Meta: U2FsdGVkX19W9u8C4jgCv76Tt3AQIrcTzYscYUHUlkmLaIaVoL/CV8cCwX/JqRmvkb0QB2LWyirAH/Gqu1nSEID7iQJCnSL3k4ly/kp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0Sy3qLCKn+To4GBT/OfVpHn4tFs6rAouqSwPqtJ9DSK5PYYIyfaWnZz9yc8mPps5hIGogABH2Y0UOBCSZJubtuoU00eCOzi/q5mmEeNCBk9ahwp4ueFfWha6vbHwcHpGviRTdsv/+CdxzUUF2yzTvYWCsg84q7jEUysyfGI5QT6c0CFeczxwRBPakCuGEKN4omRtv5iS92Hs+sVGuPIfwpjkw== 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.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