On Sat, 10 May 2014 00:16:48 +0800 Jianyu Zhan <nasa4...@gmail.com> wrote:

> mlocked_vma_newpage() is only called in fault path by
> page_add_new_anon_rmap(), which is called on a *new* page.
> And such page is initially only visible via the pagetables, and the
> pte is locked while calling page_add_new_anon_rmap(), so we need not
> use an irq-safe mod_zone_page_state() here, using a light-weight version
> __mod_zone_page_state() would be OK.
> 
> ...
>
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -196,7 +196,7 @@ static inline int mlocked_vma_newpage(struct 
> vm_area_struct *vma,
>               return 0;
>  
>       if (!TestSetPageMlocked(page)) {
> -             mod_zone_page_state(page_zone(page), NR_MLOCK,
> +             __mod_zone_page_state(page_zone(page), NR_MLOCK,
>                                   hpage_nr_pages(page));
>               count_vm_event(UNEVICTABLE_PGMLOCKED);
>       }

The comment over __mod_zone_page_state() says "For use when we know
that interrupts are disabled".  But that is not the case here.

Please fix this up, probably by altering the __mod_zone_page_state()
documentation.


Your proposed change to (the very poorly named) mlocked_vma_newpage()
makes that function more dangerous - people might add new callsites
without knowing that they're adding races.  This risk can be reduced by

a) adding documentation explaining why __mod_zone_page_state() is
   used and why it is safe and

b) moving mlocked_vma_newpage() out of internal.h and placing it in
   mm/rmap.c immediately before page_add_new_anon_rmap().  Or, probably
   better, by removing mlocked_vma_newpage() altogether and open-coding
   its logic into page_add_new_anon_rmap().


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to