• Eric Paris's avatar
    [PATCH] hugetlb: fix race in set_max_huge_pages for multiple updaters of nr_huge_pages · 0bd0f9fb
    Eric Paris authored
    If there are multiple updaters to /proc/sys/vm/nr_hugepages simultaneously
    it is possible for the nr_huge_pages variable to become incorrect.  There
    is no locking in the set_max_huge_pages function around
    alloc_fresh_huge_page which is able to update nr_huge_pages.  Two callers
    to alloc_fresh_huge_page could race against each other as could a call to
    alloc_fresh_huge_page and a call to update_and_free_page.  This patch just
    expands the area covered by the hugetlb_lock to cover the call into
    alloc_fresh_huge_page.  I'm not sure how we could say that a sysctl section
    is performance critical where more specific locking would be needed.
    
    My reproducer was to run a couple copies of the following script
    simultaneously
    
    while [ true ]; do
    	echo 1000 > /proc/sys/vm/nr_hugepages
    	echo 500 > /proc/sys/vm/nr_hugepages
    	echo 750 > /proc/sys/vm/nr_hugepages
    	echo 100 > /proc/sys/vm/nr_hugepages
    	echo 0 > /proc/sys/vm/nr_hugepages
    do...
    0bd0f9fb
hugetlb.c 10.9 KB