Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1829045lqo; Sun, 12 May 2024 22:10:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7lo015zzLyY5IWx2jUGl68eDi1AIBVBjYB4EA3eGNDd8UQ7jS9a6lSEYKMLhydfaTjv+os4UOnfZZtJ764+ujXQ4G9OW0UQxTCP2FTQ== X-Google-Smtp-Source: AGHT+IEQW8we786FoKjyjriozA8ZDri2ijDcIOzpycBez23K1j2setYp59YFeqvy079WnQEpaRLr X-Received: by 2002:a50:8a99:0:b0:572:9c4c:250b with SMTP id 4fb4d7f45d1cf-5734d5db9acmr8930466a12.18.1715577020138; Sun, 12 May 2024 22:10:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715577020; cv=pass; d=google.com; s=arc-20160816; b=EQcwfXDZL36i4hY7tpkPtg8gzcVXdM/c8QW67D+bgqwnXpfQAaCZ3bn4TBjdPVC/O1 4vkTduiLtp2RNzhzkXAF/zmnhFEfTAZQjLKcaV552RQbJKE+L4luTw0mO02MX6clNajz FjtaSHtmm51V2CHY7Ma37eA8TQBd3UWVEr3P7gI2wIuGM86VAPZwu3SF41+sQMAvD401 J7wQo7YWxTetUUpYt7B+EttR2Qex8WhlKklwmE8propaQijBlUYAY8rhtsuz8Kbj4b8o TWsGy3JbqG2B4KoVqw2uh5vAnW4BmbZ0b0yAkVz1UGJG+nz2VzMLllrHIiAKgo0r9iz0 P5kw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+jNNX3W26VDDLfggMRp8CMmTsrteBwo6mbmSEbiS2X4=; fh=QbwS3auWn4deePzqcQEgPh0o+FZG4BOPGyVFHXP9ySY=; b=ts4QEniHCaFF3Qal3a7d85Xk9OQxKtwAoF304ww97KKm/t1cOQOKwA8tYi2WWedtlz aaXBAia2KBkDm+xea9fIdOQfEz5td7fbiBCGs8c9VxjosZqKfbEfyg4J1yqWmafs7bJy f+w9szlgUT53BA52Sb5mRyJTJhs8DsQOZKLF+cMH1YBjg953UAYRKe8efoFJGIUexPqj G7V5Gwg+a268Lt75Ma94O9qyE3V67/7oswrtRjntQL+vZ6lqygBLXq/aQQoYOGcK2BRZ Zoc9d9y7M9ArrsNGDvbVo8x73guLb/7y/7EDTAyict9E/Jan3oE4wKOXzlPlqR/NOmv8 dPWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=xApeZUPZ; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-177158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beac406si4515535a12.108.2024.05.12.22.10.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 22:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=xApeZUPZ; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-177158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DA86C1F210BE for ; Mon, 13 May 2024 05:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C835146016; Mon, 13 May 2024 05:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="xApeZUPZ" Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB13C14600B for ; Mon, 13 May 2024 05:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715576935; cv=none; b=cshddrtzVYfhQ/IERErSKFIH6izh4e84f83rabxFYtdcIEpICWoCGLKKlHYuvuVl/iEasaCEKH3CRFS3CM9y/KQpgx0ogTtfUX5FLPtiNps4NyGq4J63QQb2Nw0it0vwPaOF2K0ysspTxOK4eHFDZy8QvXdtmzMZlcM5dbYzIH0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715576935; c=relaxed/simple; bh=a8YAPu6NbKPuP9q8NY35W/OW7WuX38VQbh3a6oAHFTo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A5sxP73HGtdsnvsE27SOjSuG/i8Pt9hlYIxlYi3OCOgx460Ebx7ECWNP/eapOkNGKKQobGq0h7oBQK6XtSyg/M2zpHml/xSR7ANB6orAju3nlNPa/c7l48Z+9fQ6IBwr55UvRyccE1Ima1m1EXQrivztQvHEPoG1dDrKzchlcgI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=xApeZUPZ; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715576926; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=+jNNX3W26VDDLfggMRp8CMmTsrteBwo6mbmSEbiS2X4=; b=xApeZUPZeXrum9Ps6AU5QTTCUm/MxXv1SuULma+sdMTEeF41YOgwImlYZFYcszVZWkjk4+l4njfUAG3xT6l+Z7H0LueS8hGT2/sWayLEeliP9YHHp0GXa5cT64LFtAHgHoyC+D+yJCazxnErlUm6jnvaTRteIRSGXvErDkuwrXo= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R331e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033022160150;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0W6HN0Qb_1715576922; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6HN0Qb_1715576922) by smtp.aliyun-inc.com; Mon, 13 May 2024 13:08:43 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] mm: shmem: add mTHP counters for anonymous shmem Date: Mon, 13 May 2024 13:08:17 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add mTHP counters for anonymous shmem. Signed-off-by: Baolin Wang --- include/linux/huge_mm.h | 3 +++ mm/huge_memory.c | 6 ++++++ mm/shmem.c | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index b5339210268d..e162498fef82 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -281,6 +281,9 @@ enum mthp_stat_item { MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, MTHP_STAT_ANON_SWPOUT, MTHP_STAT_ANON_SWPOUT_FALLBACK, + MTHP_STAT_FILE_ALLOC, + MTHP_STAT_FILE_FALLBACK, + MTHP_STAT_FILE_FALLBACK_CHARGE, __MTHP_STAT_COUNT }; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d3080a8843f2..fcda6ae604f6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -555,6 +555,9 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE); DEFINE_MTHP_STAT_ATTR(anon_swpout, MTHP_STAT_ANON_SWPOUT); DEFINE_MTHP_STAT_ATTR(anon_swpout_fallback, MTHP_STAT_ANON_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); static struct attribute *stats_attrs[] = { &anon_fault_alloc_attr.attr, @@ -562,6 +565,9 @@ static struct attribute *stats_attrs[] = { &anon_fault_fallback_charge_attr.attr, &anon_swpout_attr.attr, &anon_swpout_fallback_attr.attr, + &file_alloc_attr.attr, + &file_fallback_attr.attr, + &file_fallback_charge_attr.attr, NULL, }; diff --git a/mm/shmem.c b/mm/shmem.c index 8b020ff09c72..fd2cb2e73a21 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1786,6 +1786,9 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, if (pages == HPAGE_PMD_NR) count_vm_event(THP_FILE_FALLBACK); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(order, MTHP_STAT_FILE_FALLBACK); +#endif order = next_order(&suitable_orders, order); } } else { @@ -1805,9 +1808,15 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, if (xa_find(&mapping->i_pages, &index, index + pages - 1, XA_PRESENT)) { error = -EEXIST; - } else if (pages == HPAGE_PMD_NR) { - count_vm_event(THP_FILE_FALLBACK); - count_vm_event(THP_FILE_FALLBACK_CHARGE); + } else if (pages > 1) { + if (pages == HPAGE_PMD_NR) { + count_vm_event(THP_FILE_FALLBACK); + count_vm_event(THP_FILE_FALLBACK_CHARGE); + } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK); + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK_CHARGE); +#endif } goto unlock; } @@ -2178,6 +2187,9 @@ static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index, if (!IS_ERR(folio)) { if (folio_test_pmd_mappable(folio)) count_vm_event(THP_FILE_ALLOC); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_ALLOC); +#endif goto alloced; } if (PTR_ERR(folio) == -EEXIST) -- 2.39.3