mm: compaction: limit illegal input parameters of compact_memory interface
Subsystems (3)
PATCH v3 2/2 mm: compaction: limit illegal input parameters of compact_memory interface
From: Minghao Chi <[email protected]>
Available only when CONFIG_COMPACTION is set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter > compact_memory, this function will be triggered by writing parameters to the interface.
Applied this patch,
sh/$ echo 1.1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argument
--- mm/compaction.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/compaction.c +9 -1
@@ -2762,15 +2762,18 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,return 0 ; } +static int sysctl_compact_memory;#ifdef CONFIG_SYSCTL static struct ctl_table vm_compact_memory[] = { { .procname ="compact_memory" , - .data =NULL , + .data = &sysctl_compact_memory, .maxlen =sizeof (int ), .mode =0200 , .proc_handler = sysctl_compaction_handler, + .extra1 =SYSCTL_ONE , + .extra2 =SYSCTL_ONE , }, { } };
@@ -2782,6 +2785,11 @@ static struct ctl_table vm_compact_memory[] = {int sysctl_compaction_handler (struct ctl_table *table,int write,void *buffer,size_t *length,loff_t *ppos) { +int ret; + + ret =proc_dointvec_minmax (table, write, buffer, length, ppos); +if (ret) +return ret;if (write)compact_nodes ();
Signature · 1 line
2.25.1
Quoted 11 lines · On Thu, Mar 09, 2023 at 11:42:58AM +0800, [email protected] wrote:
From: Minghao Chi <[email protected]>
Available only when
CONFIG_COMPACTIONis set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter >compact_memory, this function will be triggered by writing parameters to the interface.Applied this patch,
sh/$ echo 1.1 >/proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argument
Didn't echo 2 > /proc/sys/vm/compact_memory used to work too?
Why kill that? Did the docs say only 1 was possible? If not perhaps the docs need to be updated?
Luis
Actually, it seems odd to use a min setting and configure it to map to SYSCTL_ONE to SYSCTL_ONE so just a SYCTL_$(type)_MAX or just the type max would be better and not break old userspace.
Quoted 21 lines · Luis Chamberlain
Quoted 11 lines · On Thu, Mar 09, 2023 at 11:42:58AM +0800, [email protected] wrote:
From: Minghao Chi <[email protected]>
Available only when
CONFIG_COMPACTIONis set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter >compact_memory, this function will be triggered by writing parameters to the interface.Applied this patch,
sh/$ echo 1.1 >/proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argumentDidn't echo 2 >
/proc/sys/vm/compact_memoryused to work too?Why kill that? Did the docs say only 1 was possible? If not perhaps the docs need to be updated?
Luis
Quoted 8 lines
Quoted 8 lines
From: Minghao Chi <[email protected]>
Available only when
CONFIG_COMPACTIONis set. When 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
But echo others-parameter >compact_memory, this function will be triggered by writing parameters to the interface.
Quoted 5 lines
Quoted 3 lines
Applied this patch,
sh/$ echo 1.1 >/proc/sys/vm/compact_memory
sh/$ sh: write error: Invalid argumentDidn't echo 2 >
/proc/sys/vm/compact_memoryused to work too?
yes
Quoted 3 lines
Why kill that? Did the docs say only 1 was possible? If not perhaps the docs need to be updated?
In Documentation/admin-guide/sysctl/vm.rst:109 say: when 1 is written to the file, all zones are compacted such that free memory is available in contiguous blocks where possible.
So limit the value of interface compact_memory to 1.
Chi, and Ye