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 1A198C3DA4A for ; Thu, 1 Aug 2024 06:09:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2E1F6B0099; Thu, 1 Aug 2024 02:09:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DE2E6B009A; Thu, 1 Aug 2024 02:09:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A6656B009B; Thu, 1 Aug 2024 02:09:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6E98C6B0099 for ; Thu, 1 Aug 2024 02:09:57 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id ECC201608E1 for ; Thu, 1 Aug 2024 06:09:56 +0000 (UTC) X-FDA: 82402650792.17.7404989 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf29.hostedemail.com (Postfix) with ESMTP id 2914912001E for ; Thu, 1 Aug 2024 06:09:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=E47tasuo; spf=pass (imf29.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722492550; 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=2Eg+RUP9iU4Lo9A3KNo9HLoGW6thPDnN1L6pmuhPpEY=; b=PMa5ShbyQGY12dUTjc+7zgOtsGp6Ovb25x40oUzAmvFAjxBj2Fb2IEycy4FUT8BurRwvEg cYwJcLSR8AXTjNOB24rFi9IxZeF9eLlz/Hh76xZ294ikCS/jDnK4mUBEXkAxzSrIaFdq2w xV5EGUWyMo4U55SRjNP4XZZLCWK/Qu8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=E47tasuo; spf=pass (imf29.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722492550; a=rsa-sha256; cv=none; b=608tS613+Bg2GLqh3leg2FFuQfvSCqtsCeWsE0yvJwrfEAc93E8Zv39h+VldYbnU9B78wX WJJv1EN3DKEZej4wY7i+oa7LZUsUL34ynXfMz1d4vLadGTU2KspEXjfgOFgHX8nxuSaash /nG0QXDsKFsL44bVY6DLSAJOsKf1qEg= Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-44fdc70e695so752841cf.0 for ; Wed, 31 Jul 2024 23:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722492594; x=1723097394; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2Eg+RUP9iU4Lo9A3KNo9HLoGW6thPDnN1L6pmuhPpEY=; b=E47tasuoAcfuYKdgwqsiqOBVmaq0Wcpx230qXtM8tM48/MDB0C/tC0FIBaWP1k9yYY 181yllYGMhRn1uczf+meXRBF865ikEfvke6iKXnkZfxjjDH6Z9iORoHJhLSc5Vdd9SRP FqZjosYn2dYYL/JcFIyzBLfg/zrML9Snx+aU3jOniCOmZuvjDvDKXzkTeqvKrqeYRbm4 absU/5ToSjNvrSXuGiDBLWP2Onui/cHiuEMkBkVjq0+bUbcY7ZrT4Y4cFcPC6ofPi35m AGsm/UvHOcTpPKeSzkiyqjz7bII+2GoqU903hgEMTJ8FLJ1yk2UOUguaxAhPRXl2tG6/ OApQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722492594; x=1723097394; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Eg+RUP9iU4Lo9A3KNo9HLoGW6thPDnN1L6pmuhPpEY=; b=XBGTfQofWHbXvu5l/WdHT8zbMqTih4fphmILP+XTYBN/OQaMzWd5FsV2iu5tCN+81t MkNhkIayZRGN0I1ARmHH5xa4dDqDkZABtcqoQSRCYh/d02EKAtuGVu8ZCgDP05COul5j K2XmtUWoTDdpvqcRel0eZdGmEMYwXVrAAiq+nRs0SVjKiiVgQQHL2r8ITjhuKBOk+uvr GPRh43qQrUEvKVoel7Go/YhRhZiHyrAWZCqOZhM02aBIopBwZDuYoVaBwQrKiR1IRGod 9ndVSZYmbNmyXN1e1jjsyP79Q2hlqhoKZnaEtwvNDaC2Y44ndpBKYZdVbNuPEWlAmb0C EBMA== X-Forwarded-Encrypted: i=1; AJvYcCWV0PxpjN0tU4m3rfhgokoi6ESg1AVLRbAntiJxUeFCHahlmIlmnAczIT0ULUfk33xlRKmJLN6I3TMLB19kGemb0m4= X-Gm-Message-State: AOJu0YwsjTLfkWwqCH1tWGWRYGyL5mESBSDZgJhV+6spCC5QapXYBlhC +QPTjXqaC5ZeOKtfZG7MIWc3zTjjQde/jog4So1MOM8icfXrVUIckSHG0Kv58MVhsJvI9lnTFQQ SVzAAtew1I3EdF1mCDZ01wElKnpkh6L284RwC X-Google-Smtp-Source: AGHT+IE32QTSyXkgVRiA98YySoDS2GugHQvPGGCTz+jLkfFLBYvzI9l2JDRt7v8P/NPfxMKkZ2qSPwQZMxJetASvTrQ= X-Received: by 2002:a05:622a:1a9e:b0:447:ed90:7396 with SMTP id d75a77b69052e-45180b4b862mr1352661cf.24.1722492593997; Wed, 31 Jul 2024 23:09:53 -0700 (PDT) MIME-Version: 1.0 References: <20240730125346.1580150-1-usamaarif642@gmail.com> In-Reply-To: <20240730125346.1580150-1-usamaarif642@gmail.com> From: Yu Zhao Date: Thu, 1 Aug 2024 00:09:16 -0600 Message-ID: Subject: Re: [PATCH 0/6] mm: split underutilized THPs To: Usama Arif Cc: akpm@linux-foundation.org, linux-mm@kvack.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, roman.gushchin@linux.dev, david@redhat.com, baohua@kernel.org, ryan.roberts@arm.com, rppt@kernel.org, willy@infradead.org, cerasuolodomenico@gmail.com, corbet@lwn.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: j3dioccesty4qjg1ie8simdd4meaac1p X-Rspam-User: X-Rspamd-Queue-Id: 2914912001E X-Rspamd-Server: rspam02 X-HE-Tag: 1722492594-62705 X-HE-Meta: U2FsdGVkX1+dUjkspj5g+aeXIrn8r38RQI1+28nU2KFOjDK6ZYYh4oeQu6rYeqvidHu3d5FyHX66DWxGl4fv6Rt7hJTxmvnUDZG/qJO1W0Wha9YKTZKzCYNwKRbESH8Hds9pjS4L9ZiD4x0TOTDZWQwQF8JBf4V8ajzhxBa3cnteSS1NVV1UX5jSoaiNZH7hz5Jsl+JzgrSPNWUaocMkCZQcxlESyrPoeYCAOMz4+k5HyZl7V5nKudomT/sQ+1DiCbB0CjpgRu/sjawTcNEMK9mlDooOqZe24TuASeypto0AL7lqnSget4nYhh1DRVTJ12TLMSkNoJGMpvBPFvbibO4Q7RHRtjU9JrBi39zHp8sYu3WMpytjRiJHGG/hCy/VZ2TPKBswHHP7CgrklWLX1Xpu8iPwzAlyOuC0KDKKsXswmG+Zg7uPbgh6H+659WINEmAXmHtoT5ZXW9ND9CpznaHNjCAPghN/xuv00iRxdva06LCxaC+DE6t7ZBEUSgClDIdYJPh9SOgQWdvb2YOPwtfj4YiMU8FUQk/JZjNspzkQrdN7u/O3Yjpe6MqgUK7R1/eF4JprW8JRGtzcnP7k749aTn+NNl/bEHauAc+R/v/ZTp2c3lZkeYKocDBwvaZRfHrl+1u3VujOu1rl0iemRvTtaWVpsnkepu21cCIm99BLBxLYPkXSeTlXVaDRyhQLq5UrLIVcR3IP8RIMuEyI/Np+ySVPWavDnS5xDmflLsFh4A0CC392xjOOqmdysAEyUkjV29cOomUPrqbcjd8j+9i+m0orrEUo6gl7SgsLnGdogkPigTgkWygvQ9djhZyEFwRox3nwIsDOprtEWRKDP0u981RJnVipZH/QoyEV5zEHgEwG168JKk4j6mDUhvO0zrTqA/X1ByUNAc+RpiArGzvku/Dn2/8N/AtjsAO8bPMqoXKBmcClZSFEMATXTnmtTBsS6DYU3Umub/nE/oG dIleuL7B wDudTAKpgOzrNDBunoWZe7oJGSt5lDZKk3C04HwMCmzWconeBSO2qYtBTaavNJwICaVyeM3iCp9VN7SBoX+/IlI4+t1SZ6+eUTauqX1jT+vMCe/itgGdIHQ1vt4yOh5KlP+glfAUtl4UKptN0BGOpA7ny+YsZ0taZLvTmfzqS3o19yAJGm8xolboYE4ODxj9anuwrGhvPBloma+aiurOrSYK/eLB1VIsLC5Cv3GtKqrjJIteV52Ns8RFttnV7aWRKe1OHNsfrREE53TPGONtQq5bS1zAQBIpAJ5ybcg5K7AGljVk0He4Ezm38JUD8iunAovCDwiGLmwFs6j75B0sni+WnWYvZX8v0/5dV8DBy/ECB7LO0ZnaVHNnBww== 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: List-Subscribe: List-Unsubscribe: On Tue, Jul 30, 2024 at 6:54=E2=80=AFAM Usama Arif = wrote: > > The current upstream default policy for THP is always. However, Meta > uses madvise in production as the current THP=3Dalways policy vastly > overprovisions THPs in sparsely accessed memory areas, resulting in > excessive memory pressure and premature OOM killing. > Using madvise + relying on khugepaged has certain drawbacks over > THP=3Dalways. Using madvise hints mean THPs aren't "transparent" and > require userspace changes. Waiting for khugepaged to scan memory and > collapse pages into THP can be slow and unpredictable in terms of perform= ance > (i.e. you dont know when the collapse will happen), while production > environments require predictable performance. If there is enough memory > available, its better for both performance and predictability to have > a THP from fault time, i.e. THP=3Dalways rather than wait for khugepaged > to collapse it, and deal with sparsely populated THPs when the system is > running out of memory. > > This patch-series is an attempt to mitigate the issue of running out of > memory when THP is always enabled. During runtime whenever a THP is being > faulted in or collapsed by khugepaged, the THP is added to a list. > Whenever memory reclaim happens, the kernel runs the deferred_split > shrinker which goes through the list and checks if the THP was underutili= zed, > i.e. how many of the base 4K pages of the entire THP were zero-filled. > If this number goes above a certain threshold, the shrinker will attempt > to split that THP. Then at remap time, the pages that were zero-filled ar= e > not remapped, hence saving memory. This method avoids the downside of > wasting memory in areas where THP is sparsely filled when THP is always > enabled, while still providing the upside THPs like reduced TLB misses wi= thout > having to use madvise. > > Meta production workloads that were CPU bound (>99% CPU utilzation) were > tested with THP shrinker. The results after 2 hours are as follows: > > | THP=3Dmadvise | THP=3Dalways | THP=3Dalw= ays > | | | + shrinker se= ries > | | | + max_ptes_no= ne=3D409 > -------------------------------------------------------------------------= ---- > Performance improvement | - | +1.8% | +1.7% > (over THP=3Dmadvise) | | | > -------------------------------------------------------------------------= ---- > Memory usage | 54.6G | 58.8G (+7.7%) | 55.9G (+2.4= %) > -------------------------------------------------------------------------= ---- > max_ptes_none=3D409 means that any THP that has more than 409 out of 512 > (80%) zero filled filled pages will be split. > > To test out the patches, the below commands without the shrinker will > invoke OOM killer immediately and kill stress, but will not fail with > the shrinker: > > echo 450 > /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none > mkdir /sys/fs/cgroup/test > echo $$ > /sys/fs/cgroup/test/cgroup.procs > echo 20M > /sys/fs/cgroup/test/memory.max > echo 0 > /sys/fs/cgroup/test/memory.swap.max > # allocate twice memory.max for each stress worker and touch 40/512 of > # each THP, i.e. vm-stride 50K. > # With the shrinker, max_ptes_none of 470 and below won't invoke OOM > # killer. > # Without the shrinker, OOM killer is invoked immediately irrespective > # of max_ptes_none value and kill stress. > stress --vm 1 --vm-bytes 40M --vm-stride 50K > > Patches 1-2 add back helper functions that were previously removed > to operate on page lists (needed by patch 3). > Patch 3 is an optimization to free zapped tail pages rather than > waiting for page reclaim or migration. > Patch 4 is a prerequisite for THP shrinker to not remap zero-filled > subpages when splitting THP. > Patches 6 adds support for THP shrinker. > > (This patch-series restarts the work on having a THP shrinker in kernel > originally done in > https://lore.kernel.org/all/cover.1667454613.git.alexlzhu@fb.com/. > The THP shrinker in this series is significantly different than the > original one, hence its labelled v1 (although the prerequisite to not > remap clean subpages is the same).) > > Alexander Zhu (1): > mm: add selftests to split_huge_page() to verify unmap/zap of zero > pages > > Usama Arif (3): > Revert "memcg: remove mem_cgroup_uncharge_list()" > Revert "mm: remove free_unref_page_list()" > mm: split underutilized THPs > > Yu Zhao (2): > mm: free zapped tail pages when splitting isolated thp > mm: don't remap unused subpages when splitting isolated thp I would recommend shatter [1] instead of splitting so that 1) whoever underutilized their THPs get punished for the overhead; 2) underutilized THPs are kept intact and can be reused by others. [1] https://lore.kernel.org/20240229183436.4110845-3-yuzhao@google.com/