mm: Use unsigned types for fragmentation score
Subsystems (5)
PATCH 1/1 mm: Use unsigned types for fragmentation score
Proactive compaction uses per-node/zone "fragmentation score" which is always in range [0, 100], so use unsigned type of these scores as well as for related constants.
--- include/linux/compaction.h | 4 ++-- kernel/sysctl.c | 2 +- mm/compaction.c | 18 +++++++++--------- mm/vmstat.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)
include/linux/compaction.h +2 -2
@@ -85,13 +85,13 @@ static inline unsigned long compact_gap(unsigned int order)#ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; -extern int sysctl_compaction_proactiveness; +extern unsigned int sysctl_compaction_proactiveness;extern int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos);extern int sysctl_extfrag_threshold;extern int sysctl_compact_unevictable_allowed; -extern int extfrag_for_order (struct zone *zone,unsigned int order); +extern unsigned int extfrag_for_order (struct zone *zone,unsigned int order);extern int fragmentation_index (struct zone *zone,unsigned int order); extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags,
kernel/sysctl.c +1 -1
@@ -2833,7 +2833,7 @@ static struct ctl_table vm_table[] = { { .procname = "compaction_proactiveness", .data = &sysctl_compaction_proactiveness, - .maxlen = sizeof(int), + .maxlen = sizeof(sysctl_compaction_proactiveness), .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO,
mm/compaction.c +9 -9
@@ -53,7 +53,7 @@ static inline void count_compact_events(enum vm_event_item item, long delta)/* * Fragmentation score check interval for proactive compaction purposes. */ -static const int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ; +static const unsigned int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ;/* * Page order with-respect-to which proactive compaction
@@ -1890,7 +1890,7 @@ static bool kswapd_is_running(pg_data_t *pgdat)* ZONE_DMA32. For smaller zones, the score value remains close to zero, * and thus never exceeds the high threshold for proactive compaction. */ -static int fragmentation_score_zone (struct zone *zone) +static unsigned int fragmentation_score_zone (struct zone *zone) {unsigned long score;
@@ -1906,9 +1906,9 @@ static int fragmentation_score_zone(struct zone *zone)* the node's score falls below the low threshold, or one of the back-off * conditions is met. */ -static int fragmentation_score_node (pg_data_t *pgdat) +static unsigned int fragmentation_score_node (pg_data_t *pgdat) { -unsigned long score =0 ; +unsigned int score =0 ;int zoneid;for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {
@@ -1921,17 +1921,17 @@ static int fragmentation_score_node(pg_data_t *pgdat)return score; } -static int fragmentation_score_wmark (pg_data_t *pgdat,bool low) +static unsigned int fragmentation_score_wmark (pg_data_t *pgdat,bool low) { -int wmark_low; +unsigned int wmark_low;/* * Cap the low watermak to avoid excessive compaction * activity in case a user sets the proactivess tunable * close to 100 (maximum). */ - wmark_low =max (100 - sysctl_compaction_proactiveness,5 ); -return low ? wmark_low :min (wmark_low +10 ,100 ); + wmark_low =max (100U - sysctl_compaction_proactiveness,5U ); +return low ? wmark_low :min (wmark_low +10 ,100U ); }static bool should_proactive_compact_node (pg_data_t *pgdat)
@@ -2604,7 +2604,7 @@ int sysctl_compact_memory;* aggressively the kernel should compact memory in the * background. It takes values in the range [0, 100]. */ -int __read_mostly sysctl_compaction_proactiveness =20 ; +unsigned int __read_mostly sysctl_compaction_proactiveness =20 ;/* * This is the entry point for compacting all nodes via
mm/vmstat.c +1 -1
@@ -1079,7 +1079,7 @@ static int __fragmentation_index(unsigned int order, struct contig_page_info *in* It is defined as the percentage of pages found in blocks of size * less than 1 << order. It returns values in range [0, 100]. */ -int extfrag_for_order (struct zone *zone,unsigned int order) +unsigned int extfrag_for_order (struct zone *zone,unsigned int order) {struct contig_page_info info;
Signature · 1 line
2.27.0
Quoted 37 lines · Nitin Gupta
Proactive compaction uses per-node/zone "fragmentation score" which is always in range [0, 100], so use unsigned type of these scores as well as for related constants.
Signed-off-by Nitin Gupta <[email protected]>--- include/linux/compaction.h | 4 ++-- kernel/sysctl.c | 2 +- mm/compaction.c | 18 +++++++++--------- mm/vmstat.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)include/linux/compaction.h +2
-2@@ -85,13 +85,13 @@ static inline unsigned long compact_gap(unsigned int order)#ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; -extern int sysctl_compaction_proactiveness; +extern unsigned int sysctl_compaction_proactiveness;extern int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos);extern int sysctl_extfrag_threshold;extern int sysctl_compact_unevictable_allowed; -extern int extfrag_for_order (struct zone *zone,unsigned int order); +extern unsigned int extfrag_for_order (struct zone *zone,unsigned int order);extern int fragmentation_index (struct zone *zone,unsigned int order); extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags,kernel/sysctl.c +0
-0
kernel/sysctl.c static struct ctl_table vm_table[] = { · line 2836
Quoted 5 lines
kernel/sysctl.c +1
-1@@ -2833,7 +2833,7 @@ static struct ctl_table vm_table[] = { { .procname = "compaction_proactiveness", .data = &sysctl_compaction_proactiveness, - .maxlen = sizeof(int), + .maxlen = sizeof(sysctl_compaction_proactiveness),
Patch looks good to me. Wondering why not using 'unsigned int' here, just curious.
Quoted 85 lines
kernel/sysctl.c +0
-0.mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO,mm/compaction.c +9
-9@@ -53,7 +53,7 @@ static inline void count_compact_events(enum vm_event_item item, long delta)/* * Fragmentation score check interval for proactive compaction purposes. */ -static const int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ; +static const unsigned int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ;/* * Page order with-respect-to which proactive compaction @@ -1890,7 +1890,7 @@ static bool kswapd_is_running(pg_data_t *pgdat)* ZONE_DMA32. For smaller zones, the score value remains close to zero, * and thus never exceeds the high threshold for proactive compaction. */ -static int fragmentation_score_zone (struct zone *zone) +static unsigned int fragmentation_score_zone (struct zone *zone) {unsigned long score;@@ -1906,9 +1906,9 @@ static int fragmentation_score_zone(struct zone *zone)* the node's score falls below the low threshold, or one of the back-off * conditions is met. */ -static int fragmentation_score_node (pg_data_t *pgdat) +static unsigned int fragmentation_score_node (pg_data_t *pgdat) { -unsigned long score =0 ; +unsigned int score =0 ;int zoneid;for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {@@ -1921,17 +1921,17 @@ static int fragmentation_score_node(pg_data_t *pgdat)return score; } -static int fragmentation_score_wmark (pg_data_t *pgdat,bool low) +static unsigned int fragmentation_score_wmark (pg_data_t *pgdat,bool low) { -int wmark_low; +unsigned int wmark_low;/* * Cap the low watermak to avoid excessive compaction * activity in case a user sets the proactivess tunable * close to 100 (maximum). */ - wmark_low =max (100 - sysctl_compaction_proactiveness,5 ); -return low ? wmark_low :min (wmark_low +10 ,100 ); + wmark_low =max (100U - sysctl_compaction_proactiveness,5U ); +return low ? wmark_low :min (wmark_low +10 ,100U ); }static bool should_proactive_compact_node (pg_data_t *pgdat)@@ -2604,7 +2604,7 @@ int sysctl_compact_memory;* aggressively the kernel should compact memory in the * background. It takes values in the range [0, 100]. */ -int __read_mostly sysctl_compaction_proactiveness =20 ; +unsigned int __read_mostly sysctl_compaction_proactiveness =20 ;/* * This is the entry point for compacting all nodes via mm/vmstat.c +1
-1@@ -1079,7 +1079,7 @@ static int __fragmentation_index(unsigned int order, struct contig_page_info *in* It is defined as the percentage of pages found in blocks of size * less than 1 << order. It returns values in range [0, 100]. */ -int extfrag_for_order (struct zone *zone,unsigned int order) +unsigned int extfrag_for_order (struct zone *zone,unsigned int order) {struct contig_page_info info;Signature · 1 line
2.27.0
Quoted 38 lines · Baoquan He
Quoted 37 lines · Nitin Gupta
Proactive compaction uses per-node/zone "fragmentation score" which is always in range [0, 100], so use unsigned type of these scores as well as for related constants.
Signed-off-by Nitin Gupta <[email protected]>--- include/linux/compaction.h | 4 ++-- kernel/sysctl.c | 2 +- mm/compaction.c | 18 +++++++++--------- mm/vmstat.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)include/linux/compaction.h +2
-2@@ -85,13 +85,13 @@ static inline unsigned long compact_gap(unsigned int order)#ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; -extern int sysctl_compaction_proactiveness; +extern unsigned int sysctl_compaction_proactiveness;extern int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos);extern int sysctl_extfrag_threshold;extern int sysctl_compact_unevictable_allowed; -extern int extfrag_for_order (struct zone *zone,unsigned int order); +extern unsigned int extfrag_for_order (struct zone *zone,unsigned int order);extern int fragmentation_index (struct zone *zone,unsigned int order); extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags,kernel/sysctl.c +0
-0@@ -2833,7 +2833,7 @@ static struct ctl_table vm_table[] = {
Quoted 9 lines
kernel/sysctl.c static struct ctl_table vm_table[] = { · line 2836
Quoted 5 lines
kernel/sysctl.c +1
-1{ .procname = "compaction_proactiveness", .data = &sysctl_compaction_proactiveness, - .maxlen = sizeof(int), + .maxlen = sizeof(sysctl_compaction_proactiveness),Patch looks good to me. Wondering why not using 'unsigned int' here, just curious.
It's just coding style preference. I see the same style used for many other sysctls too (min_free_kbytes etc.).
Thanks,
Nitin
Quoted 5 lines · Nitin Gupta
Proactive compaction uses per-node/zone "fragmentation score" which is always in range [0, 100], so use unsigned type of these scores as well as for related constants.
Signed-off-by Nitin Gupta <[email protected]>
Quoted 122 lines
--- include/linux/compaction.h | 4 ++-- kernel/sysctl.c | 2 +- mm/compaction.c | 18 +++++++++--------- mm/vmstat.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-)include/linux/compaction.h +2
-2@@ -85,13 +85,13 @@ static inline unsigned long compact_gap(unsigned int order)#ifdef CONFIG_COMPACTION extern int sysctl_compact_memory; -extern int sysctl_compaction_proactiveness; +extern unsigned int sysctl_compaction_proactiveness;extern int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos);extern int sysctl_extfrag_threshold;extern int sysctl_compact_unevictable_allowed; -extern int extfrag_for_order (struct zone *zone,unsigned int order); +extern unsigned int extfrag_for_order (struct zone *zone,unsigned int order);extern int fragmentation_index (struct zone *zone,unsigned int order); extern enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order, unsigned int alloc_flags,kernel/sysctl.c +1
-1@@ -2833,7 +2833,7 @@ static struct ctl_table vm_table[] = { { .procname = "compaction_proactiveness", .data = &sysctl_compaction_proactiveness, - .maxlen = sizeof(int), + .maxlen = sizeof(sysctl_compaction_proactiveness), .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO,mm/compaction.c +9
-9@@ -53,7 +53,7 @@ static inline void count_compact_events(enum vm_event_item item, long delta)/* * Fragmentation score check interval for proactive compaction purposes. */ -static const int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ; +static const unsigned int HPAGE_FRAG_CHECK_INTERVAL_MSEC =500 ;/* * Page order with-respect-to which proactive compaction @@ -1890,7 +1890,7 @@ static bool kswapd_is_running(pg_data_t *pgdat)* ZONE_DMA32. For smaller zones, the score value remains close to zero, * and thus never exceeds the high threshold for proactive compaction. */ -static int fragmentation_score_zone (struct zone *zone) +static unsigned int fragmentation_score_zone (struct zone *zone) {unsigned long score;@@ -1906,9 +1906,9 @@ static int fragmentation_score_zone(struct zone *zone)* the node's score falls below the low threshold, or one of the back-off * conditions is met. */ -static int fragmentation_score_node (pg_data_t *pgdat) +static unsigned int fragmentation_score_node (pg_data_t *pgdat) { -unsigned long score =0 ; +unsigned int score =0 ;int zoneid;for (zoneid =0 ; zoneid <MAX_NR_ZONES ; zoneid++) {@@ -1921,17 +1921,17 @@ static int fragmentation_score_node(pg_data_t *pgdat)return score; } -static int fragmentation_score_wmark (pg_data_t *pgdat,bool low) +static unsigned int fragmentation_score_wmark (pg_data_t *pgdat,bool low) { -int wmark_low; +unsigned int wmark_low;/* * Cap the low watermak to avoid excessive compaction * activity in case a user sets the proactivess tunable * close to 100 (maximum). */ - wmark_low =max (100 - sysctl_compaction_proactiveness,5 ); -return low ? wmark_low :min (wmark_low +10 ,100 ); + wmark_low =max (100U - sysctl_compaction_proactiveness,5U ); +return low ? wmark_low :min (wmark_low +10 ,100U ); }static bool should_proactive_compact_node (pg_data_t *pgdat)@@ -2604,7 +2604,7 @@ int sysctl_compact_memory;* aggressively the kernel should compact memory in the * background. It takes values in the range [0, 100]. */ -int __read_mostly sysctl_compaction_proactiveness =20 ; +unsigned int __read_mostly sysctl_compaction_proactiveness =20 ;/* * This is the entry point for compacting all nodes via mm/vmstat.c +1
-1@@ -1079,7 +1079,7 @@ static int __fragmentation_index(unsigned int order, struct contig_page_info *in* It is defined as the percentage of pages found in blocks of size * less than 1 << order. It returns values in range [0, 100]. */ -int extfrag_for_order (struct zone *zone,unsigned int order) +unsigned int extfrag_for_order (struct zone *zone,unsigned int order) {struct contig_page_info info;Signature · 1 line
2.27.0