Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1413262

Re: [linux-next: Tree for Jun 1] __khugepaged_exit rwsem_down_write_failed lockup

From Andrea Arcangeli <aarcange@redhat.com>
Newsgroups linux.kernel
Subject Re: [linux-next: Tree for Jun 1] __khugepaged_exit rwsem_down_write_failed lockup
Date 2016-06-03 16:00 +0200
Message-ID <rFXNM-3QL-23@gated-at.bofh.it> (permalink)
References <rF4Rj-2Wb-13@gated-at.bofh.it> <rFq5s-7Xr-11@gated-at.bofh.it> <rFx6V-48t-13@gated-at.bofh.it> <rFzBL-5Mk-3@gated-at.bofh.it> <rFzV8-5SN-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, Jun 02, 2016 at 02:21:10PM +0200, Michal Hocko wrote:
> Testing with the patch makes some sense as well, but I would like to
> hear from Andrea whether the approach is good because I am wondering why
> he hasn't done that before - it feels so much simpler than the current
> code.

The down_write in the exit path comes from __ksm_exit. If you don't
like it there I'd suggest to also remove it from __ksm_exit.

This is a proposed cleanup correct?

The first thing that I can notice is that khugepaged_test_exit() then
can only be called and provide the expected retval, after
atomic_inc_not_zero(mm_users). Also note mmget_not_zero() should be
used instead.

However the code still uses khugepaged_test_exit in __khugepage_enter
that won't increase the mm_users, so then the patch relaxes that check
too much, albeit only for a debug check not strictly a bug.

The cons of this change purely that it'll decrease the responsiveness
in releasing the RAM of a killed task a bit.

To me the fewer time we hold the mm_users the better and I don't see
an obvious runtime improvement coming from this change. It's a bit
simpler yes, but the down_write in the exit path is well understood,
ksm does the same thing and it's in a slow path (it only happens if
the mm that exited is the current one under scan by either ksmd or
khugepaged, so normally the down_write is not executed in the exit
path and the "mm" is collected right away both as a mm_users and
mm_count).

In short I think it's a tradeoff: pros) removes down_write in a slow
path of the the mm exit which may simplify the code a bit, cons) it
could increase the latency in freeing memory as result of a task
exiting or being killed during the khugepaged scan, for example while
the THP is being allocated. While compaction runs to allocate the THP
in collapse_huge_page, if the task is killed currently the memory is
released right away, without waiting for the allocation to succeed or
fail.

I don't see a big enough problem with the down_write in a slow path of
khugepaged_exit to justify the increased latency in releasing memory.

I was very happy by Oleg's patch reducing the mm_users holding of
userfaultfd too. That was controlled by userland so it would only be
an issue for non-cooperative usage which isn't upstream yet, and it
was also much wider than this one would become with the patch applied,
but I liked the direction.

If prefer instead to remove the down_write, you probably could move
the test_exit before the down_read/write to bail out before taking the
lock: you don't need the mmap_sem to do test_exit anymore. The only
reason the text_exit would remain in fact is just to reduce the
latency of the memory freeing, it then becomes a voluntary preempt
cond_resched() to release the memory to make a parallel ;), but unable
to let the kernel free the memory while the THP allocation runs.

Thanks,
Andrea

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

linux-next: Tree for Jun 1 Stephen Rothwell <sfr@canb.auug.org.au> - 2016-06-01 05:20 +0200
  [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-02 04:00 +0200
    Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-02 11:30 +0200
      Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-06-02 14:10 +0200
        Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-02 14:30 +0200
          Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Andrea Arcangeli <aarcange@redhat.com> - 2016-06-03 16:00 +0200
            Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 16:50 +0200
              Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Andrea Arcangeli <aarcange@redhat.com> - 2016-06-03 17:20 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-07 09:40 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Vlastimil Babka <vbabka@suse.cz> - 2016-06-08 10:20 +0200
      Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-03 09:20 +0200
        Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 09:30 +0200
          Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-03 10:50 +0200
            Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 12:00 +0200
              Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 12:10 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-06-03 15:40 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 15:50 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-03 15:50 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-04 10:00 +0200
                Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Michal Hocko <mhocko@kernel.org> - 2016-06-06 10:40 +0200
    Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Vlastimil Babka <vbabka@suse.cz> - 2016-06-02 15:30 +0200
      Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Ebru Akagunduz <ebru.akagunduz@gmail.com> - 2016-06-02 21:00 +0200
        Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-03 03:10 +0200
          Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-03 03:30 +0200
            Re: [linux-next: Tree for Jun 1] __khugepaged_exit  rwsem_down_write_failed lockup Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-03 06:20 +0200
      [PATCH] mm, thp: fix locking inconsistency in collapse_huge_page Ebru Akagunduz <ebru.akagunduz@gmail.com> - 2016-06-03 14:30 +0200
        Re: [PATCH] mm, thp: fix locking inconsistency in collapse_huge_page Vlastimil Babka <vbabka@suse.cz> - 2016-06-06 15:10 +0200
          Re: [PATCH] mm, thp: fix locking inconsistency in collapse_huge_page Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-06-09 06:00 +0200

csiph-web