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 A3312C3DA64 for ; Sun, 4 Aug 2024 21:55:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF4516B007B; Sun, 4 Aug 2024 17:55:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7CA06B0082; Sun, 4 Aug 2024 17:55:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F6066B0085; Sun, 4 Aug 2024 17:55:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 696806B007B for ; Sun, 4 Aug 2024 17:55:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 22C3EA80AF for ; Sun, 4 Aug 2024 21:55:37 +0000 (UTC) X-FDA: 82415920314.07.F98B2A8 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf26.hostedemail.com (Postfix) with ESMTP id 52F4F14000D for ; Sun, 4 Aug 2024 21:55:35 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ulqujXU/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yuzhao@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722808467; 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=P8s6/ypPv2wbuWHf/ATun4VhYJJ06DR5ZHtUhhgqlE8=; b=LgvrmncAUu1Nsw9sgXSYaP/qGjxugCAUU+T4VpeYsquX5OP20LT/RqN96dV0OcjQ3900FQ r4N5wn+FmH41Vrt10bvMwEr1fRBqvj/NLIYtMJZzQF2aWnZjz6s1WarBPJhNmsP2U/bnpE bAi+vxdYgGGRvsFtzxVoSJh/d6B7eIM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722808467; a=rsa-sha256; cv=none; b=JFZC+OFnpcEZhgAyTnigAeaDPb81WdNc++Bbu/VgH/4ScxsEffzCWDd+F0zG+Am9oS9pZJ EYFNsLtA0jHCaU0FIWJgnYh2VrId0Sn3ybtoWUEWO9u33L2Z4rFhMevleq8tdpfBPAkNw8 O6OrvKll55SBMlFx74PfRGwPqD6FPY4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="ulqujXU/"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of yuzhao@google.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=yuzhao@google.com Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-45029af1408so198691cf.1 for ; Sun, 04 Aug 2024 14:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722808534; x=1723413334; 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=P8s6/ypPv2wbuWHf/ATun4VhYJJ06DR5ZHtUhhgqlE8=; b=ulqujXU/iwRQBLQ+yFcZbnkENy0yVEeN4LyfevK/IM11H9wVxae4Vc7E9kKNi14zHd aine/paqUbSBYCBwUE8bs/s9BAjerB0moDmURhKn46kxUnyR2Tfu6BP5lmn7tf9b8ZVj LGmiTClz2Gs8nbvstKaBcXX3j0edRhd3MxqQH7QaihiS3EqscZEmKsgS50NiDsICjUNf z86dWfFSi/sPaAALwM+VZfNRi3n/g+8PmKa1nVfqV6dY1HKqB2DoM7ckVVeWZ45Cm+SC iWy7mOne2nyvk50h2ggOxtTmsRLYokhgakJhDrGyyW1vK/kHVvIJj+To21emHXX7DuSS P6pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722808534; x=1723413334; 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=P8s6/ypPv2wbuWHf/ATun4VhYJJ06DR5ZHtUhhgqlE8=; b=ichhDbEodfAjZBb2dQkUpevo8pAVdADRp/h7h3hZXejLOLxPiP8lGEiVYfl+LIWi2b wSBsFW2jROt3D5Ezbjl7odhzHNk9+zJomIHPzS9B4o91V/mhgMlrH8RTcayFhR6snWs0 jV/8hCtKfOhiJ7OWKWfw6395Ms2GXKhtO26TMxXjrnicXSMgaWT98N1RtBVWd3UmLORd lvwOs29FPZqgZ1BtjtfqkULkDZSjkAV3G1ioE3eJMcoKusMXjOdg2dOboooi1zEJARE6 2XABrO3s6HejxAF8LQEwhq6aPvE24WL+mtxRky6T/nvR8lBOi9rQdMk48WEvcRcrk+kJ T/sw== X-Forwarded-Encrypted: i=1; AJvYcCWaAyc7baSOd5IESzUjx/fzRBVFXW/EBeGqbvX9CFTZD95oj9KA/nrSf4Qc1ivFah67Twlkmmyr1qCKp4PLb0JsCj8= X-Gm-Message-State: AOJu0Yzou/aSYwafTCF1176cOy9ANBJx+jlGbg+6aPt0GvTjTxvXxTwX TNDXxrROXfZE00zRz7WbGQDJJX/6uJuV20Chj9RgL2cLzAXuccNQpCP0Lvog2sHp6U38Twdq9TG 0Du8zLTaKnro41BQCljVgTj3bWkQI86mlioUp X-Google-Smtp-Source: AGHT+IEqf9okWn67PocUy8Jocw+dhghNQyk3Kfdq2yIp+/9Gkk10jzuGIlDmiYcXIwua7o+f+NVqtl0RNtMVswl/hqQ= X-Received: by 2002:ac8:7e8b:0:b0:447:dd54:2cd4 with SMTP id d75a77b69052e-4519adec1a8mr3133101cf.22.1722808533991; Sun, 04 Aug 2024 14:55:33 -0700 (PDT) MIME-Version: 1.0 References: <20240730125346.1580150-1-usamaarif642@gmail.com> In-Reply-To: From: Yu Zhao Date: Sun, 4 Aug 2024 15:54:57 -0600 Message-ID: Subject: Re: [PATCH 0/6] mm: split underutilized THPs To: David Hildenbrand Cc: Usama Arif , akpm@linux-foundation.org, linux-mm@kvack.org, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, roman.gushchin@linux.dev, 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 52F4F14000D X-Stat-Signature: pxhwxoiexhk44e389ahiprb9opz9p6se X-Rspam-User: X-HE-Tag: 1722808535-272834 X-HE-Meta: U2FsdGVkX1/q5gABVksWXYFAIX4/+QobRs4D1hk+6JTiR8n2sG9QdxLfidHlJQ5bcB9ZX0zB2YPKqRAP8KF6mDtVXvse3syLDVtouvOR+EAiK1qxxmS/hOsSzcaX8+7JmFzUaSROW/ChEVwalLup9ciAC5sXjEVHx/TiPxS+MQzvckBQbNcK1+i/oFzzu0V8zsClG1F4A2YvUloPhIExTS5qRPOOJp2vtbY6e3jO3UmwElG41pke5bnCmuAC1vpiZHyWlB1X23esQfoTFVRMaZklPmP2YM/OoPmuZ6dtbfHvpAfATwgdofbIq23jdRygopv18l/7kmsS/bvaLW2wwgMHR/lnv1v7CxDiUuC0zApP3IoQoMYrw3TVG8YqGHDgqOqRc1DiIDr7SeO75CeIAOfYkh1Agst66GrLy9sDOylHIbJlkpoKbC5pt4q6eaXbWA/B67JR2dPQeOlkw3M1IsaZ2UsrbvUNjZ+4iXW/QTX8sJpGiqHG5WtfU8glbS1O8974/ANKh6cXsmyshMX+nqzMFEcJNlQuNL9jRlmdzX5frzqNCgDSsiSiBdlyzNzYhoF5dPEByVqiWJsg8+SuqG5MC6ZmCsxXUXA1WHevls9eUtj5o1i9NGbZrsfByEiNZwK9/vmFq4CgHXhzQnYUKVz4mE1RSXiHLb0RTTPuKbgdGhbbiIiY7lQhOBbbGGrZxtio6Y2kjaqVC2fP+TBFBT9XsBovKbU1eCKuwSIFovlb59TAghh/J3PSItKXMaOEwMz2tRzVNgBILWrOgA7VshqPoLUIcNvNW9+5cypDh3WJx/RLjJfhEiprYkkFUCZsvZY3ihDwkdGAWrilO/wO++2MBGCpH2lbZoulUKdMJwKCz9VCAdN2HO1mGLPM5D1L4uWNFNIq98m3dhZOH77Atp0BW6LYJmHfBCd1vOq8qKWQ7DINCv84fFrKftTBakLWVIm/doRm2yzO7Vsp/oE 7J38iAJ8 p6xgBv5Q8LAn+zLimBeW5dMjo2+YOMG+8MQnNyvKbpsQBfFZTVaakeAfy7VLB+BM/KDLszH9Ez84jHXak4N1kU8azYA5fwW0l8BetuFsOzoh8Q9864LOtBJ8Xj5roGtrZ7We7xoPGJDc9qlKi2/rht02TwsDP+NFN5VkFHN+zaYMobmeYcEv0BgTn8Vx7KLl2Mvjl5xqBbVi2sEh21fZjSX+7jmiug5zQ9zgduKYhWqxia2N6wItvSHa6Gz3lvxuLi/5/zxsVlpdPl7LOQ7+Ti9tDppBcc5VNq4zKqgrE1eP2ZDNbxI8jJVC2rPEhEcmYqPdYv45+AWBTtOmeSYAtK+SrkvwbSsCmrJD25I/jVDuBra1eVKTsaVkczHVu3klMT8xSq+h0H7FMqj0= 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 Thu, Aug 1, 2024 at 9:47=E2=80=AFAM David Hildenbrand = wrote: > > On 01.08.24 08:09, Yu Zhao wrote: > > 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 perf= ormance > >> (i.e. you dont know when the collapse will happen), while production > >> environments require predictable performance. If there is enough memor= y > >> available, its better for both performance and predictability to have > >> a THP from fault time, i.e. THP=3Dalways rather than wait for khugepag= ed > >> 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 o= f > >> memory when THP is always enabled. During runtime whenever a THP is be= ing > >> 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 underut= ilized, > >> 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 attem= pt > >> to split that THP. Then at remap time, the pages that were zero-filled= are > >> not remapped, hence saving memory. This method avoids the downside of > >> wasting memory in areas where THP is sparsely filled when THP is alway= s > >> enabled, while still providing the upside THPs like reduced TLB misses= without > >> having to use madvise. > >> > >> Meta production workloads that were CPU bound (>99% CPU utilzation) we= re > >> tested with THP shrinker. The results after 2 hours are as follows: > >> > >> | THP=3Dmadvise | THP=3Dalways | THP= =3Dalways > >> | | | + shrinke= r series > >> | | | + max_pte= s_none=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 5= 12 > >> (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_non= e > >> 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 kerne= l > >> 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/ > > > > Do you have any plans to upstream the shattering also during "ordinary" > deferred splitting? Yes, once we finish verifying it in our production.