From mboxrd@z Thu Jan 1 00:00:00 1970 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 819F5C48BF6 for ; Mon, 26 Feb 2024 17:05:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC185440185; Mon, 26 Feb 2024 12:05:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E48E244017F; Mon, 26 Feb 2024 12:05:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE98D440185; Mon, 26 Feb 2024 12:05:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BAC2D44017F for ; Mon, 26 Feb 2024 12:05:33 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6FC69A0E14 for ; Mon, 26 Feb 2024 17:05:33 +0000 (UTC) X-FDA: 81834581346.08.C036B0D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 5922640027 for ; Mon, 26 Feb 2024 17:05:31 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.hostedemail.com: domain of "SRS0=nkCE=KD=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=nkCE=KD=goodmis.org=rostedt@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708967131; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gUOP71r4RNfFXtHp95+xbcsx76Hhme0tfYvSkmKJz34=; b=hW9JIM6jFqRcdQcyDjFGB6kp/sWJN2Xafxwe73eKlAQbHwPoAGvwC4hIueGt29gHOC7+KO S/nvHWFXyOhfuK2z4rs715Qx1y4rd6kyD1zhylkEI6/7RQ91p6SdgGdYgzr4sp1L7a5RIi M0NMpjL5iJFl4QLCCY3FSLGg0UcG60U= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.hostedemail.com: domain of "SRS0=nkCE=KD=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=nkCE=KD=goodmis.org=rostedt@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708967131; a=rsa-sha256; cv=none; b=esWgn2l/ti9dB0pFeM487fudAJbvveG298Zpgcqehdc+rr1wd5zwZkRZlgM6NxrdCg06sy SPilVQUHetYG2G91UhE9Qqynqz7Dk83Kajex5MvVlTgR1fVb6ac8ctkqJWV5sfftCrIqlN jGj0JjAPAXCQ0pdaHbKxG6K0R58vIh0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 511A260F91; Mon, 26 Feb 2024 17:05:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2810C433F1; Mon, 26 Feb 2024 17:05:28 +0000 (UTC) Date: Mon, 26 Feb 2024 12:07:28 -0500 From: Steven Rostedt To: Richard Chang Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, liumartin@google.com, surenb@google.com, minchan@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: add alloc_contig_migrate_range allocation statistics Message-ID: <20240226120728.3f495fa7@gandalf.local.home> In-Reply-To: <20240226120629.0c371252@gandalf.local.home> References: <20240226100045.2083962-1-richardycc@google.com> <20240226120629.0c371252@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 5922640027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: zq6c7ihhp8qmeqq3abj1h6ym8rsnnmrs X-HE-Tag: 1708967131-286534 X-HE-Meta: U2FsdGVkX18+bJJASmcRIE6F7nJC9PEM0sOVwJkJ/BQO0z8DpuaIewjqGqDXzHdKOFA24C5AjOB06pTljaHdKkw3uGMa7O1NviforedojXSd+9d4kW2oW6IEIcZMst2WQzAoj+ezYqF//emSc35F1p4sS448Vi8iaUfQQS2rQCPnYCbfVoaTp350ZqOrLWabSHhqHxMw9irUmvUyvEdP9UrMWPRXkh/MPHivQhGHtOJxIFWoNkB0gSkbdZZLunwGprlT4g9Fbv8GuMx9i2e/RQd6jSGbUEbYDxcxr34NoDJViSVYZxQj/aNAHNWeNK+k7MbwuhOJGHy8oO/YFCc11ZhurSz/13a1nd6v9BjAirxKV3+bhm4+kcA9qKcYyXt8StZs2EYJomxEfM5hNA3EAhR1ReioZ8m0qwylnTaAgV3GyNla15XdfETlKMyBxjupVxh68/ZnVo4It+znWVz3RefcanA4jPyazbDLZ4QpGrw9FM27dEsSerwYWgzBCFg41oVf6aDhzqs5oS3CvJ6e9pe/WYa29SgGSITr4hbyYSwESZ9AwCu3wYm4CUh74Ss7KxJyDVQPClvSQ+hG8ntMNSnWEBjBiCTGami0SoX/0tZwVFjSYgsFXydos5p8E6UgHLV8/VB/t61x06/q9B4j/ibSVnHHLM9+QNoOr7Nr27YN/d1XYZMMEVheJA4VqdqldyZKaP1vpiK0H5a6Hr1GMfj4SD78N3dpayWhB8VDU7z7UTum5xP/C4hW4nGNoMOnLvUlBMLvVMHO1ZTHo7XWG+760TX+x6u7hc1yvq1RWFy26BL4NxLftvPgXsj+kNxrtNxqImr+GN4iQ7TMFF9TV7pnu4hfSamjwzcT7s0D+Jenrrc7LHfJHJCC00JbrMytP0nKHUcS8nnUB9TTyYwLI4UYPe/unZSxKRI32XezcXEo8yJLuWpay2lZCwCyfhr2TomstGCRL7CWl9O4d+L RILsXA9k jtjyWnH+tdCmjLfvrdtycjWMlWlMWLJ/tqiwZurDdWJYrl4BmyIZNIFDiZYNgNsXkmJKVT13pfRogTRSLKSMR77+0Ifve83laOIPfWBR0+dhnrGA7EvqEO2RYLMIal3niB0R6UF9OXKIdDBhCCcNeyUDv0mX3m7Pu0+AqUSmY0G4OrVKROBoMQJPGE44AEmIauXX7cCXUOeHJ8oVJ9yXDK4xHOVp/zhaRc+ok/8BUTX+gMcvSo36J5Fk5TjSG60R8/g12kjyLZjMMaJOoFZcRf8ZaDbaA2FIVFNadkQyek0RDFMDr9IswVSjgeNiWRkDn/HWVr4YOvYOFORY0aHukCYIGi8a7j3e5go16pzSayhorW/eY2GrjvJyWDjjW5ZHkZWmO 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: On Mon, 26 Feb 2024 12:06:29 -0500 Steven Rostedt wrote: > On Mon, 26 Feb 2024 10:00:15 +0000 > Richard Chang wrote: > > > alloc_contig_migrate_range has every information to be able to > > understand big contiguous allocation latency. For example, how many > > pages are migrated, how many times they were needed to unmap from > > page tables. > > > > This patch adds the trace event to collect the allocation statistics. > > In the field, it was quite useful to understand CMA allocation > > latency. > > > > Signed-off-by: Richard Chang > > --- > > include/trace/events/kmem.h | 39 +++++++++++++++++++++++++++++++++++++ > > mm/internal.h | 3 ++- > > mm/page_alloc.c | 30 +++++++++++++++++++++++----- > > mm/page_isolation.c | 2 +- > > 4 files changed, 67 insertions(+), 7 deletions(-) > > > > diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h > > index 58688768ef0f..964704d76f9f 100644 > > --- a/include/trace/events/kmem.h > > +++ b/include/trace/events/kmem.h > > @@ -304,6 +304,45 @@ TRACE_EVENT(mm_page_alloc_extfrag, > > __entry->change_ownership) > > ); > > > > +TRACE_EVENT(mm_alloc_contig_migrate_range_info, > > + > > + TP_PROTO(unsigned long start, > > + unsigned long end, > > + int migratetype, > > + unsigned long nr_migrated, > > + unsigned long nr_reclaimed, > > + unsigned long nr_mapped), > > + > > + TP_ARGS(start, end, migratetype, > > + nr_migrated, nr_reclaimed, nr_mapped), > > + > > + TP_STRUCT__entry( > > + __field(unsigned long, start) > > + __field(unsigned long, end) > > + __field(int, migratetype) > > > Please move the int to the end of the longs, as it will cause a 4 byte hole > in 64 bit machines otherwise. > > > > + __field(unsigned long, nr_migrated) > > + __field(unsigned long, nr_reclaimed) > > + __field(unsigned long, nr_mapped) > > + ), > > + > > + TP_fast_assign( > > + __entry->start = start; > > + __entry->end = end; > > + __entry->migratetype = migratetype; > > + __entry->nr_migrated = nr_migrated; > > + __entry->nr_reclaimed = nr_reclaimed; > > + __entry->nr_mapped = nr_mapped; > > + ), > > + > > + TP_printk("start=0x%lx end=0x%lx migratetype=%d nr_migrated=%lu nr_reclaimed=%lu nr_mapped=%lu", > > + __entry->start, > > + __entry->end, > > + __entry->migratetype, > > + __entry->nr_migrated, > > + __entry->nr_reclaimed, > > + __entry->nr_mapped) > > +); > > + > > /* > > * Required for uniquely and securely identifying mm in rss_stat tracepoint. > > */ > > diff --git a/mm/internal.h b/mm/internal.h > > index f309a010d50f..e114c647e278 100644 > > --- a/mm/internal.h > > +++ b/mm/internal.h > > @@ -537,7 +537,8 @@ isolate_migratepages_range(struct compact_control *cc, > > unsigned long low_pfn, unsigned long end_pfn); > > > > int __alloc_contig_migrate_range(struct compact_control *cc, > > - unsigned long start, unsigned long end); > > + unsigned long start, unsigned long end, > > + int migratetype); > > > > /* Free whole pageblock and set its migration type to MIGRATE_CMA. */ > > void init_cma_reserved_pageblock(struct page *page); > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 150d4f23b010..f840bc785afa 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -6219,9 +6219,14 @@ static void alloc_contig_dump_pages(struct list_head *page_list) > > } > > } > > > > -/* [start, end) must belong to a single zone. */ > > +/* > > + * [start, end) must belong to a single zone. > > + * @migratetype: using migratetype to filter the type of migration in > > + * trace_mm_alloc_contig_migrate_range_info. > > + */ > > int __alloc_contig_migrate_range(struct compact_control *cc, > > - unsigned long start, unsigned long end) > > + unsigned long start, unsigned long end, > > + int migratetype) > > { > > /* This function is based on compact_zone() from compaction.c. */ > > unsigned int nr_reclaimed; > > @@ -6232,6 +6237,10 @@ int __alloc_contig_migrate_range(struct compact_control *cc, > > .nid = zone_to_nid(cc->zone), > > .gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, > > }; > > + struct page *page; > > + unsigned long total_mapped = 0; > > + unsigned long total_migrated = 0; > > + unsigned long total_reclaimed = 0; > > > > lru_cache_disable(); > > > > @@ -6257,9 +6266,16 @@ int __alloc_contig_migrate_range(struct compact_control *cc, > > &cc->migratepages); > > cc->nr_migratepages -= nr_reclaimed; > > > > + total_reclaimed += nr_reclaimed; > > + list_for_each_entry(page, &cc->migratepages, lru) > > + total_mapped += page_mapcount(page); > > You're doing this calculation regardless of if tracing is enabled or not > and it's only used for tracing? Please add: > > if (trace_mm_alloc_contig_migrate_range_info_enabled()) { > total_reclaimed += nr_reclaimed; > list_for_each_entry(page, &cc->migratepages, lru) > total_mapped += page_mapcount(page); > } > > -- Steve Oops, I forgot to remove this sig when I came back and added the below reply too. -- Steve > > > + > > ret = migrate_pages(&cc->migratepages, alloc_migration_target, > > NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL); > > > > + if (!ret) > > May want the above to be: > > if (trace_mm_alloc_config_migrate_range_info_enabled() && !ret) > > too. > > -- Steve > > > + total_migrated += cc->nr_migratepages; > > + > > /* > > * On -ENOMEM, migrate_pages() bails out right away. It is pointless > > * to retry again over this error, so do the same here. > > @@ -6273,9 +6289,13 @@ int __alloc_contig_migrate_range(struct compact_control *cc, > > if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY) > > alloc_contig_dump_pages(&cc->migratepages); > > putback_movable_pages(&cc->migratepages); > > - return ret; > > } > > - return 0; > > + > > + trace_mm_alloc_contig_migrate_range_info(start, end, migratetype, > > + total_migrated, > > + total_reclaimed, > > + total_mapped); > > + return (ret < 0) ? ret : 0; > > } > > > > /** > > @@ -6355,7 +6375,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, > > * allocated. So, if we fall through be sure to clear ret so that > > * -EBUSY is not accidentally used or returned to caller. > > */ > > - ret = __alloc_contig_migrate_range(&cc, start, end); > > + ret = __alloc_contig_migrate_range(&cc, start, end, migratetype); > > if (ret && ret != -EBUSY) > > goto done; > > ret = 0; > > diff --git a/mm/page_isolation.c b/mm/page_isolation.c > > index cd0ea3668253..a5c8fa4c2a75 100644 > > --- a/mm/page_isolation.c > > +++ b/mm/page_isolation.c > > @@ -434,7 +434,7 @@ static int isolate_single_pageblock(unsigned long boundary_pfn, int flags, > > } > > > > ret = __alloc_contig_migrate_range(&cc, head_pfn, > > - head_pfn + nr_pages); > > + head_pfn + nr_pages, page_mt); > > > > /* > > * restore the page's migratetype so that it can >