From patchwork Tue Aug 13 12:02:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13761890 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 7D5CBC52D7C for ; Tue, 13 Aug 2024 12:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAFA46B00A5; Tue, 13 Aug 2024 08:03:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E38916B00A6; Tue, 13 Aug 2024 08:03:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3C7E6B00A7; Tue, 13 Aug 2024 08:03:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A04F36B00A5 for ; Tue, 13 Aug 2024 08:03:54 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 55BFC14080B for ; Tue, 13 Aug 2024 12:03:54 +0000 (UTC) X-FDA: 82447088388.05.8769B00 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by imf12.hostedemail.com (Postfix) with ESMTP id B766C4000F for ; Tue, 13 Aug 2024 12:03:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="b1/Jcwr2"; spf=pass (imf12.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=1723550619; 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=fpDDmqOnJijcRyZ/zRVr0dfh/EUV8mM0nwD7hiV/Er4=; b=A5McyKCGGr458qX1AyUV8qHNuLjmQNZR43h2UalFHBrLJGUcnajK1h+lXOfiA4plEZ5May attq2C39bX2A4d5vjyeGh5i8H3DUsi7kru3WrKY0N55Kf0jN/b+beJyelS422FsFj0Y8xn ZqJ7AuUMOgmUUxr2eS1+nkeJ/j4CZoE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="b1/Jcwr2"; spf=pass (imf12.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=1723550620; a=rsa-sha256; cv=none; b=Sn5IWPDlLjVbabFckDvvJ3D5h+KpAah4q7eN4mhtQushbb+XSbkadMSvnivETuCGKykHgH pi3xiA2kUtnhaUZ4z4oPJc/8WM3lnMPVtgBPhxC3wzq2msIEcy+LERsaEgM2w2asGpsnxG DjqhjYqQWvnGa4nQVPUH315qiCzx7HE= Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6bbc1cee9b7so32087476d6.3 for ; Tue, 13 Aug 2024 05:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723550630; x=1724155430; 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=fpDDmqOnJijcRyZ/zRVr0dfh/EUV8mM0nwD7hiV/Er4=; b=b1/Jcwr2P0cWdUlmVaFUCQbtjRmwuveBlMdTHFe4xFKVLdBetufTmdZYD4Udx5lXH/ 7q7yZHVB6usGwCSDl3iImGuRV4S68k3x6K63GNOqHxbejIXIKgkWZNUNGX5rWLpI37Oe SBE53pgOVA54uryL+hr3qrFVS1Ac64V+jBwDQfwkkPwLzZitKaoZTZqXtUg795+HjPmv BqnordLZ6HrTZ5JO7bwyEF/hiBXioliKWsJkxNiUsQk2xITHO1xqCijfY6E9m1WXFJFs pBbJopVAXVVWuEGzV3qK0zNzjvl1QXYMWDScw0nOT0eTWKiYKYAbib1lCti+NRIQaHJw uHjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723550630; x=1724155430; 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=fpDDmqOnJijcRyZ/zRVr0dfh/EUV8mM0nwD7hiV/Er4=; b=VPs4oQjnqiTI0UakBXmBjswi9jOBwPy9Npih2rd9K7M2en3V2ksuGJVAhSh/crXqfW HlxWMYbspAbON/A70TnbRXIV6hyb3WxYFlfGdUrki1ahiurIoEou72JA+U0jcH7TGJff oG4+1Fci+Q8/PQnuwchCx2EV7oESNYgcFK59IJnuJ6X14oM+23saxs35YrxL5A94yw05 hmWcca0l8vG5Xfztres0oY+NWKhvtOAdw2WwtLzuXk329qJNfNK8GFLimyw/5u+44erV jBcGzJfu0UIPJGrhfyjwV13fgk79V9xu8aD99e/AldJN9IzmEnoD8LIfeBYxqHGgInKG rq9Q== X-Forwarded-Encrypted: i=1; AJvYcCWnylAQl4R6v0KQGQwOUDQXFIevluh8nV7bLFHBPDpi2RbVbeK7PebGYDfygffv2Xqnf7yI9kZgX/81x5eu9mbeyPk= X-Gm-Message-State: AOJu0YxAF9dYVKsN379jglOaP5ye702GK5gcqF/Fi7E8t//1eWhJwpS6 OUiEFjI5Kyx3k7sKNcUdCwQXf9TnxnoUNBVKKvYGauLbTvtzBxiLKxp5fCRr X-Google-Smtp-Source: AGHT+IG/p4KHdjtbRHl8jrRDtZpiTzA00oY1agex2KO6TAfMpoEbk5fNk2V++Y8FeIZ5s4O/KzF07g== X-Received: by 2002:a05:6214:5f0b:b0:6b7:980b:e0ac with SMTP id 6a1803df08f44-6bf4f7e2315mr29329476d6.32.1723550630417; Tue, 13 Aug 2024 05:03:50 -0700 (PDT) Received: from localhost (fwdproxy-ash-011.fbsv.net. [2a03:2880:20ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bd82c81cd0sm33464656d6.53.2024.08.13.05.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 05:03:50 -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, corbet@lwn.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH v3 6/6] mm: add sysfs entry to disable splitting underutilized THPs Date: Tue, 13 Aug 2024 13:02:49 +0100 Message-ID: <20240813120328.1275952-7-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240813120328.1275952-1-usamaarif642@gmail.com> References: <20240813120328.1275952-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: r8njj9ypqrpza7xw35dr9g7nwjxepjnd X-Rspamd-Queue-Id: B766C4000F X-Rspamd-Server: rspam11 X-HE-Tag: 1723550631-588671 X-HE-Meta: U2FsdGVkX1/RzsgS6idMtji/5yoPf85sChspLzhZQZND78Tww9EFuDwAOxV+It58hdPJb+iwglK1h66R2BRTAa/xNzCtgUaX3QA+SoFATN7J77uFqtW6PUD7SsxWp4bo6L8WrSLdrTtD5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0ki5PIwLSO4EOsP1B9pOWd1UxRhC1H9/YciYpf8AMO/oOihJBhh2xc7uts6sqaBZ4dMLsnNhL4iVmI/JaG5VvjKTV1s+zOTlJXKjm77b1hT7zPj/ePi4HsQ== 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 underutilized. Signed-off-by: Usama Arif --- mm/huge_memory.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6b32b2d4ab1e..b4d72479330d 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_underutilized_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_underutilized_thp_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", split_underutilized_thp); +} + +static ssize_t split_underutilized_thp_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err = kstrtobool(buf, &split_underutilized_thp); + + if (err < 0) + return err; + + return count; +} + +static struct kobj_attribute split_underutilized_thp_attr = __ATTR( + thp_low_util_shrinker, 0644, split_underutilized_thp_show, split_underutilized_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_underutilized_thp_attr.attr, NULL, }; @@ -3475,6 +3498,9 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped) if (folio_order(folio) <= 1) return; + if (!partially_mapped && !split_underutilized_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.