Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp241949lqp; Tue, 11 Jun 2024 03:11:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqBkMn/2gksCdbussEAkQe6GftLR6FKMs2q7doTzYHXUO1aZE1jvxHZ8dgUk5Qso88e8hMdco6eIsuu0rjRTXjBYe8am7IvVUaxZx0iA== X-Google-Smtp-Source: AGHT+IE/5uMzAYRKn44C0EhmvnN+rgq6ToyR/2O9HdakH1fV2b6rY0UKryxou9ZFvZn7BpFrrB1+ X-Received: by 2002:a05:6122:3663:b0:4eb:5fb9:166f with SMTP id 71dfb90a1353d-4eb5fb9182amr8074640e0c.7.1718100717502; Tue, 11 Jun 2024 03:11:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718100717; cv=pass; d=google.com; s=arc-20160816; b=xE8NBolnnpFkFDFkNZdvuqC5FAA5hUBR0C9NgJUoQr23BoxLzZLKi9xwwOxTJs2k95 83/UQ8E+deyo7nmBSQ2ujzPk215zzpsy13htk5ctMgiKnZvJaygKbLrdHcHr/i33KL/w sHZVwDoU8zNycgJyJ1uOWgH7Z4OqNSkaSBssGLMZBJwoFKikMPeoVX343amKbXqEbH3/ 3FBS6OdmBEQ441L1343fsPD6COEp2n/HGKHCNyVx+eJzm3AtbqLwTRMz3HKOGhB6aW82 Eo0mtL9XEdYAV+CA1oEFphF+dY8fZ97D14euZ1o/gS8Zg1l2rnpeRLQyOhHySsdq4/lp Pwug== 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=nLj8yUsK2lei34HSlxIopppsBC+abcyB+V/ZUwcOo4A=; fh=d9B6n7k7iFbk3BUsTidzz8lQOS2iyyRQbZ5BNlMEHw4=; b=KEf9tdLo51d/O6VqXzzeaxcz0Znhl2Mq7vDSD2ivbjN9N5SCDb29HJK5wPs/yH7oWK 7HTrzshOrylZjKjPOIzVNBGey4RwbatgVu5y+idbx7kAnEDiEWL+UfyUWCNO3GX3XtZ2 xLtPGPbf0FfoMVSFHv/AZXg8xk06PwggE/GtmOw2wuoX683tIJkDiNH/KRl+9Y7+bUpG /+uFdNqv33+LuYIABwBdxGkwsafBejDJ42VUI1V4+1LMnhPuSssG/r60bVjFuxWxBYil bQkER0yRgiG+R8+9VG18ySg/rie1lEH/kGBggB+TqiXdlsOPJKKMscOxTTD2rm7ou8k3 0dnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=d5opbIJS; 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-209615-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209615-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-795597ed37dsi789060985a.41.2024.06.11.03.11.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 03:11:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209615-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=d5opbIJS; 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-209615-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209615-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C14D1C2354E for ; Tue, 11 Jun 2024 10:11:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CD71E57E; Tue, 11 Jun 2024 10:11:28 +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="d5opbIJS" 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 65081178367 for ; Tue, 11 Jun 2024 10:11:24 +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=1718100687; cv=none; b=cMxbWKvsIwxAP8XBltf8G59hqL5ScpKnfV4LOD+IH55E/MDxyoIU0vgHWejY6TDrK2OiD6imICl5yK6G45hdhYq25AEojqxuNKzhIs2e55atSD5bTV5t0DWUVftIiy4z6NPhXIEACdiq0/Q2RRhB6PcsJopqClXCTMX1Te4+oVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718100687; c=relaxed/simple; bh=6tVgkjyqOI9itw8lEaekQQOUJebgN5aDPo+xjDJkHX4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dcbqkD8Rdx2pIdmKcTnpCyZR0S9weNSvWQmfr+K1kX2r8W/MFOoUseKJxbMypeV6DU6iBqSwFPw8AYfGgamBHfVXlh9LHE2cUpzU6Sgb+haT2PMhhOSbdUBXPuCIr3oxcbt5+GFJtAq2+0yPEezSFl92hsM/PCg+jtXZPnZoc+4= 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=d5opbIJS; 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=1718100683; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=nLj8yUsK2lei34HSlxIopppsBC+abcyB+V/ZUwcOo4A=; b=d5opbIJSkEVOPTNByAOoCdOvKH4mh7epYituqTdWbYVGoHQ9hHZomUp8XWlE6DrOv2wgRAH0xTrbE8cLS6qlm2nYmNYWXsSH6Skc91F6WUUrfO5fFQdgzyDCnz74TRsr2VewIt+rhtgRQB0/n+lECiqwWPSllhVB+9d2QvLmQrY= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W8G7ENT_1718100681; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W8G7ENT_1718100681) by smtp.aliyun-inc.com; Tue, 11 Jun 2024 18:11:22 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 6/6] mm: shmem: add mTHP counters for anonymous shmem Date: Tue, 11 Jun 2024 18:11:10 +0800 Message-Id: <4fd9e467d49ae4a747e428bcd821c7d13125ae67.1718090413.git.baolin.wang@linux.alibaba.com> 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 909cfc67521d..212cca384d7e 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_SWPOUT, MTHP_STAT_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 1360a1903b66..3fbcd77f5957 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(swpout, MTHP_STAT_SWPOUT); 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); 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, &swpout_attr.attr, &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 f5469c357be6..99bd3c34f0fb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1773,6 +1773,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 { @@ -1792,9 +1795,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; } @@ -2168,6 +2177,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