All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ning Qu <quning@google.com>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Hugh Dickins <hughd@google.com>,
	Wu Fengguang <fengguang.wu@intel.com>, Jan Kara <jack@suse.cz>,
	Mel Gorman <mgorman@suse.de>,
	linux-mm@kvack.org, Andi Kleen <ak@linux.intel.com>,
	Matthew Wilcox <willy@linux.intel.com>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	Hillf Danton <dhillf@gmail.com>, Dave Hansen <dave@sr71.net>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 20/23] thp: handle file pages in split_huge_page()
Date: Tue, 6 Aug 2013 14:47:43 -0700	[thread overview]
Message-ID: <CACz4_2fv1g2dRLh72gtaCYkNC6+Pp4h=R0q-taR51tejpL1gnw@mail.gmail.com> (raw)
In-Reply-To: <CACz4_2de=zm2-VtE=dFTfYjrdma4QFX1S-ukQ_7J4DZ32q1JQQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 10695 bytes --]

I just tried, and it seems working fine now without the deadlock anymore. I
can run some big internal test with about 40GB files in sysv shm. Just move
the line before the locking happens in vma_adjust, something as below, the
line number is not accurate because my patch is based on another tree right
now.

--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -581,6 +581,8 @@ again:                      remove_next = 1 + (end >
next->vm_end);
                }
        }

+       vma_adjust_trans_huge(vma, start, end, adjust_next);
+
        if (file) {
                mapping = file->f_mapping;
                if (!(vma->vm_flags & VM_NONLINEAR))
@@ -597,8 +599,6 @@ again:                      remove_next = 1 + (end >
next->vm_end);
                }
        }

-       vma_adjust_trans_huge(vma, start, end, adjust_next);
-
        anon_vma = vma->anon_vma;
        if (!anon_vma && adjust_next)
                anon_vma = next->anon_vma;


Best wishes,
-- 
Ning Qu (曲宁) | Software Engineer | quning@google.com | +1-408-418-6066


On Tue, Aug 6, 2013 at 2:09 PM, Ning Qu <quning@google.com> wrote:

> Is this safe to move the vma_adjust_trans_huge before the line 772? Seems
> for anonymous memory, we only take the lock after vma_adjust_trans_huge,
> maybe we should do the same for file?
>
> Best wishes,
> --
> Ning Qu (曲宁) | Software Engineer | quning@google.com | +1-408-418-6066
>
>
> On Tue, Aug 6, 2013 at 12:09 PM, Ning Qu <quning@google.com> wrote:
>
>> I am probably running into a deadlock case for this patch.
>>
>> When splitting the file huge page, we hold the i_mmap_mutex.
>>
>> However, when coming from the call path in vma_adjust as following, we
>> will grab the i_mmap_mutex already before doing vma_adjust_trans_huge,
>> which will eventually calls the split_huge_page then split_file_huge_page
>> ....
>>
>>
>> https://git.kernel.org/cgit/linux/kernel/git/kas/linux.git/tree/mm/mmap.c?h=thp/pagecache#n753
>>
>>
>>
>>
>> Best wishes,
>> --
>> Ning Qu (曲宁) | Software Engineer | quning@google.com | +1-408-418-6066
>>
>>
>> On Sat, Aug 3, 2013 at 7:17 PM, Kirill A. Shutemov <
>> kirill.shutemov@linux.intel.com> wrote:
>>
>>> From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
>>>
>>> The base scheme is the same as for anonymous pages, but we walk by
>>> mapping->i_mmap rather then anon_vma->rb_root.
>>>
>>> When we add a huge page to page cache we take only reference to head
>>> page, but on split we need to take addition reference to all tail pages
>>> since they are still in page cache after splitting.
>>>
>>> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>>> ---
>>>  mm/huge_memory.c | 89
>>> +++++++++++++++++++++++++++++++++++++++++++++++---------
>>>  1 file changed, 76 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>>> index 523946c..d7c6830 100644
>>> --- a/mm/huge_memory.c
>>> +++ b/mm/huge_memory.c
>>> @@ -1580,6 +1580,7 @@ static void __split_huge_page_refcount(struct page
>>> *page,
>>>         struct zone *zone = page_zone(page);
>>>         struct lruvec *lruvec;
>>>         int tail_count = 0;
>>> +       int initial_tail_refcount;
>>>
>>>         /* prevent PageLRU to go away from under us, and freeze lru
>>> stats */
>>>         spin_lock_irq(&zone->lru_lock);
>>> @@ -1589,6 +1590,13 @@ static void __split_huge_page_refcount(struct
>>> page *page,
>>>         /* complete memcg works before add pages to LRU */
>>>         mem_cgroup_split_huge_fixup(page);
>>>
>>> +       /*
>>> +        * When we add a huge page to page cache we take only reference
>>> to head
>>> +        * page, but on split we need to take addition reference to all
>>> tail
>>> +        * pages since they are still in page cache after splitting.
>>> +        */
>>> +       initial_tail_refcount = PageAnon(page) ? 0 : 1;
>>> +
>>>         for (i = HPAGE_PMD_NR - 1; i >= 1; i--) {
>>>                 struct page *page_tail = page + i;
>>>
>>> @@ -1611,8 +1619,9 @@ static void __split_huge_page_refcount(struct page
>>> *page,
>>>                  * atomic_set() here would be safe on all archs (and
>>>                  * not only on x86), it's safer to use atomic_add().
>>>                  */
>>> -               atomic_add(page_mapcount(page) +
>>> page_mapcount(page_tail) + 1,
>>> -                          &page_tail->_count);
>>> +               atomic_add(initial_tail_refcount + page_mapcount(page) +
>>> +                               page_mapcount(page_tail) + 1,
>>> +                               &page_tail->_count);
>>>
>>>                 /* after clearing PageTail the gup refcount can be
>>> released */
>>>                 smp_mb();
>>> @@ -1651,23 +1660,23 @@ static void __split_huge_page_refcount(struct
>>> page *page,
>>>                 */
>>>                 page_tail->_mapcount = page->_mapcount;
>>>
>>> -               BUG_ON(page_tail->mapping);
>>>                 page_tail->mapping = page->mapping;
>>>
>>>                 page_tail->index = page->index + i;
>>>                 page_nid_xchg_last(page_tail, page_nid_last(page));
>>>
>>> -               BUG_ON(!PageAnon(page_tail));
>>>                 BUG_ON(!PageUptodate(page_tail));
>>>                 BUG_ON(!PageDirty(page_tail));
>>> -               BUG_ON(!PageSwapBacked(page_tail));
>>>
>>>                 lru_add_page_tail(page, page_tail, lruvec, list);
>>>         }
>>>         atomic_sub(tail_count, &page->_count);
>>>         BUG_ON(atomic_read(&page->_count) <= 0);
>>>
>>> -       __mod_zone_page_state(zone, NR_ANON_TRANSPARENT_HUGEPAGES, -1);
>>> +       if (PageAnon(page))
>>> +               __mod_zone_page_state(zone,
>>> NR_ANON_TRANSPARENT_HUGEPAGES, -1);
>>> +       else
>>> +               __mod_zone_page_state(zone,
>>> NR_FILE_TRANSPARENT_HUGEPAGES, -1);
>>>
>>>         ClearPageCompound(page);
>>>         compound_unlock(page);
>>> @@ -1767,7 +1776,7 @@ static int __split_huge_page_map(struct page *page,
>>>  }
>>>
>>>  /* must be called with anon_vma->root->rwsem held */
>>> -static void __split_huge_page(struct page *page,
>>> +static void __split_anon_huge_page(struct page *page,
>>>                               struct anon_vma *anon_vma,
>>>                               struct list_head *list)
>>>  {
>>> @@ -1791,7 +1800,7 @@ static void __split_huge_page(struct page *page,
>>>          * and establishes a child pmd before
>>>          * __split_huge_page_splitting() freezes the parent pmd (so if
>>>          * we fail to prevent copy_huge_pmd() from running until the
>>> -        * whole __split_huge_page() is complete), we will still see
>>> +        * whole __split_anon_huge_page() is complete), we will still see
>>>          * the newly established pmd of the child later during the
>>>          * walk, to be able to set it as pmd_trans_splitting too.
>>>          */
>>> @@ -1822,14 +1831,11 @@ static void __split_huge_page(struct page *page,
>>>   * from the hugepage.
>>>   * Return 0 if the hugepage is split successfully otherwise return 1.
>>>   */
>>> -int split_huge_page_to_list(struct page *page, struct list_head *list)
>>> +static int split_anon_huge_page(struct page *page, struct list_head
>>> *list)
>>>  {
>>>         struct anon_vma *anon_vma;
>>>         int ret = 1;
>>>
>>> -       BUG_ON(is_huge_zero_page(page));
>>> -       BUG_ON(!PageAnon(page));
>>> -
>>>         /*
>>>          * The caller does not necessarily hold an mmap_sem that would
>>> prevent
>>>          * the anon_vma disappearing so we first we take a reference to
>>> it
>>> @@ -1847,7 +1853,7 @@ int split_huge_page_to_list(struct page *page,
>>> struct list_head *list)
>>>                 goto out_unlock;
>>>
>>>         BUG_ON(!PageSwapBacked(page));
>>> -       __split_huge_page(page, anon_vma, list);
>>> +       __split_anon_huge_page(page, anon_vma, list);
>>>         count_vm_event(THP_SPLIT);
>>>
>>>         BUG_ON(PageCompound(page));
>>> @@ -1858,6 +1864,63 @@ out:
>>>         return ret;
>>>  }
>>>
>>> +static int split_file_huge_page(struct page *page, struct list_head
>>> *list)
>>> +{
>>> +       struct address_space *mapping = page->mapping;
>>> +       pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
>>> +       struct vm_area_struct *vma;
>>> +       int mapcount, mapcount2;
>>> +
>>> +       BUG_ON(!PageHead(page));
>>> +       BUG_ON(PageTail(page));
>>> +
>>> +       mutex_lock(&mapping->i_mmap_mutex);
>>> +       mapcount = 0;
>>> +       vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
>>> +               unsigned long addr = vma_address(page, vma);
>>> +               mapcount += __split_huge_page_splitting(page, vma, addr);
>>> +       }
>>> +
>>> +       if (mapcount != page_mapcount(page))
>>> +               printk(KERN_ERR "mapcount %d page_mapcount %d\n",
>>> +                      mapcount, page_mapcount(page));
>>> +       BUG_ON(mapcount != page_mapcount(page));
>>> +
>>> +       __split_huge_page_refcount(page, list);
>>> +
>>> +       mapcount2 = 0;
>>> +       vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) {
>>> +               unsigned long addr = vma_address(page, vma);
>>> +               mapcount2 += __split_huge_page_map(page, vma, addr);
>>> +       }
>>> +
>>> +       if (mapcount != mapcount2)
>>> +               printk(KERN_ERR "mapcount %d mapcount2 %d page_mapcount
>>> %d\n",
>>> +                      mapcount, mapcount2, page_mapcount(page));
>>> +       BUG_ON(mapcount != mapcount2);
>>> +       count_vm_event(THP_SPLIT);
>>> +       mutex_unlock(&mapping->i_mmap_mutex);
>>> +
>>> +       /*
>>> +        * Drop small pages beyond i_size if any.
>>> +        *
>>> +        * XXX: do we need to serialize over i_mutex here?
>>> +        * If yes, how to get mmap_sem vs. i_mutex ordering fixed?
>>> +        */
>>> +       truncate_inode_pages(mapping, i_size_read(mapping->host));
>>> +       return 0;
>>> +}
>>> +
>>> +int split_huge_page_to_list(struct page *page, struct list_head *list)
>>> +{
>>> +       BUG_ON(is_huge_zero_page(page));
>>> +
>>> +       if (PageAnon(page))
>>> +               return split_anon_huge_page(page, list);
>>> +       else
>>> +               return split_file_huge_page(page, list);
>>> +}
>>> +
>>>  #define VM_NO_THP
>>> (VM_SPECIAL|VM_MIXEDMAP|VM_HUGETLB|VM_SHARED|VM_MAYSHARE)
>>>
>>>  int hugepage_madvise(struct vm_area_struct *vma,
>>> --
>>> 1.8.3.2
>>>
>>>
>>
>

[-- Attachment #2: Type: text/html, Size: 19191 bytes --]

  reply	other threads:[~2013-08-06 21:47 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-04  2:17 [PATCHv5 00/23] Transparent huge page cache: phase 1, everything but mmap() Kirill A. Shutemov
2013-08-04  2:17 ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 01/23] radix-tree: implement preload for multiple contiguous elements Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-05 11:17   ` Jan Kara
2013-08-05 11:17     ` Jan Kara
2013-08-06 16:34     ` Matthew Wilcox
2013-08-06 16:34       ` Matthew Wilcox
2013-08-06 20:17       ` Jan Kara
2013-08-06 20:17         ` Jan Kara
2013-08-07 16:32     ` Kirill A. Shutemov
2013-08-07 16:32       ` Kirill A. Shutemov
2013-08-07 16:32       ` Kirill A. Shutemov
2013-08-07 20:00       ` Jan Kara
2013-08-07 20:00         ` Jan Kara
2013-08-07 20:24         ` Kirill A. Shutemov
2013-08-07 20:24           ` Kirill A. Shutemov
2013-08-07 20:24           ` Kirill A. Shutemov
2013-08-07 20:36           ` Jan Kara
2013-08-07 20:36             ` Jan Kara
2013-08-07 21:37             ` Kirill A. Shutemov
2013-08-07 21:37               ` Kirill A. Shutemov
2013-08-07 21:37               ` Kirill A. Shutemov
2013-08-08  8:45               ` Kirill A. Shutemov
2013-08-08  8:45                 ` Kirill A. Shutemov
2013-08-08  8:45                 ` Kirill A. Shutemov
2013-08-08 10:04                 ` Jan Kara
2013-08-08 10:04                   ` Jan Kara
2013-08-09 11:13                   ` Kirill A. Shutemov
2013-08-09 11:13                     ` Kirill A. Shutemov
2013-08-09 11:13                     ` Kirill A. Shutemov
2013-08-09 11:36                     ` Jan Kara
2013-08-09 11:36                       ` Jan Kara
2013-08-04  2:17 ` [PATCH 02/23] memcg, thp: charge huge cache pages Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  8:25   ` Michal Hocko
2013-08-04  8:25     ` Michal Hocko
2013-08-04  2:17 ` [PATCH 03/23] thp: compile-time and sysfs knob for thp pagecache Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-09-05 21:53   ` Ning Qu
2013-09-06 11:33     ` Kirill A. Shutemov
2013-09-06 11:33       ` Kirill A. Shutemov
2013-09-06 11:33       ` Kirill A. Shutemov
2013-09-06 17:14       ` Ning Qu
2013-08-04  2:17 ` [PATCH 04/23] thp, mm: introduce mapping_can_have_hugepages() predicate Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 05/23] thp: represent file thp pages in meminfo and friends Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-30 22:16   ` Ning Qu
2013-09-02 11:36     ` Kirill A. Shutemov
2013-09-02 11:36       ` Kirill A. Shutemov
2013-09-02 20:05       ` Ning Qu
2013-08-04  2:17 ` [PATCH 06/23] thp, mm: rewrite add_to_page_cache_locked() to support huge pages Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 07/23] mm: trace filemap: dump page order Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 08/23] block: implement add_bdi_stat() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-05 11:21   ` Jan Kara
2013-08-05 11:21     ` Jan Kara
2013-08-04  2:17 ` [PATCH 09/23] thp, mm: rewrite delete_from_page_cache() to support huge pages Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 10/23] thp, mm: warn if we try to use replace_page_cache_page() with THP Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 11/23] thp, mm: handle tail pages in page_cache_get_speculative() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 12/23] thp, mm: add event counters for huge page alloc on file write or read Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 13/23] thp, mm: allocate huge pages in grab_cache_page_write_begin() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 14/23] thp, mm: naive support of thp in generic_perform_write Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 15/23] mm, fs: avoid page allocation beyond i_size on read Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-05  0:29   ` NeilBrown
2013-08-05  0:29     ` NeilBrown
2013-08-04  2:17 ` [PATCH 16/23] thp, mm: handle transhuge pages in do_generic_file_read() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 17/23] thp, libfs: initial thp support Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 18/23] thp: libfs: introduce simple_thp_release() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 19/23] truncate: support huge pages Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-05 13:29   ` Jan Kara
2013-08-05 13:29     ` Jan Kara
2013-08-06 20:23   ` Dave Hansen
2013-08-06 20:23     ` Dave Hansen
2013-08-06 20:57     ` Kirill A. Shutemov
2013-08-06 20:57       ` Kirill A. Shutemov
2013-08-06 21:55   ` Dave Hansen
2013-08-06 21:55     ` Dave Hansen
2013-08-09 14:39     ` Kirill A. Shutemov
2013-08-09 14:39       ` Kirill A. Shutemov
2013-08-09 14:39       ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 20/23] thp: handle file pages in split_huge_page() Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-06 19:09   ` Ning Qu
2013-08-06 21:09     ` Ning Qu
2013-08-06 21:47       ` Ning Qu [this message]
2013-08-09 14:46         ` Kirill A. Shutemov
2013-08-09 14:46           ` Kirill A. Shutemov
2013-08-09 14:46           ` Kirill A. Shutemov
2013-08-09 14:49           ` Ning Qu
2013-08-09 21:24             ` Ning Qu
2013-08-09 21:24               ` Ning Qu
2013-08-04  2:17 ` [PATCH 21/23] thp: wait_split_huge_page(): serialize over i_mmap_mutex too Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 22/23] thp, mm: split huge page on mmap file page Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov
2013-08-08 20:49   ` Khalid Aziz
2013-08-08 20:49     ` Khalid Aziz
2013-08-09 14:50     ` Kirill A. Shutemov
2013-08-09 14:50       ` Kirill A. Shutemov
2013-08-04  2:17 ` [PATCH 23/23] ramfs: enable transparent huge page cache Kirill A. Shutemov
2013-08-04  2:17   ` Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACz4_2fv1g2dRLh72gtaCYkNC6+Pp4h=R0q-taR51tejpL1gnw@mail.gmail.com' \
    --to=quning@google.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@sr71.net \
    --cc=dhillf@gmail.com \
    --cc=fengguang.wu@intel.com \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kirill@shutemov.name \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.