Re: [PATCHv6 27/36] mm: differentiate page_mapped() from page_mapcount() for compound pages
From: Kirill A. Shutemov
Date: Tue Jun 09 2015 - 07:00:29 EST
On Wed, Jun 03, 2015 at 08:05:58PM +0300, Kirill A. Shutemov wrote:
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 22cd540104ec..16add6692f49 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -917,10 +917,21 @@ static inline pgoff_t page_file_index(struct page *page)
>
> /*
> * Return true if this page is mapped into pagetables.
> + * For compound page it returns true if any subpage of compound page is mapped.
> */
> -static inline int page_mapped(struct page *page)
> +static inline bool page_mapped(struct page *page)
> {
> - return atomic_read(&(page)->_mapcount) + compound_mapcount(page) >= 0;
> + int i;
> + if (likely(!PageCompound(page)))
> + return atomic_read(&page->_mapcount) >= 0;
> + page = compound_head(page);
> + if (compound_mapcount(page))
> + return true;
> + for (i = 0; i < hpage_nr_pages(page); i++) {
> + if (atomic_read(&page[i]._mapcount) >= 0)
> + return true;
> + }
> + return true;
Oops. 'false' should be here. Updated patch is below.