Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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().

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Acked-by: Adam Litke <agl@us.ibm.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: William Lee Irwin III <wli@holomorphy.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Nishanth Aravamudan and committed by
Linus Torvalds
a3d0c6aa ac74c00e

+12 -1
+1
include/linux/hugetlb.h
··· 17 17 } 18 18 19 19 int hugetlb_sysctl_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *); 20 + int hugetlb_overcommit_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *); 20 21 int hugetlb_treat_movable_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *); 21 22 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *); 22 23 int follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, struct vm_area_struct **, unsigned long *, int *, int, int);
+1 -1
kernel/sysctl.c
··· 982 982 .data = &nr_overcommit_huge_pages, 983 983 .maxlen = sizeof(nr_overcommit_huge_pages), 984 984 .mode = 0644, 985 - .proc_handler = &proc_doulongvec_minmax, 985 + .proc_handler = &hugetlb_overcommit_handler, 986 986 }, 987 987 #endif 988 988 {
+10
mm/hugetlb.c
··· 605 605 return 0; 606 606 } 607 607 608 + int hugetlb_overcommit_handler(struct ctl_table *table, int write, 609 + struct file *file, void __user *buffer, 610 + size_t *length, loff_t *ppos) 611 + { 612 + spin_lock(&hugetlb_lock); 613 + proc_doulongvec_minmax(table, write, file, buffer, length, ppos); 614 + spin_unlock(&hugetlb_lock); 615 + return 0; 616 + } 617 + 608 618 #endif /* CONFIG_SYSCTL */ 609 619 610 620 int hugetlb_report_meminfo(char *buf)