Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp531016lqd; Wed, 24 Apr 2024 09:17:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWLJzoM+ly4sroumTaDNK30irkPj9WfMMc1r9JRt47MUEHUy2eBW/+k1X5nB8MgmRxVYf+oeKbwya2K5j9Cr11qtg+dk+kr/9BhyMcZGg== X-Google-Smtp-Source: AGHT+IE5/VM9Dt4cpRmQuVcdLPt8uxoci00XoRHO4XYbrY46QQbDU9rNZQNLH+JO3hFkuJRxztEY X-Received: by 2002:a17:90b:3b85:b0:2ae:63e9:113f with SMTP id pc5-20020a17090b3b8500b002ae63e9113fmr2454112pjb.44.1713975420845; Wed, 24 Apr 2024 09:17:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713975420; cv=pass; d=google.com; s=arc-20160816; b=QkZHlXRvchw31zMb/XRZwqAJ9UK11+OjeijrssUx2rLY/6xD44gQ1+QadOVlChOj8x NqjW13PRry1xMMiL6TYdTxYipxEO40lu2myxqwoDrjRExc/dAwIusBX40fZRaXBoI6nI wy5jBCyBzTbYF7JJLPT3AkxIP/dilNDndObpbaytg+fKuo95vvha3Q3DZAJQxUiaGUte lMhu15pXZE6xWYKKUfyqPknmThlnKWfbBEA3NEcHaWRGO2r5lvKRBxWlT5/aKt6Fxi7x 9XdeMmwtS/gKkZiVU8yEzZqWR9YVaIZXyYf0oEA3NaHRWTpBfU0XebrpNlVAc950ANf4 3Mrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=311R666ZqdnPYzFUWxZS9joLbDsGQyRQSi08ptf5A6E=; fh=eYoYI5YrJHzTxHAEfF/Q0Xgw2jLXorlkn2Yw8ByzRog=; b=TwYklIsSeEs6iLT4jJtGR6uZHsJlRpgRvHZRKLxeuhOIlk5nBSaeAa6yCl+qkBraZm fgGIym1Cec5hZe2HnAlAN7QS1BAH6nlQZ1KkQeek70TaHNw+Q7jUrvKGLVmU9URG+LVU CQhv1/z7lhWDGTaOcs7SKfNJn5XCwgJF8H5PyrORWclJwbEHlVGjotdrsh44Zar0SJIK 34vS+BftHZGcOKAy+ocj7SB0KMWsfR9nVArRxDEwn/I7MPerGzHY1GHYzi30MGmmedJc 2eaFh8UaeZJ7Az92BT6SKR3/fPqPzw6fQfgMZPYnr+uUNEtk87OdsficCKboFIjvJIu6 0j4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-157233-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157233-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id g13-20020a17090adb0d00b002ae11fae035si5046333pjv.86.2024.04.24.09.17.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 09:17:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157233-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-157233-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157233-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 2C517B2BB44 for ; Wed, 24 Apr 2024 15:44:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4815216C437; Wed, 24 Apr 2024 15:41:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D43716ABC7 for ; Wed, 24 Apr 2024 15:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973298; cv=none; b=sZ7Vki9tsDL1rMeYyLqia2ixvRq6hHxgnonP316ij2/HraQqCwdy6EGlkw5UQCPpEdg1Ikro8gAkFgU3Qd5eP5T32NbFR3hJjYFx0SVCAhLDf5nM5oyzowZUY1sOL3Um24Re3JREAVbNnCmaTn6cxHYCfu9ETvO6nbQnodd3BlA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713973298; c=relaxed/simple; bh=YDOT+Scl4Ftcid46ZrKpdxOL3JYX1bQJU/XlxKOLZyw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kmjw+OlhfCZWblRlYaSbrq+Qvhe5AdC/k4vr9O2bzfdmuKk4u8IAaIi/1TG9Fr03QgOS8JJEpsyGKnfRcJ9jJq9uCLGObL1dPkUTMTEOgzAMKod2gc8je/Tvanqpis8M6+020KM9tHuZlT+zKBLc+9msCyJXR7hlRf5UegQN+9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 344EB1063; Wed, 24 Apr 2024 08:42:04 -0700 (PDT) Received: from [10.1.25.156] (XHFQ2J9959.cambridge.arm.com [10.1.25.156]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 865833F73F; Wed, 24 Apr 2024 08:41:35 -0700 (PDT) Message-ID: Date: Wed, 24 Apr 2024 16:41:34 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] mm: add per-order mTHP split counters Content-Language: en-GB To: Lance Yang , akpm@linux-foundation.org, Barry Song <21cnbao@gmail.com> Cc: 21cnbao@gmail.com, david@redhat.com, baolin.wang@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20240424135148.30422-1-ioworker0@gmail.com> <20240424135148.30422-2-ioworker0@gmail.com> From: Ryan Roberts In-Reply-To: <20240424135148.30422-2-ioworker0@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit + Barry On 24/04/2024 14:51, Lance Yang wrote: > At present, the split counters in THP statistics no longer include > PTE-mapped mTHP. Therefore, this commit introduces per-order mTHP split > counters to monitor the frequency of mTHP splits. This will assist > developers in better analyzing and optimizing system performance. > > /sys/kernel/mm/transparent_hugepage/hugepages-/stats > split_page > split_page_failed > deferred_split_page > > Signed-off-by: Lance Yang > --- > include/linux/huge_mm.h | 3 +++ > mm/huge_memory.c | 14 ++++++++++++-- > 2 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > index 56c7ea73090b..7b9c6590e1f7 100644 > --- a/include/linux/huge_mm.h > +++ b/include/linux/huge_mm.h > @@ -272,6 +272,9 @@ enum mthp_stat_item { > MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, > MTHP_STAT_ANON_SWPOUT, > MTHP_STAT_ANON_SWPOUT_FALLBACK, > + MTHP_STAT_SPLIT_PAGE, > + MTHP_STAT_SPLIT_PAGE_FAILED, > + MTHP_STAT_DEFERRED_SPLIT_PAGE, > __MTHP_STAT_COUNT > }; > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 055df5aac7c3..52db888e47a6 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -557,6 +557,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(split_page, MTHP_STAT_SPLIT_PAGE); > +DEFINE_MTHP_STAT_ATTR(split_page_failed, MTHP_STAT_SPLIT_PAGE_FAILED); > +DEFINE_MTHP_STAT_ATTR(deferred_split_page, MTHP_STAT_DEFERRED_SPLIT_PAGE); > > static struct attribute *stats_attrs[] = { > &anon_fault_alloc_attr.attr, > @@ -564,6 +567,9 @@ static struct attribute *stats_attrs[] = { > &anon_fault_fallback_charge_attr.attr, > &anon_swpout_attr.attr, > &anon_swpout_fallback_attr.attr, > + &split_page_attr.attr, > + &split_page_failed_attr.attr, > + &deferred_split_page_attr.attr, > NULL, > }; > > @@ -3083,7 +3089,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; > @@ -3262,8 +3268,10 @@ 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_PAGE : > + MTHP_STAT_SPLIT_PAGE_FAILED); > return ret; > } > > @@ -3327,6 +3335,8 @@ void deferred_split_folio(struct folio *folio) > if (list_empty(&folio->_deferred_list)) { > if (folio_test_pmd_mappable(folio)) > count_vm_event(THP_DEFERRED_SPLIT_PAGE); > + count_mthp_stat(folio_order(folio), > + MTHP_STAT_DEFERRED_SPLIT_PAGE); There is a very long conversation with Barry about adding a 'global "mTHP became partially mapped 1 or more processes" counter (inc only)', which terminates at [1]. There is a lot of discussion about the required semantics around the need for partial map to cover alignment and contiguity as well as whether all pages are mapped, and to trigger once it becomes partial in at least 1 process. MTHP_STAT_DEFERRED_SPLIT_PAGE is giving much simpler semantics, but less information as a result. Barry, what's your view here? I'm guessing this doesn't quite solve what you are looking for? [1] https://lore.kernel.org/linux-mm/6cc7d781-884f-4d8f-a175-8609732b87eb@arm.com/ Thanks, Ryan > list_add_tail(&folio->_deferred_list, &ds_queue->split_queue); > ds_queue->split_queue_len++; > #ifdef CONFIG_MEMCG