From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta22.hihonor.com (mta22.honor.com [81.70.192.198]) (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 E3A54327213 for ; Fri, 28 Nov 2025 12:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.192.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764331421; cv=none; b=mbheJCzHBvvWcmHgBfFZU5Nl+JFswclvE4/XZf4BQQCNse1tP6X/GgibZW/im5h8GlUNBre1O/4V9E0fAVyycq2FhxdCgQmMa4ALulR+SCrJtXVvISP8Ui16gCEzxVdJaIGHxofzWwW4U13ZkfZ39uwhreCM+OuhEt921Z/Izuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764331421; c=relaxed/simple; bh=pEeR7Oo+l14MuuF7wm4y1BsAvc/JypQVvcuDwJi3wwk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vjwk0pJjeNuTBkXVXQmd9cM3j82eS5liNdXOahUuPNlPzzN00NiFNFcJiaNZX3FKW0LBrkSzbXlUlfoS8z5B4Y9aSAQITVOG4ZfQcxTPfALDMHQ3LqT7VhARqyosxkpbLlDHtPa2bqx5xnkRWcaByFeL9gG6S/IVFbdUXySps0U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; dkim=pass (1024-bit key) header.d=honor.com header.i=@honor.com header.b=T8jKQgdU; arc=none smtp.client-ip=81.70.192.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=honor.com header.i=@honor.com header.b="T8jKQgdU" dkim-signature: v=1; a=rsa-sha256; d=honor.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=To:From; bh=0JX+62Pp8uju8BDAawX/OvVTdkdk/Op1RBKURLR7P9E=; b=T8jKQgdUOojwZ57jCC6fGrfjMfjbJ1bUfWVkfdddJU9mts0KXWNl0SPe4yMyV+hE4QvHMzEsR Tag0V+kEBMrJ3vg2K/jFbTKgHoRy5XAWAj5amy4ta+4qVWckj2iitOol5zP8XByvimTHI+W8xjQ WCpmiGMcXvi7SIc+oslQCgs= Received: from w011.hihonor.com (unknown [10.68.20.122]) by mta22.hihonor.com (SkyGuard) with ESMTPS id 4dHsN56YbpzYl6fH; Fri, 28 Nov 2025 20:01:41 +0800 (CST) Received: from a018.hihonor.com (10.68.17.250) by w011.hihonor.com (10.68.20.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 28 Nov 2025 20:03:33 +0800 Received: from localhost.localdomain (10.144.20.219) by a018.hihonor.com (10.68.17.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 28 Nov 2025 20:03:32 +0800 From: zhongjinji To: CC: , , , , , , , , , , , , , , , , Subject: Re: [PATCH 2/3] mm/vmstat: get fragmentation statistics from per-migragetype count Date: Fri, 28 Nov 2025 20:03:28 +0800 Message-ID: <20251128120328.8693-1-zhongjinji@honor.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <780ded63aca04eb513d6e7e2c8862e6972b84b45.1764297987.git.zhanghongru@xiaomi.com> References: <780ded63aca04eb513d6e7e2c8862e6972b84b45.1764297987.git.zhanghongru@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: w011.hihonor.com (10.68.20.122) To a018.hihonor.com (10.68.17.250) Hi, Hongru > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 9431073e7255..a90f2bf735f6 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -818,7 +818,8 @@ static inline void __add_to_free_list(struct page *page, struct zone *zone, > else > list_add(&page->buddy_list, &area->free_list[migratetype]); > area->nr_free++; > - area->mt_nr_free[migratetype]++; > + WRITE_ONCE(area->mt_nr_free[migratetype], > + area->mt_nr_free[migratetype] + 1); > > if (order >= pageblock_order && !is_migrate_isolate(migratetype)) > __mod_zone_page_state(zone, NR_FREE_PAGES_BLOCKS, nr_pages); > @@ -841,8 +842,8 @@ static inline void move_to_free_list(struct page *page, struct zone *zone, > get_pageblock_migratetype(page), old_mt, nr_pages); > > list_move_tail(&page->buddy_list, &area->free_list[new_mt]); > - area->mt_nr_free[old_mt]--; > - area->mt_nr_free[new_mt]++; > + WRITE_ONCE(area->mt_nr_free[old_mt], area->mt_nr_free[old_mt] - 1); > + WRITE_ONCE(area->mt_nr_free[new_mt], area->mt_nr_free[new_mt] + 1); > > account_freepages(zone, -nr_pages, old_mt); > account_freepages(zone, nr_pages, new_mt); > @@ -873,7 +874,8 @@ static inline void __del_page_from_free_list(struct page *page, struct zone *zon > __ClearPageBuddy(page); > set_page_private(page, 0); > area->nr_free--; > - area->mt_nr_free[migratetype]--; > + WRITE_ONCE(area->mt_nr_free[migratetype], > + area->mt_nr_free[migratetype] - 1); It doesn't seem like a good idea to use WRITE_ONCE on the hot path. > > if (order >= pageblock_order && !is_migrate_isolate(migratetype)) > __mod_zone_page_state(zone, NR_FREE_PAGES_BLOCKS, -nr_pages); > diff --git a/mm/vmstat.c b/mm/vmstat.c > index bb09c032eecf..9334bbbe1e16 100644 > --- a/mm/vmstat.c > +++ b/mm/vmstat.c > @@ -1590,32 +1590,16 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, > zone->name, > migratetype_names[mtype]); > for (order = 0; order < NR_PAGE_ORDERS; ++order) { > - unsigned long freecount = 0; > - struct free_area *area; > - struct list_head *curr; > + unsigned long freecount; > bool overflow = false; > > - area = &(zone->free_area[order]); > - > - list_for_each(curr, &area->free_list[mtype]) { > - /* > - * Cap the free_list iteration because it might > - * be really large and we are under a spinlock > - * so a long time spent here could trigger a > - * hard lockup detector. Anyway this is a > - * debugging tool so knowing there is a handful > - * of pages of this order should be more than > - * sufficient. > - */ > - if (++freecount >= 100000) { > - overflow = true; > - break; > - } > + /* Keep the same output format for user-space tools compatibility */ > + freecount = READ_ONCE(zone->free_area[order].mt_nr_free[mtype]); I think it might be better for using an array of size NR_PAGE_ORDERS to store the free count for each order. Like the code below. unsigned long freecount[NR_PAGE_ORDERS] spin_lock_irq(&zone->lock) for_each_order freecount[order] = zone->free_area[order].mt_nr_free[mtype] spin_unlock_irq(&zone->lock) for_each_order print freecount[order] > + if (freecount >= 100000) { > + overflow = true; > + freecount = 100000; > } > seq_printf(m, "%s%6lu ", overflow ? ">" : "", freecount); > - spin_unlock_irq(&zone->lock); > - cond_resched(); > - spin_lock_irq(&zone->lock); > } > seq_putc(m, '\n'); > } > @@ -1633,7 +1617,7 @@ static void pagetypeinfo_showfree(struct seq_file *m, void *arg) > seq_printf(m, "%6d ", order); > seq_putc(m, '\n'); > > - walk_zones_in_node(m, pgdat, true, false, pagetypeinfo_showfree_print); > + walk_zones_in_node(m, pgdat, true, true, pagetypeinfo_showfree_print); > }