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 2A465C32771 for ; Wed, 28 Sep 2022 14:21:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 322B26B0073; Wed, 28 Sep 2022 10:21:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ABDC6B0075; Wed, 28 Sep 2022 10:21:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14C286B0078; Wed, 28 Sep 2022 10:21:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 02D8E6B0073 for ; Wed, 28 Sep 2022 10:21:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 90212A5C9B for ; Wed, 28 Sep 2022 14:21:31 +0000 (UTC) X-FDA: 79961707182.08.E3909F4 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 855C5120002 for ; Wed, 28 Sep 2022 14:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664374888; 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=ABN18yfHanO7kyNSoPzHC6Sw/2197qbN8zEEWo7VMtY=; b=by/2m1xhNr32aTY9QgtqDNf2MraIDGTSsdHSTqQFBfWYVp5w7ESYtrBQ0c3o7JHQ5BjUM8 WXfzMGRYYiHgZJoQ0vW2EVvQbsUWBXbuyAP4ApqdLBjwK0LF3/2ab+IPi/DzdujKq3HOIW 9pbLuQFzP4BK6OthrOrAOSA2O9//KKA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-460-BmxGsRTWOzy28p3EJTW_2w-1; Wed, 28 Sep 2022 10:21:27 -0400 X-MC-Unique: BmxGsRTWOzy28p3EJTW_2w-1 Received: by mail-wr1-f71.google.com with SMTP id s16-20020adf9790000000b0022cc14c6114so1390047wrb.0 for ; Wed, 28 Sep 2022 07:21:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=ABN18yfHanO7kyNSoPzHC6Sw/2197qbN8zEEWo7VMtY=; b=zlCMvNl820ycX1HxHVYEc3lTgm4Cwl5gcKLd0AM4cUao9zp2d/HDuxXgY49JO7g8cd 9U8JACsuPNuDEyZclQ/0PQX4lH++XfTybYWMuouiJonV6NHhlPeyBZEj2j7BIImacPLf jqPNQ2stvblpJcIRCO49YDAUlSHMMyTai5fjM0744YiXtj2zLSx53om7mJ9aNAFpLeYn pDyjCkd8CNGzrD6+hQ2ypVsqFA/onhJSPZ0vjRMXz4Gs/RamlkF3puqVnEs3fc38vzS1 hdezmf9ZWXI5WtmTat1fUFFhVUzZVYUr8QolUqUYp/Zk95i/1Pn1PSM2QomPptplQFHk 37kA== X-Gm-Message-State: ACrzQf0c2Dao3ogSeGSkXZH09sCaCp9ku4xsVU6ixyVXl+MIe+pxWGiz ezKmRzlvMghPF/frp+eQJSJTE96RaSl5oRISNlSr2oJLWQtaK4Nj7jHEMtYu/S+xa+Q7umME8kl McIB4W8KrHAM= X-Received: by 2002:a05:6000:15c5:b0:22a:49be:8000 with SMTP id y5-20020a05600015c500b0022a49be8000mr20744031wry.664.1664374886297; Wed, 28 Sep 2022 07:21:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tIcpuiIyedOneJ1v6hq/Mzp3X1zKbADLxiYOcp0L2BRdElXCAhDOsv8YxCZ/j66uq4QtC2w== X-Received: by 2002:a05:6000:15c5:b0:22a:49be:8000 with SMTP id y5-20020a05600015c500b0022a49be8000mr20744010wry.664.1664374885974; Wed, 28 Sep 2022 07:21:25 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:1100:add9:5f61:6b94:7540? (p200300cbc7041100add95f616b947540.dip0.t-ipconnect.de. [2003:cb:c704:1100:add9:5f61:6b94:7540]) by smtp.gmail.com with ESMTPSA id bg14-20020a05600c3c8e00b003b341a2cfadsm1860497wmb.17.2022.09.28.07.21.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 07:21:25 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2022 16:21:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH 0/3] THP Shrinker To: alexlzhu@fb.com, linux-mm@kvack.org Cc: willy@infradead.org, akpm@linux-foundation.org, riel@surriel.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, kernel-team@fb.com References: From: David Hildenbrand Organization: Red Hat In-Reply-To: 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664374890; a=rsa-sha256; cv=none; b=QjLiMPE8bV1wPon/MSv00ACtwHBQwtsB9E0JWzjOoQlRcgnj0zBaM3G/DXdvq7v3LiJZKH 4HOs50MTL83Wzhy70raJeLCm3bdaU+fZ35ej7o6mzkWfT08p5MlQjaoYfcDnRQVaclksp3 lQhjDZ34boJlktrtl1J/v6+fuVX/4h0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="by/2m1xh"; 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=1664374890; 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=ABN18yfHanO7kyNSoPzHC6Sw/2197qbN8zEEWo7VMtY=; b=8ZLKWOIEhczC6rkqZad+PRV5Fvay0ekVFR782QpKuAjjNtiZIjx1kEjMQSrNwGbHllya/R Rx87dftLZoChXFuvxjDtW0oEt3MMjOfivPN1rjV8o3WoT7zWIKDa6QsriG++8sp1H9srMY aLCUZ+lvoygolyYDFvHVAH+h40YzYF8= X-Rspamd-Server: rspam10 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="by/2m1xh"; 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 X-Stat-Signature: 7zjw97om7dfbnk1hzyegzjgnbsf9opdt X-Rspamd-Queue-Id: 855C5120002 X-HE-Tag: 1664374889-588132 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 28.09.22 08:44, alexlzhu@fb.com wrote: > From: Alexander Zhu > > Transparent Hugepages use a larger page size of 2MB in comparison to > normal sized pages that are 4kb. A larger page size allows for fewer TLB > cache misses and thus more efficient use of the CPU. Using a larger page > size also results in more memory waste, which can hurt performance in some > use cases. THPs are currently enabled in the Linux Kernel by applications > in limited virtual address ranges via the madvise system call. The THP > shrinker tries to find a balance between increased use of THPs, and > increased use of memory. It shrinks the size of memory by removing the > underutilized THPs that are identified by the thp_utilization scanner. > > In our experiments we have noticed that the least utilized THPs are almost > entirely unutilized. > > Sample Output: > > Utilized[0-50]: 1331 680884 > Utilized[51-101]: 9 3983 > Utilized[102-152]: 3 1187 > Utilized[153-203]: 0 0 > Utilized[204-255]: 2 539 > Utilized[256-306]: 5 1135 > Utilized[307-357]: 1 192 > Utilized[358-408]: 0 0 > Utilized[409-459]: 1 57 > Utilized[460-512]: 400 13 > Last Scan Time: 223.98s > Last Scan Duration: 70.65s > > Above is a sample obtained from one of our test machines when THP is always > enabled. Of the 1331 THPs in this thp_utilization sample that have from > 0-50 utilized subpages, we see that there are 680884 free pages. This > comes out to 680884 / (512 * 1331) = 99.91% zero pages in the least > utilized bucket. This represents 680884 * 4KB = 2.7GB memory waste. > > Also note that the vast majority of pages are either in the least utilized > [0-50] or most utilized [460-512] buckets. The least utilized THPs are > responsible for almost all of the memory waste when THP is always > enabled. Thus by clearing out THPs in the lowest utilization bucket > we extract most of the improvement in CPU efficiency. We have seen > similar results on our production hosts. > > This patchset introduces the THP shrinker we have developed to identify > and split the least utilized THPs. It includes the thp_utilization > changes that groups anonymous THPs into buckets, the split_huge_page() > changes that identify and zap zero 4KB pages within THPs and the shrinker > changes. It should be noted that the split_huge_page() changes are based > off previous work done by Yu Zhao. > > In the future, we intend to allow additional tuning to the shrinker > based on workload depending on CPU/IO/Memory pressure and the > amount of anonymous memory. The long term goal is to eventually always > enable THP for all applications and deprecate madvise entirely. > > In production we thus far have observed 2-3% reduction in overall cpu > usage on stateless web servers when THP is always enabled. What's the diff to the RFC? -- Thanks, David / dhildenb