From patchwork Fri Jun 28 13:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Yang X-Patchwork-Id: 13716110 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 9DF81C2BD09 for ; Fri, 28 Jun 2024 13:09:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E6726B0088; Fri, 28 Jun 2024 09:09:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06E116B0089; Fri, 28 Jun 2024 09:09:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E02A36B008A; Fri, 28 Jun 2024 09:09:13 -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 BAECD6B0088 for ; Fri, 28 Jun 2024 09:09:13 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5A0C416030F for ; Fri, 28 Jun 2024 13:09:13 +0000 (UTC) X-FDA: 82280328186.08.0855653 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf18.hostedemail.com (Postfix) with ESMTP id 4B2DE1C0017 for ; Fri, 28 Jun 2024 13:09:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WlOCFmyG; spf=pass (imf18.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ioworker0@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=1719580141; 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=pA8e/eG8oKstNM7/17OixM+41nIGNrDwvlLD106HjE4=; b=Jue67pebxzPuHDAqWVCz0vqw4PTbm0s5PoJQVZldTxVBozZ4EzWSGpg5ySY8A/XYUl1/7O 6qT3DFuLPk1k/csvgDlcovqOPWRE+Z6DHt8mlrEnwiNBN+RoMt0i+7Z15aeJBOHMZqZB17 9vYBvM8xBb7fH0rHiOuW2pznY3pXQx4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WlOCFmyG; spf=pass (imf18.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ioworker0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719580141; a=rsa-sha256; cv=none; b=5WxjWtCK/2nhdgM2WsoeEcKNc1Pe4BB0Raj6IAxsYUTGMdvHuioe6e3OyPv3TrEns6S0N2 fRvuZyU8vwgFtCyXjmU67ACWd3fBslY2V7LqPwrSjQ27dHpJ3shnxCYdkApv88E8eQP1Z8 yefxjqhJYEfAk7VJj/RgjazVXDD4Hes= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-701b0b0be38so481309b3a.0 for ; Fri, 28 Jun 2024 06:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719580150; x=1720184950; 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=pA8e/eG8oKstNM7/17OixM+41nIGNrDwvlLD106HjE4=; b=WlOCFmyGXjbTvYsaosxjmmxwTJt+z5SHe15QjXd5+MNolT9u1FZET53GvyHOV/seBu bhx9hp/2NlFbk/J4Dl+tYz9w7GqBIqoezgk78WBhPqEx+jrTVkXl/KV5ykKyLymp3cM2 YQgqOgXFUhjwgJudURv6aF1NoiZeAYCJ7U/K/QUgeaDCHza5TgDVlD5jPpZAivvgWdiO J1QZXjzF84PO5TMPLW8V00T9dCpjix9QjmnrXQ3wyv925IKZekm/BgprKS0fAVV8uVbe TIQjcZN+Tg8VfspQNOyhQ47rSPBXl1FYi7kyWIG9bPgQcRaN6NEf5j6OZglysvKRAoJU qiag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719580150; x=1720184950; 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=pA8e/eG8oKstNM7/17OixM+41nIGNrDwvlLD106HjE4=; b=iiXxDeH6rDyTMqc+uEXPXbQtJlUZcCeHh3IYJmoT5h4yXmivrkd8a4zB+V9hLjEq9r xgZhSsmoLc/rcHZz74cY5UEq7G3TNqsxdZq3xKDlhpcupfIttE+IXQId5vce90tHRCo6 YqKkJJX5PPqH5UxaVcLm8M6q0A8AjumELKApnEyNdHNb+NGV37qqAa+ak4Lhw5ktuTi9 jk0jSW1OMjxw4d4L0ZhHtJ9UOJhPCD2MgtdRWzYYJYyt/UNz3sg5KomL2g/xJlb4/pWk h9DW0Jr6c6APD2PnxRnnUvZW0phZH91ecVa4pLBMG7w8ImFj8INkI23GiUl+RlbDtIFa ayZA== X-Forwarded-Encrypted: i=1; AJvYcCVFC2QmexbY4mNlEYEzigr+NPzqvHygadJOh2Oov6L9jdNgAWPB7ScKFqND0vWERSxmvtDfWj19n60Efx8OL67km6A= X-Gm-Message-State: AOJu0Yz3qUYMZn1rQEDBDLnT9MWDLmH1iZdwBQ0N9WuKd10i1FV/ww0Y wTZbqI9m29fMqwxqFAkCbFL310BXnCwcTYblOwKmAu+OFjixMYNI X-Google-Smtp-Source: AGHT+IFjbkgnF3EAdZd/5nvVUSzeFKuPrDEySNvAscHEob4ZAfU8Zv04k82jTF9h3HEfGazGu1kgAQ== X-Received: by 2002:a05:6a21:998b:b0:1be:c58a:7433 with SMTP id adf61e73a8af0-1bec58a775emr9386756637.59.1719580149845; Fri, 28 Jun 2024 06:09:09 -0700 (PDT) Received: from EBJ9932692.tcent.cn ([124.156.216.125]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7080498946bsm1526102b3a.200.2024.06.28.06.09.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 06:09:09 -0700 (PDT) From: Lance Yang To: akpm@linux-foundation.org Cc: dj456119@gmail.com, 21cnbao@gmail.com, ryan.roberts@arm.com, david@redhat.com, shy828301@gmail.com, ziy@nvidia.com, libang.li@antgroup.com, baolin.wang@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Lance Yang , Mingzhe Yang Subject: [PATCH v2 1/2] mm: add per-order mTHP split counters Date: Fri, 28 Jun 2024 21:07:49 +0800 Message-ID: <20240628130750.73097-2-ioworker0@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240628130750.73097-1-ioworker0@gmail.com> References: <20240628130750.73097-1-ioworker0@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 4B2DE1C0017 X-Stat-Signature: onaqj7t9uanpsup69wsiebb73j1um5x9 X-Rspam-User: X-HE-Tag: 1719580151-8490 X-HE-Meta: U2FsdGVkX1/xF5kxymu0/ZCMxJLjA3r3hcv7MSWX01kDoDk0wlYnkxM7Za6xkQC/P20QZmVpI7H99sNAAq8ZxJ1Bg+VgcbH2WPRg3iyEyi2N16KP7zLuGIlqwIe1SCQ79Ay51zLjzrtpwYg/SY/vNi+gcSnwVAmG+ax9OAUrFrzwB5nTLO1g1K81vOklygqB4+9lowzx+NA3R0iVCQD+6s4tLRSdHp9vjgtu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dU/LHAZ68vbpjgjmh2RWYMe3t0rN/Co54sJO0REjRmbFKTN2zw6JE3WxqwgiThQ== 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: Currently, the split counters in THP statistics no longer include PTE-mapped mTHP. Therefore, we propose introducing per-order mTHP split counters to monitor the frequency of mTHP splits. This will help developers better analyze and optimize system performance. /sys/kernel/mm/transparent_hugepage/hugepages-/stats split split_failed split_deferred Signed-off-by: Mingzhe Yang Signed-off-by: Lance Yang Acked-by: Barry Song Reviewed-by: Baolin Wang Reviewed-by: Ryan Roberts --- include/linux/huge_mm.h | 3 +++ mm/huge_memory.c | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 212cca384d7e..cee3c5da8f0e 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -284,6 +284,9 @@ enum mthp_stat_item { MTHP_STAT_FILE_ALLOC, MTHP_STAT_FILE_FALLBACK, MTHP_STAT_FILE_FALLBACK_CHARGE, + MTHP_STAT_SPLIT, + MTHP_STAT_SPLIT_FAILED, + MTHP_STAT_SPLIT_DEFERRED, __MTHP_STAT_COUNT }; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c7ce28f6b7f3..a633206375af 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -559,6 +559,9 @@ DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK); DEFINE_MTHP_STAT_ATTR(file_alloc, MTHP_STAT_FILE_ALLOC); DEFINE_MTHP_STAT_ATTR(file_fallback, MTHP_STAT_FILE_FALLBACK); DEFINE_MTHP_STAT_ATTR(file_fallback_charge, MTHP_STAT_FILE_FALLBACK_CHARGE); +DEFINE_MTHP_STAT_ATTR(split, MTHP_STAT_SPLIT); +DEFINE_MTHP_STAT_ATTR(split_failed, MTHP_STAT_SPLIT_FAILED); +DEFINE_MTHP_STAT_ATTR(split_deferred, MTHP_STAT_SPLIT_DEFERRED); static struct attribute *stats_attrs[] = { &anon_fault_alloc_attr.attr, @@ -569,6 +572,9 @@ static struct attribute *stats_attrs[] = { &file_alloc_attr.attr, &file_fallback_attr.attr, &file_fallback_charge_attr.attr, + &split_attr.attr, + &split_failed_attr.attr, + &split_deferred_attr.attr, NULL, }; @@ -3068,7 +3074,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, XA_STATE_ORDER(xas, &folio->mapping->i_pages, folio->index, new_order); struct anon_vma *anon_vma = NULL; struct address_space *mapping = NULL; - bool is_thp = folio_test_pmd_mappable(folio); + int order = folio_order(folio); int extra_pins, ret; pgoff_t end; bool is_hzp; @@ -3076,7 +3082,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); - if (new_order >= folio_order(folio)) + if (new_order >= order) return -EINVAL; if (folio_test_anon(folio)) { @@ -3253,8 +3259,9 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, i_mmap_unlock_read(mapping); out: xas_destroy(&xas); - if (is_thp) + if (order >= HPAGE_PMD_ORDER) count_vm_event(!ret ? THP_SPLIT_PAGE : THP_SPLIT_PAGE_FAILED); + count_mthp_stat(order, !ret ? MTHP_STAT_SPLIT : MTHP_STAT_SPLIT_FAILED); return ret; } @@ -3278,13 +3285,14 @@ void deferred_split_folio(struct folio *folio) #ifdef CONFIG_MEMCG struct mem_cgroup *memcg = folio_memcg(folio); #endif + int order = folio_order(folio); unsigned long flags; /* * Order 1 folios have no space for a deferred list, but we also * won't waste much memory by not adding them to the deferred list. */ - if (folio_order(folio) <= 1) + if (order <= 1) return; /* @@ -3305,8 +3313,9 @@ void deferred_split_folio(struct folio *folio) spin_lock_irqsave(&ds_queue->split_queue_lock, flags); if (list_empty(&folio->_deferred_list)) { - if (folio_test_pmd_mappable(folio)) + if (order >= HPAGE_PMD_ORDER) count_vm_event(THP_DEFERRED_SPLIT_PAGE); + count_mthp_stat(order, MTHP_STAT_SPLIT_DEFERRED); list_add_tail(&folio->_deferred_list, &ds_queue->split_queue); ds_queue->split_queue_len++; #ifdef CONFIG_MEMCG