From patchwork Mon Aug 19 02:30:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13767732 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 3BAEDC52D7C for ; Mon, 19 Aug 2024 02:32:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D63D6B008A; Sun, 18 Aug 2024 22:32:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75E7B6B0093; Sun, 18 Aug 2024 22:32:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B2276B0095; Sun, 18 Aug 2024 22:32:02 -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 35F1E6B008A for ; Sun, 18 Aug 2024 22:32:02 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AA3A51A0BAD for ; Mon, 19 Aug 2024 02:32:01 +0000 (UTC) X-FDA: 82467420042.22.41D6C4B Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf25.hostedemail.com (Postfix) with ESMTP id D9F44A000F for ; Mon, 19 Aug 2024 02:31:59 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="h0K6mD1/"; spf=pass (imf25.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724034659; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eO6lPMqYWNsw0u0kOe6TeGUxnE5KvmwuKqe4o/pamZ4=; b=rZxPagsgSBKx5GR0oI0yUtB+vduh/BRxnbKqCwvtrApdtHqvaXn2OrDonVEQ5xVNZ5i6bq BOgvSZJWP+3JtSp0t2e5fz7/QZ8gxem8R+B3E69qmjCrYwASRW+f2EyuKH1Lh56w0Cbqds sjUINwtuDxfgSFDmJabxlRO3cVDKFqc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="h0K6mD1/"; spf=pass (imf25.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.219.41 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724034659; a=rsa-sha256; cv=none; b=awvLR8LsFDvim9PB0YuOoPfd5HXCuKqJA7QdvOKRE/sJwPJv2jiu9u44tnsa00V+z3nDqa M18dd7NoxeghjOl26NlFr38fomafmMz9gmtzvVA5sCyS5JwPsN9xrLfBNVoJSnwQ8mgrm9 TpcPkq/czMaou4HeVPLVP6Ao4Ui6ErA= Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6bf9ddfc2dcso2011496d6.1 for ; Sun, 18 Aug 2024 19:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724034719; x=1724639519; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eO6lPMqYWNsw0u0kOe6TeGUxnE5KvmwuKqe4o/pamZ4=; b=h0K6mD1/SlKVOCp+eEpSCnSF1y7I1lGtXhLb76jsh+LFIqgwZDEjbFVgTl7eVdmtMn u8viJSpHDrSNOLCnOKGrR3qTQvumVE18ZFS0ZPRh6YpWxC/oxRG5H0KtBZZctQyWolnt r3YWTVU4tztRXuzvFvt3meJFHGvwnU+fFhUqbMxl6MKbNL8duvGDEKO+xNNsnGJSQsLd NPfqz5xzeSIuL9HM9jeVIbNYBX7T45k8FaAKe6VcGI34gt6LGa1g36bAUzVGbqYeq1t/ gZQSDkvD2DmFsO44UQKS+soyZBYbrQDnyiy5cKLORW3cu9pJog9I9j0coYod3kAItc79 lAAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724034719; x=1724639519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eO6lPMqYWNsw0u0kOe6TeGUxnE5KvmwuKqe4o/pamZ4=; b=KpJZebuJBnssZtb/aSh45f8vvNG0QgcPBZwYa5oQS/mns2LyXi6JO9OvKSPNR0Fh5B adzJqV3umUTp27+aknIuQ0VaZIwcsXGfJ9PR3Fab7NJJuZwIYdDadJ20XxiyDYlTxjr2 w4+sVxyr5xo3vThN+fWXj8Z4xUrQOk/49tGqugpPYhTYpVS1m7bAi26pnRx+8GbYydIs kke9rf7xJI5DursetrM8LycMfXgW6bAiQhCPhGBv9LPxKzU201CV3fX2R1nOJgZ5nSzz ePTha20/CH/8F2Y+dex0r0Il7SF1sYJJDEylwnz9FHLUGB5fVBigQmA89tn0QkXPAIGx IV9Q== X-Forwarded-Encrypted: i=1; AJvYcCUmDNaAkuF1psPtS8wbW71SJukXC8rC8WON16RpUElHe3GXGBmljBkT6t4VpAhbFf0naU7HACYKQH5sog7O0nYrMoc= X-Gm-Message-State: AOJu0YwxNn6Q4iKqXXxP793QhsikCZgBOnlPVkU3HB0O98UgkRcbAzUj 0WXY6w3P0a1HYEszuahXz+/ryq99NYJRVJ5ypCXvyU+VK+c9Egw9 X-Google-Smtp-Source: AGHT+IGNG9vxDFxLwp6LH6gHm98AbumciP+UKQShkj+bs5fdr5dQCOqFsqwOOMWP9Hvs4t2YHLHiLg== X-Received: by 2002:a05:6214:588e:b0:6bf:894e:7964 with SMTP id 6a1803df08f44-6bf894e7aabmr54977146d6.57.1724034718766; Sun, 18 Aug 2024 19:31:58 -0700 (PDT) Received: from localhost (fwdproxy-ash-012.fbsv.net. [2a03:2880:20ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bf763cb74fsm36274866d6.112.2024.08.18.19.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 19:31:58 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, roman.gushchin@linux.dev, yuzhao@google.com, david@redhat.com, baohua@kernel.org, ryan.roberts@arm.com, rppt@kernel.org, willy@infradead.org, cerasuolodomenico@gmail.com, ryncsn@gmail.com, corbet@lwn.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH v4 6/6] mm: add sysfs entry to disable splitting underused THPs Date: Mon, 19 Aug 2024 03:30:59 +0100 Message-ID: <20240819023145.2415299-7-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240819023145.2415299-1-usamaarif642@gmail.com> References: <20240819023145.2415299-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Stat-Signature: g7f3y1zmymna9bj9diqq6ztsgbw3f56o X-Rspam-User: X-Rspamd-Queue-Id: D9F44A000F X-Rspamd-Server: rspam02 X-HE-Tag: 1724034719-839510 X-HE-Meta: U2FsdGVkX19MP523Ri6KTge+yLmamjOQcUyZI2pkTbmkHuP2VoDNTWVAQF0sDzXl0FQ4Ooiv+k4XrcAka40dmCp03X9Cw/5kEjp/f9TLiNeImEu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EK/kz9Mbvj7hsp8h/yO8mD8//f16OQevcB2pH6zdyi+ycuVo3h/5FOAUCCmCJZxuh76P1V4DZBeqV/kIJAdTya2HTovMLNcyIfIqR2kZlDeDunhG+Kj9a292CEIbMx4xu0OsJzMtUXIKC3bmjG6A== 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: If disabled, THPs faulted in or collapsed will not be added to _deferred_list, and therefore won't be considered for splitting under memory pressure if underused. Signed-off-by: Usama Arif --- Documentation/admin-guide/mm/transhuge.rst | 10 +++++++++ mm/huge_memory.c | 26 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 40741b892aff..02ae7bc9efbd 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -202,6 +202,16 @@ PMD-mappable transparent hugepage:: cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size +All THPs at fault and collapse time will be added to _deferred_list, +and will therefore be split under memory presure if they are considered +"underused". A THP is underused if the number of zero-filled pages in +the THP is above max_ptes_none (see below). It is possible to disable +this behaviour by writing 0 to shrink_underused, and enable it by writing +1 to it:: + + echo 0 > /sys/kernel/mm/transparent_hugepage/shrink_underused + echo 1 > /sys/kernel/mm/transparent_hugepage/shrink_underused + khugepaged will be automatically started when PMD-sized THP is enabled (either of the per-size anon control or the top-level control are set to "always" or "madvise"), and it'll be automatically shutdown when diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f5363cf900f9..5d67d3b3c1b2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -74,6 +74,7 @@ static unsigned long deferred_split_count(struct shrinker *shrink, struct shrink_control *sc); static unsigned long deferred_split_scan(struct shrinker *shrink, struct shrink_control *sc); +static bool split_underused_thp = true; static atomic_t huge_zero_refcount; struct folio *huge_zero_folio __read_mostly; @@ -439,6 +440,27 @@ static ssize_t hpage_pmd_size_show(struct kobject *kobj, static struct kobj_attribute hpage_pmd_size_attr = __ATTR_RO(hpage_pmd_size); +static ssize_t split_underused_thp_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", split_underused_thp); +} + +static ssize_t split_underused_thp_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err = kstrtobool(buf, &split_underused_thp); + + if (err < 0) + return err; + + return count; +} + +static struct kobj_attribute split_underused_thp_attr = __ATTR( + shrink_underused, 0644, split_underused_thp_show, split_underused_thp_store); + static struct attribute *hugepage_attr[] = { &enabled_attr.attr, &defrag_attr.attr, @@ -447,6 +469,7 @@ static struct attribute *hugepage_attr[] = { #ifdef CONFIG_SHMEM &shmem_enabled_attr.attr, #endif + &split_underused_thp_attr.attr, NULL, }; @@ -3477,6 +3500,9 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped) if (folio_order(folio) <= 1) return; + if (!partially_mapped && !split_underused_thp) + return; + /* * The try_to_unmap() in page reclaim path might reach here too, * this may cause a race condition to corrupt deferred split queue.