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 X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74FB7C433E0 for ; Thu, 28 Jan 2021 10:43:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C944264DD8 for ; Thu, 28 Jan 2021 10:43:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C944264DD8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1EA216B0005; Thu, 28 Jan 2021 05:43:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19BEB6B0006; Thu, 28 Jan 2021 05:43:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03D056B006C; Thu, 28 Jan 2021 05:43:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id E35D76B0005 for ; Thu, 28 Jan 2021 05:43:51 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id AF2643629 for ; Thu, 28 Jan 2021 10:43:51 +0000 (UTC) X-FDA: 77754848262.23.roll33_1a089782759f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 8E28F37604 for ; Thu, 28 Jan 2021 10:43:51 +0000 (UTC) X-HE-Tag: roll33_1a089782759f X-Filterd-Recvd-Size: 9464 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 Jan 2021 10:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611830630; h=from:from: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=Dw9zDJQiGZ1YCHqJQvqME8NDU//TGGhOg7spnlegjY8=; b=L38jV59iTLJvSbqMWeHbwehLDwMLyMhdXAbO+1t8DZyUDeUoEpNV+8ABb1psoZ9PWk7Iif uN4ZXwSAIusVmWUT5YSRpoZHUJqIGitHQQYEHqAhmuhQVarFrIWqYkQQkwR9wNuCgJZ843 3+7ufKESiA6nPslH02ZoQtKOrDqjf/Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-444-nbLBKEOSNeaDEXhqLmPqwg-1; Thu, 28 Jan 2021 05:43:46 -0500 X-MC-Unique: nbLBKEOSNeaDEXhqLmPqwg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BED2107ACE4; Thu, 28 Jan 2021 10:43:44 +0000 (UTC) Received: from [10.36.113.207] (ovpn-113-207.ams2.redhat.com [10.36.113.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id A21E27D54A; Thu, 28 Jan 2021 10:43:42 +0000 (UTC) To: Oscar Salvador Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Thomas Gleixner , "Peter Zijlstra (Intel)" , Mike Rapoport , Michal Hocko , Wei Yang References: <20210127101813.6370-1-david@redhat.com> <20210127101813.6370-3-david@redhat.com> <20210128102234.GB5250@localhost.localdomain> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: [PATCH v1 2/2] mm/page_alloc: count CMA pages per zone and print them in /proc/zoneinfo Message-ID: <2246d657-4f6d-c27d-4ae2-853a8437cda9@redhat.com> Date: Thu, 28 Jan 2021 11:43:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20210128102234.GB5250@localhost.localdomain> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Content-Transfer-Encoding: quoted-printable 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: On 28.01.21 11:22, Oscar Salvador wrote: > On Wed, Jan 27, 2021 at 11:18:13AM +0100, David Hildenbrand wrote: >> Let's count the number of CMA pages per zone and print them in >> /proc/zoneinfo. >> >> Having access to the total number of CMA pages per zone is helpful for >> debugging purposes to know where exactly the CMA pages ended up, and t= o >> figure out how many pages of a zone might behave differently (e.g., li= ke >> ZONE_MOVABLE) - even after some of these pages might already have been >> allocated. >=20 > My knowledge of CMA tends to be quite low, actually I though that CMA > was somehow tied to ZONE_MOVABLE. CMA is often placed into one of the kernel zones, but can also end up in = the movable zone. >=20 > I see how tracking CMA pages per zona might give you a clue, but what d= o > you mean by "might behave differently - even after some of these pages = might > already have been allocated" Assume you have 4GB in ZONE_NORMAL but 1GB is assigned for CMA. You actua= lly only have 3GB available for random kernel allocations, not 4GB. Currently, you can only observe the free CMA pages, excluding any pages t= hat are already allocated. Having that information how many CMA pages we = have can be helpful - similar to what we already have in /proc/meminfo. >=20 >> For now, we are only able to get the global nr+free cma pages from >> /proc/meminfo and the free cma pages per zone from /proc/zoneinfo. >> >> Note: Track/print that information even without CONFIG_CMA, similar to >> "nr_free_cma" in /proc/zoneinfo. This is different to /proc/meminfo - >> maybe we want to make that consistent in the future (however, changing >> /proc/zoneinfo output might uglify the code a bit). >> Cc: Andrew Morton >> Cc: Thomas Gleixner >> Cc: "Peter Zijlstra (Intel)" >> Cc: Mike Rapoport >> Cc: Oscar Salvador >> Cc: Michal Hocko >> Cc: Wei Yang >> Signed-off-by: David Hildenbrand >> --- >> include/linux/mmzone.h | 4 ++++ >> mm/page_alloc.c | 1 + >> mm/vmstat.c | 6 ++++-- >> 3 files changed, 9 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >> index ae588b2f87ef..3bc18c9976fd 100644 >> --- a/include/linux/mmzone.h >> +++ b/include/linux/mmzone.h >> @@ -503,6 +503,9 @@ struct zone { >> * bootmem allocator): >> * managed_pages =3D present_pages - reserved_pages; >> * >> + * cma pages is present pages that are assigned for CMA use >> + * (MIGRATE_CMA). >> + * >> * So present_pages may be used by memory hotplug or memory power >> * management logic to figure out unmanaged pages by checking >> * (present_pages - managed_pages). And managed_pages should be use= d >> @@ -527,6 +530,7 @@ struct zone { >> atomic_long_t managed_pages; >> unsigned long spanned_pages; >> unsigned long present_pages; >> + unsigned long cma_pages; >=20 > I see that NR_FREE_CMA_PAGES is there even without CONFIG_CMA, as you > said, but I am not sure about adding size to a zone unconditionally. > I mean, it is not terrible as IIRC, the maximum MAX_NUMNODES can get > is 1024, and on x86_64 that would be (1024 * 4 zones) * 8 =3D 32K. > So not a big deal, but still. I'm asking myself how many such systems will run without CONFIG_CMA in the future. >=20 > Besides following NR_FREE_CMA_PAGES, is there any reason for not doing: >=20 > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 1e22d96734e0..2d8a830d168d 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -436,6 +436,9 @@ struct zone { > unsigned long managed_pages; > unsigned long spanned_pages; > unsigned long present_pages; > +#ifdef CONFIG_CMA > + unsigned long cma_pages; > +#endif > =20 > const char *name; > =20 > diff --git a/mm/vmstat.c b/mm/vmstat.c > index 8ba0870ecddd..5757df4bfd45 100644 > --- a/mm/vmstat.c > +++ b/mm/vmstat.c > @@ -1559,13 +1559,15 @@ static void zoneinfo_show_print(struct seq_file= *m, pg_data_t *pgdat, > "\n spanned %lu" > "\n present %lu" > "\n managed %lu", > + "\n cma %lu", > zone_page_state(zone, NR_FREE_PAGES), > min_wmark_pages(zone), > low_wmark_pages(zone), > high_wmark_pages(zone), > zone->spanned_pages, > zone->present_pages, > - zone->managed_pages); > + zone->managed_pages, > + IS_ENABLED(CONFIG_CMA) ? zone->cma_pages : 0); > =20 > seq_printf(m, > "\n protection: (%ld", >=20 >=20 > I do not see it that ugly, but just my taste. IIRC, that does not work. The compiler will still complain about a missing struct members. We would have to provide a zone_cma_pages() helper with some ifdefery. We could do something like this on top --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -530,7 +530,9 @@ struct zone { atomic_long_t managed_pages; unsigned long spanned_pages; unsigned long present_pages; +#ifdef CONFIG_CMA unsigned long cma_pages; +#endif =20 const char *name; =20 diff --git a/mm/vmstat.c b/mm/vmstat.c index 97fc32a53320..b753a64f099f 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1643,7 +1643,10 @@ static void zoneinfo_show_print(struct seq_file *m= , pg_data_t *pgdat, "\n spanned %lu" "\n present %lu" "\n managed %lu" - "\n cma %lu", +#ifdef CONFIG_CMA + "\n cma %lu" +#endif + "%s", zone_page_state(zone, NR_FREE_PAGES), min_wmark_pages(zone), low_wmark_pages(zone), @@ -1651,7 +1654,10 @@ static void zoneinfo_show_print(struct seq_file *m= , pg_data_t *pgdat, zone->spanned_pages, zone->present_pages, zone_managed_pages(zone), - zone->cma_pages); +#ifdef CONFIG_CMA + zone->cma_pages, +#endif + ""); =20 seq_printf(m, "\n protection: (%ld", Getting rid of NR_FREE_CMA_PAGES will be more ugly. --=20 Thanks, David / dhildenb