hugetlb: add locking for overcommit sysctl
Subsystems (3)
PATCH 1/1 hugetlb: add locking for overcommit sysctl
When I replaced hugetlb_dynamic_pool with nr_overcommit_hugepages I used proc_doulongvec_minmax() directly. However, hugetlb.c's locking rules require that all counter modifications occur under the hugetlb_lock. Add a callback into the hugetlb code similar to the one for nr_hugepages. Grab the lock around the manipulation of nr_overcommit_hugepages in proc_doulongvec_minmax().
---
I noticed that the nr_hugepages sysctl uses a helper variable, max_huge_pages to do the same thing. Is that because of locking requirements (undocmented) for proc_doulongvec_minmax() or because of the more complicated manipulation of the pool state for that sysctl? If the former, I will need to modify this patch.
include/linux/hugetlb.h +1 -0
@@ -17,6 +17,7 @@ static inline int is_vm_hugetlb_page(struct vm_area_struct *vma) }int hugetlb_sysctl_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); +int hugetlb_overcommit_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int hugetlb_treat_movable_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *);int follow_hugetlb_page (struct mm_struct *,struct vm_area_struct *,struct page **,struct vm_area_struct **,unsigned long *,int *,int ,int );
kernel/sysctl.c +1 -1
@@ -973,7 +973,7 @@ static struct ctl_table vm_table[] = { .data = &nr_overcommit_huge_pages, .maxlen = sizeof(nr_overcommit_huge_pages), .mode = 0644, - .proc_handler = &proc_doulongvec_minmax, + .proc_handler = &hugetlb_overcommit_handler, },#endif {
mm/hugetlb.c +10 -0
@@ -605,6 +605,16 @@ int hugetlb_treat_movable_handler(struct ctl_table *table, int write, return 0; } +int hugetlb_overcommit_handler (struct ctl_table *table,int write, +struct file *file,void __user *buffer, +size_t *length,loff_t *ppos) +{ +spin_lock (&hugetlb_lock); +proc_doulongvec_minmax (table, write, file, buffer, length, ppos); +spin_unlock (&hugetlb_lock); +return 0 ; +} +#endif /* CONFIG_SYSCTL */ int hugetlb_report_meminfo (char *buf)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Nishanth Aravamudan
When I replaced
hugetlb_dynamic_poolwithnr_overcommit_hugepagesI usedproc_doulongvec_minmax()directly. However, hugetlb.c's locking rules require that all counter modifications occur under thehugetlb_lock. Add a callback into the hugetlb code similar to the one fornr_hugepages. Grab the lock around the manipulation ofnr_overcommit_hugepagesinproc_doulongvec_minmax().Signed-off-by Nishanth Aravamudan <[email protected]>
Quoted 54 lines
---
I noticed that thenr_hugepagessysctl uses a helper variable,max_huge_pagesto do the same thing. Is that because of locking requirements (undocmented) forproc_doulongvec_minmax()or because of the more complicated manipulation of the pool state for that sysctl? If the former, I will need to modify this patch.include/linux/hugetlb.h +1
-0@@ -17,6 +17,7 @@ static inline int is_vm_hugetlb_page(struct vm_area_struct *vma) }int hugetlb_sysctl_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); +int hugetlb_overcommit_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int hugetlb_treat_movable_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *);int follow_hugetlb_page (struct mm_struct *,struct vm_area_struct *,struct page **,struct vm_area_struct **,unsigned long *,int *,int ,int );kernel/sysctl.c +1
-1@@ -973,7 +973,7 @@ static struct ctl_table vm_table[] = { .data = &nr_overcommit_huge_pages, .maxlen = sizeof(nr_overcommit_huge_pages), .mode = 0644, - .proc_handler = &proc_doulongvec_minmax, + .proc_handler = &hugetlb_overcommit_handler, },#endif {mm/hugetlb.c +10
-0@@ -605,6 +605,16 @@ int hugetlb_treat_movable_handler(struct ctl_table *table, int write, return 0; } +int hugetlb_overcommit_handler (struct ctl_table *table,int write, +struct file *file,void __user *buffer, +size_t *length,loff_t *ppos) +{ +spin_lock (&hugetlb_lock); +proc_doulongvec_minmax (table, write, file, buffer, length, ppos); +spin_unlock (&hugetlb_lock); +return 0 ; +} +#endif /* CONFIG_SYSCTL */ int hugetlb_report_meminfo (char *buf)
Signature · 8 lines
Adam Litke - (agl at us.ibm.com) IBM Linux Technology Center -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · Adam Litke
Quoted 8 lines · Nishanth Aravamudan
When I replaced
hugetlb_dynamic_poolwithnr_overcommit_hugepagesI usedproc_doulongvec_minmax()directly. However, hugetlb.c's locking rules require that all counter modifications occur under thehugetlb_lock. Add a callback into the hugetlb code similar to the one fornr_hugepages. Grab the lock around the manipulation ofnr_overcommit_hugepagesinproc_doulongvec_minmax().Signed-off-by Nishanth Aravamudan <[email protected]>Acked-by Adam Litke <[email protected]>
Thanks, Adam.
Andrew, this is a bugfix for 2.6.25 and presumably should be backported to -stable once upstream (I'll keep my eye out for the commit message if it goes there).
Quoted 58 lines
Quoted 54 lines
---
I noticed that thenr_hugepagessysctl uses a helper variable,max_huge_pagesto do the same thing. Is that because of locking requirements (undocmented) forproc_doulongvec_minmax()or because of the more complicated manipulation of the pool state for that sysctl? If the former, I will need to modify this patch.include/linux/hugetlb.h +1
-0@@ -17,6 +17,7 @@ static inline int is_vm_hugetlb_page(struct vm_area_struct *vma) }int hugetlb_sysctl_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); +int hugetlb_overcommit_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int hugetlb_treat_movable_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *);int follow_hugetlb_page (struct mm_struct *,struct vm_area_struct *,struct page **,struct vm_area_struct **,unsigned long *,int *,int ,int );kernel/sysctl.c +1
-1@@ -973,7 +973,7 @@ static struct ctl_table vm_table[] = { .data = &nr_overcommit_huge_pages, .maxlen = sizeof(nr_overcommit_huge_pages), .mode = 0644, - .proc_handler = &proc_doulongvec_minmax, + .proc_handler = &hugetlb_overcommit_handler, },#endif {mm/hugetlb.c +10
-0@@ -605,6 +605,16 @@ int hugetlb_treat_movable_handler(struct ctl_table *table, int write, return 0; } +int hugetlb_overcommit_handler (struct ctl_table *table,int write, +struct file *file,void __user *buffer, +size_t *length,loff_t *ppos) +{ +spin_lock (&hugetlb_lock); +proc_doulongvec_minmax (table, write, file, buffer, length, ppos); +spin_unlock (&hugetlb_lock); +return 0 ; +} +#endif /* CONFIG_SYSCTL */ int hugetlb_report_meminfo (char *buf)Signature · 2 lines
Adam Litke - (agl at us.ibm.com) IBM Linux Technology Center
Signature · 8 lines
Nishanth Aravamudan <[email protected]> IBM Linux Technology Center -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>