From patchwork Fri Aug 30 10:03:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13784872 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 12C21CA0EFB for ; Fri, 30 Aug 2024 10:04:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE45F6B00FC; Fri, 30 Aug 2024 06:04:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6A306B00FE; Fri, 30 Aug 2024 06:04:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91FFF6B00FD; Fri, 30 Aug 2024 06:04:54 -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 71C4F6B00FB for ; Fri, 30 Aug 2024 06:04:54 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E9EB81A1751 for ; Fri, 30 Aug 2024 10:04:53 +0000 (UTC) X-FDA: 82508478066.12.39776D7 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) by imf16.hostedemail.com (Postfix) with ESMTP id 10F34180009 for ; Fri, 30 Aug 2024 10:04:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F0AzkFmf; spf=pass (imf16.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.210.45 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=1725012220; 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=y9HM33kRGSHCEaJuDM+XKG3QBl4KNlRa8+XSdjB42Js=; b=zRf7T8Q9TjTP20wC5XwhbxzJkNYgDNG0rW30ebkd80fA6mluhusic/CLpnPgG4CZ1TjPcd u6mbgAFspxwYBZXmGV/x7cxuE4ffxzKQ2ROLSZOJi83tG9+ckfAeuV7llCCcmta+gLXBbB DH1lDwq/qTWsUnoUmA8IRJclY6txd8Q= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=F0AzkFmf; spf=pass (imf16.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.210.45 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=1725012220; a=rsa-sha256; cv=none; b=C/QBoZ4gHbChxVW1m9l4XmRzWp/UdwfUYYjldBHc3mp21fsoXWB1yTxjFqw256f/lFzdYf 9wcyqasFtR2b/0jcLuhLYCJDYsUn8rflKfjWFCD1e8gxsFHpyHOCxY1YEMWon6ZGIp7cxs HeQS/ysX8CtfNQwE9GqWkHGLRYsta2c= Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-70f5a9bf18bso774422a34.2 for ; Fri, 30 Aug 2024 03:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725012291; x=1725617091; 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=y9HM33kRGSHCEaJuDM+XKG3QBl4KNlRa8+XSdjB42Js=; b=F0AzkFmfkWA0LPW7ySley6EgXXeLIjI83IVljU0Yfw2AQtdAd5klM3dYkBKKufwW36 ysDONEO7yeQLi3hLbdMK7IaZVtSUlM7BIFWfB/Gp6+sKxiDQzsAP+nPiOifrObTvsTxx mF2U5Nt3SCB1FiOxE/rlfha6law8b2y3/ODgaP64xWBQIBS3YHIGaVHo+fq+06bYqb8t aIdpsnGCLgy6nEuR6Ojp0cTRWQ+HAJaQfrDTJpbHKrQ4FvXZbSVPbujhea8JHduzIsxM iVrWM+tI6XjUV5eLaPeMCxXjen11iyRVLMptslI7+1mDKDb7ibKPShqxGjvk76j4dcVI Vv+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725012291; x=1725617091; 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=y9HM33kRGSHCEaJuDM+XKG3QBl4KNlRa8+XSdjB42Js=; b=oAio2GpbsOM/e+irppULl6UNfLfzh2OgG2ChqrqxFR1fl5RtrNyhehQVYBNUoP58n6 XaJSVXKJf3n55Z8P1mcQ/YC56m9pFc0zOG3iTN06zyb/E/NuOvquf8afogiRvkGmXw4V 4yU4/qw0xJYoStk3mTNfM3xm+QR7sx9vfwvfLH5e1DwGFV63/CP/X4vlTWqc+M2CaZ6v N96/ah1FAGw0eA0hHkvYDxKSCrLb2DMN+ETmMsY5pyw7UfS/S9MCd+j+G7mr9+0d54ET Y9H0xeJZpXR8hIkY1Do51QwBsTNma26RktQtR/eJI9lczdvERQz12U6XXqAwUDHT/D// X/9Q== X-Forwarded-Encrypted: i=1; AJvYcCVOWaZIdeoa+re0++SSCBzmlrtKEKmw1mWJ19GTB7tlRZMNedZg8rBjZf4MWFicX1IBT/FsinjVLQ==@kvack.org X-Gm-Message-State: AOJu0YzAKMUeflDyraWav4ifjYVuUhsXYCeAtHGk9yL+wH6bK1ksecP7 LHUmHvtBSHTEhWc9OKoEpJuRBhpIllus0BtUQJNxvoxl95A46Eod X-Google-Smtp-Source: AGHT+IFnFxgDYehxBOjERbSY3E6IQRb/Eo5/olia1KlgsAQYx6fH7Gfn02t5h6FRR0dUftMkedAUyg== X-Received: by 2002:a05:6830:2682:b0:704:45b7:8ffc with SMTP id 46e09a7af769-70f5c49e963mr5658027a34.32.1725012290746; Fri, 30 Aug 2024 03:04:50 -0700 (PDT) Received: from localhost (fwdproxy-ash-013.fbsv.net. [2a03:2880:20ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c340c0020esm13219306d6.50.2024.08.30.03.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 03:04:49 -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, npache@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 v5 6/6] mm: add sysfs entry to disable splitting underused THPs Date: Fri, 30 Aug 2024 11:03:40 +0100 Message-ID: <20240830100438.3623486-7-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240830100438.3623486-1-usamaarif642@gmail.com> References: <20240830100438.3623486-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Stat-Signature: z4ywe6bw7hxfweiqkrea6uyntzttio7r X-Rspam-User: X-Rspamd-Queue-Id: 10F34180009 X-Rspamd-Server: rspam02 X-HE-Tag: 1725012291-834385 X-HE-Meta: U2FsdGVkX1+owRZAoQWEWF7L+RIz6/xpC9ERpCU/uMmbfG02U0uOX6HryY4APALV9xMnLO/3FBDYOq3UEPf4QpZNU4kZ7p6+qrf9N16N/VBPy+OyDqpXYice9Iq70Y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gJmtvfbIMtSmGP28UN3fuhH/hJ9c6klMro5nlxtA7lT5/UdzBT158PK4YxNd/N7mQwHul6uvAyhUZSEeQkGLyoWB13c0ApQLtsJvZjZB7X8FY+qo2GcAzjHgGRumqFiBkbM4CfRQb8NWWzf0acH66FqkBrqgeA45uk4lUPYI3DZf8 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 aca0cff852b8..cfdd16a52e39 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 a97aeffc55d6..0993dfe9ae94 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; @@ -440,6 +441,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, @@ -448,6 +470,7 @@ static struct attribute *hugepage_attr[] = { #ifdef CONFIG_SHMEM &shmem_enabled_attr.attr, #endif + &split_underused_thp_attr.attr, NULL, }; @@ -3601,6 +3624,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.