Skip to contentSkip to conversation

mm/compaction: remove unused variable sysctl_compact_memory

PATCH Superseded Pintu Kumar 4 participants 9 messages Mar 2, 2021 – Mar 4, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/compaction: remove unused variable sysctl_compact_memory

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

---
 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 1 +
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 4 deletions(-)
include/linux/compaction.h +0 -1
index ed4070e..4221888 100644
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 }
 
 #ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
 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);
kernel/sysctl.c +1 -0
index c9fbdd8..66aff21 100644
@@ -198,6 +198,7 @@ static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
 #ifdef CONFIG_COMPACTION
 static int min_extfrag_threshold;
 static int max_extfrag_threshold = 1000;
+static int sysctl_compact_memory;
 #endif
 
 #endif /* CONFIG_SYSCTL */
mm/compaction.c +0 -3
index 190ccda..ede2886 100644
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
 		compact_node(nid);
 }
 
-/* The written value is actually unused, all memory is compacted */
-int sysctl_compact_memory;
-
 /*
  * Tunable for proactive compaction. It determines how
  * aggressively the kernel should compact memory in the
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
#1 lore raw
Quoted 19 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pintu Kumar
Sent: Tuesday, March 2, 2021 9:56 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nitin Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] mm/compaction: remove unused variable sysctl_compact_memory

External email: Use caution opening links or attachments

Quoted 6 lines

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file.

I prefer keeping the existing pattern of listing all compaction related tunables together in compaction.h:

	extern int sysctl_compact_memory;
	extern unsigned int sysctl_compaction_proactiveness;
	extern int sysctl_extfrag_threshold;
	extern int sysctl_compact_unevictable_allowed;
Quoted 37 lines

No functionality is broken or changed this way.

---
 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 1 +
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 4 deletions(-)
include/linux/compaction.h index renamed from include/linux/compaction.h +0 -0

ed4070e..4221888 100644

include/linux/compaction.h +0 -1
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned int
 order)  }
 
 #ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
 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); diff --git

a/kernel/sysctl.c b/kernel/sysctl.c index c9fbdd8..66aff21 100644

kernel/sysctl.c +0 -0
@@ -198,6 +198,7 @@ static int max_sched_tunable_scaling =

SCHED_TUNABLESCALING_END-1; #ifdef CONFIG_COMPACTION static int min_extfrag_threshold; static int max_extfrag_threshold = 1000;

kernel/sysctl.c +1 -0
+static int sysctl_compact_memory;
 #endif
 
 #endif /* CONFIG_SYSCTL */
mm/compaction.c index 190ccda..ede2886 renamed from mm/compaction.c +0 -0

100644

mm/compaction.c static void compact_nodes(void) · line 2655

Quoted 6 lines
mm/compaction.c +0 -2
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
                compact_node(nid);
 }
 
-/* The written value is actually unused, all memory is compacted */ -int
 sysctl_compact_memory;
-

Please retain this comment for the tunable.

-Nitin

#2 lore raw
Quoted 25 lines · Nitin Gupta
Quoted 17 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pintu Kumar
Sent: Tuesday, March 2, 2021 9:56 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nitin Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] mm/compaction: remove unused variable sysctl_compact_memory

External email: Use caution opening links or attachments

Quoted 6 lines

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file.

Quoted 8 lines

I prefer keeping the existing pattern of listing all compaction related tunables together in compaction.h:

	extern int sysctl_compact_memory;
	extern unsigned int sysctl_compaction_proactiveness;
	extern int sysctl_extfrag_threshold;
	extern int sysctl_compact_unevictable_allowed;

Thanks Nitin for your review.
You mean, you just wanted to retain this extern declaration ? Any real benefit of keeping this declaration if not used elsewhere ?

Quoted 42 lines
Quoted 42 lines

No functionality is broken or changed this way.

---
 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 1 +
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 4 deletions(-)
include/linux/compaction.h index renamed from include/linux/compaction.h +0 -0

ed4070e..4221888 100644

include/linux/compaction.h +0 -1
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned int
 order)  }
 
 #ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
 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); 

diff --git
a/kernel/sysctl.c b/kernel/sysctl.c index c9fbdd8..66aff21 100644

kernel/sysctl.c +0 -0
@@ -198,6 +198,7 @@ static int max_sched_tunable_scaling =

SCHED_TUNABLESCALING_END-1; #ifdef CONFIG_COMPACTION static int min_extfrag_threshold; static int max_extfrag_threshold = 1000;

kernel/sysctl.c +1 -0
+static int sysctl_compact_memory;
 #endif
 
 #endif /* CONFIG_SYSCTL */
mm/compaction.c index 190ccda..ede2886 renamed from mm/compaction.c +0 -0

100644

mm/compaction.c +0 -0
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
                compact_node(nid);
 }
 
Quoted 7 lines

mm/compaction.c static void compact_nodes(void) · line 2655

Quoted 4 lines
mm/compaction.c +0 -3
-/* The written value is actually unused, all memory is compacted */ 
-int
 sysctl_compact_memory;
-

Please retain this comment for the tunable.

Sorry, I could not understand.
You mean to say just retain this last comment and only remove the variable ? Again any real benefit you see in retaining this even if its not used?

Thanks,
Pintu

#3 lore raw
Quoted 54 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, March 3, 2021 6:34 AM
To: Nitin Gupta <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] mm/compaction: remove unused variable sysctl_compact_memory

External email: Use caution opening links or attachments

Quoted 7 lines · Nitin Gupta
Quoted 7 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Pintu Kumar
Sent: Tuesday, March 2, 2021 9:56 AM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected];

[email protected];

Quoted 18 lines
Quoted 10 lines

[email protected]; Nitin Gupta <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] mm/compaction: remove unused variable sysctl_compact_memory

External email: Use caution opening links or attachments

Quoted 6 lines

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file.

Quoted 8 lines

I prefer keeping the existing pattern of listing all compaction related tunables together in compaction.h:

      extern int sysctl_compact_memory;
      extern unsigned int sysctl_compaction_proactiveness;
      extern int sysctl_extfrag_threshold;
      extern int sysctl_compact_unevictable_allowed;
Quoted 4 lines

Thanks Nitin for your review.
You mean, you just wanted to retain this extern declaration ? Any real benefit of keeping this declaration if not used elsewhere ?

I see that sysctl_compaction_handler() doesn't use the sysctl value at all. So, we can get rid of it completely as Vlastimil suggested.

Quoted 52 lines
Quoted 35 lines
Quoted 35 lines

No functionality is broken or changed this way.

---
 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 1 +
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 4 deletions(-)
include/linux/compaction.h +0 -0

index
ed4070e..4221888 100644

include/linux/compaction.h +0 -0
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned

int
order) }

#ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
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);
kernel/sysctl.c index c9fbdd8..66aff21 renamed from kernel/sysctl.c +0 -0

100644

kernel/sysctl.c +0 -0
@@ -198,6 +198,7 @@ static int max_sched_tunable_scaling =

SCHED_TUNABLESCALING_END-1; #ifdef CONFIG_COMPACTION static int min_extfrag_threshold; static int max_extfrag_threshold = 1000; +static int sysctl_compact_memory;
#endif

Quoted 2 lines

mm/compaction.c index

Quoted 2 lines

#endif /* CONFIG_SYSCTL */

mm/compaction.c index renamed from mm/compaction.c +0 -0

190ccda..ede2886

Quoted 7 lines
Quoted 7 lines

100644

mm/compaction.c +0 -0
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
                compact_node(nid);
 }
 
Quoted 6 lines

mm/compaction.c static void compact_nodes(void) · line 2655

Quoted 3 lines
mm/compaction.c +0 -3
-/* The written value is actually unused, all memory is compacted */
-int sysctl_compact_memory;
-

Please retain this comment for the tunable.

Quoted 6 lines

Sorry, I could not understand.
You mean to say just retain this last comment and only remove the variable ?
Again any real benefit you see in retaining this even if its not used?

You are just moving declaration of sysctl_compact_memory from compaction.c to sysctl.c. So, I wanted the comment "... all memory is compacted" to be retained with the sysctl variable. Since you are now getting rid of this variable completely, this comment goes away too.

Thanks,
Nitin

#4 lore raw
In reply to Pintu Kumar
Quoted 10 lines · Pintu Kumar

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

You need to specify the first commit which added sysctl_compact_memory variable and if exists the last commit which removed the last access of the same variable in the file mm/compaction.c in for completeness of the commit log.

#5 lore raw
In reply to Pintu Kumar
Quoted 10 lines · Pintu Kumar

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

You should be able to remove the variable completely and set .data to NULL in the corresponding entry. The sysctl_compaction_handler doesn't access it at all.

Then you could do the same with drop_caches. Currently drop_caches_sysctl_handler currently writes to it, but that can be avoided using a local variable - see how sysrq_sysctl_handler avoids the global variable and its corresponding .data field is NULL.

Vlastimil

#6 lore raw
Quoted 12 lines · Vlastimil Babka
Quoted 10 lines · Pintu Kumar

The sysctl_compact_memory is mostly unsed in mm/compaction.c It just acts as a place holder for sysctl.

Thus we can remove it from here and move the declaration directly in kernel/sysctl.c itself.
This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

Quoted 8 lines

You should be able to remove the variable completely and set .data to NULL in the corresponding entry. The sysctl_compaction_handler doesn't access it at all.

Then you could do the same with drop_caches. Currently drop_caches_sysctl_handler currently writes to it, but that can be avoided using a local variable - see how sysrq_sysctl_handler avoids the global variable and its corresponding .data field is NULL.

Oh yes, thank you so much for the reference.
Yes I was looking to do something similar but didn't realize that is possible. I will re-submit the new patch.

And yes, I will try to explore more on drop_caches part as well.

Thanks,
Pintu

#7 lore raw

PATCH v2 1/1 mm/compaction: remove unused variable sysctl_compact_memory

The sysctl_compact_memory is mostly unused in mm/compaction.c It just acts as a place holder for sysctl to store .data.

But the .data itself is not needed here.
So we can get ride of this variable completely and make .data as NULL. This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

---
v2: completely get rid of this variable and set .data to NULL

 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 2 +-
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 5 deletions(-)
include/linux/compaction.h +0 -1
index ed4070e..4221888 100644
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 }
 
 #ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
 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);
kernel/sysctl.c +1 -1
index c9fbdd8..07ef240 100644
@@ -2856,7 +2856,7 @@ static struct ctl_table vm_table[] = {
 #ifdef CONFIG_COMPACTION
 	{
 		.procname	= "compact_memory",
-		.data		= &sysctl_compact_memory,
+		.data		= NULL,
 		.maxlen		= sizeof(int),
 		.mode		= 0200,
 		.proc_handler	= sysctl_compaction_handler,
mm/compaction.c +0 -3
index 190ccda..ede2886 100644
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
 		compact_node(nid);
 }
 
-/* The written value is actually unused, all memory is compacted */
-int sysctl_compact_memory;
-
 /*
  * Tunable for proactive compaction. It determines how
  * aggressively the kernel should compact memory in the
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.
Reviewed-by on v2 1/1
#8 lore raw
Quoted 10 lines · Pintu Kumar

The sysctl_compact_memory is mostly unused in mm/compaction.c It just acts as a place holder for sysctl to store .data.

But the .data itself is not needed here.
So we can get ride of this variable completely and make .data as NULL. This will also eliminate the extern declaration from header file. No functionality is broken or changed this way.

Quoted 49 lines

---
v2: completely get rid of this variable and set .data to NULL

 include/linux/compaction.h | 1 -
 kernel/sysctl.c            | 2 +-
 mm/compaction.c            | 3 ---
 3 files changed, 1 insertion(+), 5 deletions(-)
include/linux/compaction.h +0 -1
index ed4070e..4221888 100644
@@ -81,7 +81,6 @@ static inline unsigned long compact_gap(unsigned int order)
 }
 
 #ifdef CONFIG_COMPACTION
-extern int sysctl_compact_memory;
 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);
kernel/sysctl.c +1 -1
index c9fbdd8..07ef240 100644
@@ -2856,7 +2856,7 @@ static struct ctl_table vm_table[] = {
 #ifdef CONFIG_COMPACTION
 	{
 		.procname	= "compact_memory",
-		.data		= &sysctl_compact_memory,
+		.data		= NULL,
 		.maxlen		= sizeof(int),
 		.mode		= 0200,
 		.proc_handler	= sysctl_compaction_handler,
mm/compaction.c +0 -3
index 190ccda..ede2886 100644
@@ -2650,9 +2650,6 @@ static void compact_nodes(void)
 		compact_node(nid);
 }
 
-/* The written value is actually unused, all memory is compacted */
-int sysctl_compact_memory;
-
 /*
  * Tunable for proactive compaction. It determines how
  * aggressively the kernel should compact memory in the