Received: by 2002:ab2:644:0:b0:1ec:cbc4:63fb with SMTP id 4csp1158329lqn; Mon, 26 Feb 2024 09:14:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfh4N8vf0/kRSFHZQj+wp7Zkg6bEriDzhcivyUOTz8OYNSrF28qlocy55ycz+IB3fkhl9eu8/zWqtlga+xHFMu21I5j5AN04elYY+DRg== X-Google-Smtp-Source: AGHT+IFEujEhEIfQAju1rvSdabbdEATthRUSWdwc5jC39/1NdSskfkNzyk1+VTsR3YZ3xNcRsl0G X-Received: by 2002:a05:6102:825:b0:470:48ea:1966 with SMTP id k5-20020a056102082500b0047048ea1966mr4925842vsb.14.1708967662048; Mon, 26 Feb 2024 09:14:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708967662; cv=pass; d=google.com; s=arc-20160816; b=LsX0zaufUAqo/5Yvclx70ubhWTdwwNK+p/5tuFLjS8lNxnxbIJ/9PIUsA61aqM7m42 1fIVFehDz1o58kTbA7Com7slFmMHBx+Ce+mCmTlUvYx4hqsom1lzpmvCTyweCAXAcXGL 11/V5Mds4aPOTLfoTHKxqoogTWBVVhJ1g4PJD8fDlRu142DcNcN8RAunmdJHEaXfArcK J+ortTknZH9tB0aFn0fWgdyTphE/N1NLXw0ZLN04iFgTPm3hdscWEHVMLOKyYebjD2Qx iQ5fSH57HPkZgh4qXo8PI2HmNatnxqImrDVT/zSeqlRYKYxWlsqYfqoE9qIkou7Da7a7 csKA== 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 :subject:cc:to:from:date; bh=GrNF/QzEwUHRlDJPYHfli88FEZZDml/FSO7w8vbl0Uc=; fh=gxmD7nJseD6CBvgyDr8VJHxTTPfwtCcjpyj3NVfLBEA=; b=bEHdexpUlBq/3alQxrnScAFmZXiMjfUy6DQMTAG1Hwyg5yDWY723lMNwPvVq8jaxf3 v+fielE436PCnV7EyD8Zz3HHq8vMaq3Ikowqpql4YtFLwoMDDprVUv39V0yiZqJA+N8q ak+Hjc7spYUUtLC8c5ix7jzsB4Yot8v68rjktm1QLWHLtU8ygBdcjwBrXdpZA9xd9nj2 YS++qgCyIpXa6649FdTO+p+8+v1g6agDdy/r2M+kkSJ6p/khvXM35nPcT/MMRUH6lHg8 khHRY0JpJfqc7T5k5L9jsSQRyork4NLx2dcWinak7sGj5HH5cZ4JAZCk9f9xLJVyrtUN Egww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-82016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82016-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p8-20020a67f408000000b004706a9bb92bsi619707vsn.506.2024.02.26.09.14.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 09:14:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82016-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-82016-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82016-linux.lists.archive=gmail.com@vger.kernel.org" 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 A794A1C2A7F2 for ; Mon, 26 Feb 2024 17:14:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18AE612E1C3; Mon, 26 Feb 2024 17:04:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7736B12C55E; Mon, 26 Feb 2024 17:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708967071; cv=none; b=HRk8yplHpxg0b1UsF9A5GRPoKOOWJ8IAuVj9OGaxG8Ugk0g7EH+FHkkyQQN7yZ0jkxwcJVl6qDaD/nelD2Chij9EkudeAAdTatBNLACSLOsyVh0Kduu/GOZsk4ikiUxsceIuanM+4nRXbnFE4pOGL/caK2eO07YDGwS15KL1yRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708967071; c=relaxed/simple; bh=RKIx+oQQY1jqQNQfa40US/jQ3+vApFBCzgxBshqFQus=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tu3cOe2l3agysoF9Zv898TdTnPr4nxX7em4BQMQooWGR6G57PeGRnZe5IGMiA0g8OuT0pSUYapkJfahYC2rZu0ns4EKlJ9SqOvTkaaBVyDa1z8NMWwydGxCimgre31uPEF10bN5WLzyhc0uOLqisxYOAQqlrrhJ21P8ExedYUBM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2875AC433F1; Mon, 26 Feb 2024 17:04:30 +0000 (UTC) Date: Mon, 26 Feb 2024 12:06:29 -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: <20240226120629.0c371252@gandalf.local.home> In-Reply-To: <20240226100045.2083962-1-richardycc@google.com> References: <20240226100045.2083962-1-richardycc@google.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 > + > 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