From: Andrea Arcangeli <aarcange@redhat.com> To: Michal Hocko <mhocko@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org>, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>, David Rientjes <rientjes@google.com>, Oleg Nesterov <oleg@redhat.com>, Andrea Argangeli <andrea@kernel.org>, Hugh Dickins <hughd@google.com>, "Kirill A. Shutemov" <kirill@shutemov.name>, linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>, Michal Hocko <mhocko@suse.com> Subject: Re: [PATCH] mm, oom: allow oom reaper to race with exit_mmap Date: Thu, 10 Aug 2017 20:05:54 +0200 [thread overview] Message-ID: <20170810180554.GT25347@redhat.com> (raw) In-Reply-To: <20170810081632.31265-1-mhocko@kernel.org> On Thu, Aug 10, 2017 at 10:16:32AM +0200, Michal Hocko wrote: > Andrea has proposed and alternative solution [4] which should be > equivalent functionally similar to {ksm,khugepaged}_exit. I have to > confess I really don't like that approach but I can live with it if > that is a preferred way (to be honest I would like to drop the empty Well you added two branches, when only one is necessary. It's more or less like preferring a rwsem when a mutex is enough, because you're more used to use rwsems. > down_write();up_write() from the other two callers as well). In fact I > have asked Andrea to post his patch [5] but that hasn't happened. I do > not think we should wait much longer and finally merge some fix. It's posted in [4] already below I didn't think it was necessary to resend it. The only other improvement I can think of is an unlikely around tsk_is_oom_victim() in exit_mmap, but your patch below would need it too, and two of them. > [1] http://lkml.kernel.org/r/20170724072332.31903-1-mhocko@kernel.org > [2] http://lkml.kernel.org/r/20170725142626.GJ26723@dhcp22.suse.cz > [3] http://lkml.kernel.org/r/20170725160359.GO26723@dhcp22.suse.cz > [4] http://lkml.kernel.org/r/20170726162912.GA29716@redhat.com > [5] http://lkml.kernel.org/r/20170728062345.GA2274@dhcp22.suse.cz > > + if (tsk_is_oom_victim(current)) { > + down_write(&mm->mmap_sem); > + locked = true; > + } > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > tlb_finish_mmu(&tlb, 0, -1); > > @@ -3005,7 +3018,10 @@ void exit_mmap(struct mm_struct *mm) > nr_accounted += vma_pages(vma); > vma = remove_vma(vma); > } > + mm->mmap = NULL; > vm_unacct_memory(nr_accounted); > + if (locked) > + up_write(&mm->mmap_sem); I wouldn't normally repost to add an unlikely when I'm not sure if it gets merged, but if it gets merged I would immediately tell to Andrew about the microoptimization being missing there so he can fold it later. Before reposting about the unlikely I thought we should agree which version to merge: [4] or the above double branch (for no good as far as I tangibly can tell). I think down_write;up_write is the correct thing to do here because holding the lock for any additional instruction has zero benefits, and if it has zero benefits it only adds up confusion and makes the code partly senseless, and that ultimately hurts the reader when it tries to understand why you're holding the lock for so long when it's not needed. I just read other code yesterday for another bug about the rss going off by one in some older kernel, that calls add_mm_rss_vec(mm, rss); where rss is on the stack and mm->rss_stat is mm global, under the PT lock, and again I had to ask myself why is it done there, and if the PT lock could possibly help. My evaluation was no, it's just done in the wrong place, but then I'm not 100% sure because there's a chance I misread something very subtle. add_mm_rss_vec(mm, rss); arch_leave_lazy_mmu_mode(); /* Do the actual TLB flush before dropping ptl */ if (force_flush) tlb_flush_mmu_tlbonly(tlb); pte_unmap_unlock(start_pte, ptl); The tlb flushing doesn't seem to check the stats either, so why is add_mm_rss_vec isn't called after pte_unmap_unlock? And yes it looks offtopic (and there's no bug in the rss accounting, I was just reading around it just in case) but it's not, it's precisely the kind of issue I have with your patch because it'll introduce another case like above that I can't explain why it's done under a lock when it doesn't need it, and it's hard to guess it was just your dislike for down_read;up_write that made you choose to hold the lock for no good reason arbitrarily a bit longer. Thanks, Andrea
WARNING: multiple messages have this Message-ID (diff)
From: Andrea Arcangeli <aarcange@redhat.com> To: Michal Hocko <mhocko@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org>, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>, David Rientjes <rientjes@google.com>, Oleg Nesterov <oleg@redhat.com>, Andrea Argangeli <andrea@kernel.org>, Hugh Dickins <hughd@google.com>, "Kirill A. Shutemov" <kirill@shutemov.name>, linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>, Michal Hocko <mhocko@suse.com> Subject: Re: [PATCH] mm, oom: allow oom reaper to race with exit_mmap Date: Thu, 10 Aug 2017 20:05:54 +0200 [thread overview] Message-ID: <20170810180554.GT25347@redhat.com> (raw) In-Reply-To: <20170810081632.31265-1-mhocko@kernel.org> On Thu, Aug 10, 2017 at 10:16:32AM +0200, Michal Hocko wrote: > Andrea has proposed and alternative solution [4] which should be > equivalent functionally similar to {ksm,khugepaged}_exit. I have to > confess I really don't like that approach but I can live with it if > that is a preferred way (to be honest I would like to drop the empty Well you added two branches, when only one is necessary. It's more or less like preferring a rwsem when a mutex is enough, because you're more used to use rwsems. > down_write();up_write() from the other two callers as well). In fact I > have asked Andrea to post his patch [5] but that hasn't happened. I do > not think we should wait much longer and finally merge some fix. It's posted in [4] already below I didn't think it was necessary to resend it. The only other improvement I can think of is an unlikely around tsk_is_oom_victim() in exit_mmap, but your patch below would need it too, and two of them. > [1] http://lkml.kernel.org/r/20170724072332.31903-1-mhocko@kernel.org > [2] http://lkml.kernel.org/r/20170725142626.GJ26723@dhcp22.suse.cz > [3] http://lkml.kernel.org/r/20170725160359.GO26723@dhcp22.suse.cz > [4] http://lkml.kernel.org/r/20170726162912.GA29716@redhat.com > [5] http://lkml.kernel.org/r/20170728062345.GA2274@dhcp22.suse.cz > > + if (tsk_is_oom_victim(current)) { > + down_write(&mm->mmap_sem); > + locked = true; > + } > free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); > tlb_finish_mmu(&tlb, 0, -1); > > @@ -3005,7 +3018,10 @@ void exit_mmap(struct mm_struct *mm) > nr_accounted += vma_pages(vma); > vma = remove_vma(vma); > } > + mm->mmap = NULL; > vm_unacct_memory(nr_accounted); > + if (locked) > + up_write(&mm->mmap_sem); I wouldn't normally repost to add an unlikely when I'm not sure if it gets merged, but if it gets merged I would immediately tell to Andrew about the microoptimization being missing there so he can fold it later. Before reposting about the unlikely I thought we should agree which version to merge: [4] or the above double branch (for no good as far as I tangibly can tell). I think down_write;up_write is the correct thing to do here because holding the lock for any additional instruction has zero benefits, and if it has zero benefits it only adds up confusion and makes the code partly senseless, and that ultimately hurts the reader when it tries to understand why you're holding the lock for so long when it's not needed. I just read other code yesterday for another bug about the rss going off by one in some older kernel, that calls add_mm_rss_vec(mm, rss); where rss is on the stack and mm->rss_stat is mm global, under the PT lock, and again I had to ask myself why is it done there, and if the PT lock could possibly help. My evaluation was no, it's just done in the wrong place, but then I'm not 100% sure because there's a chance I misread something very subtle. add_mm_rss_vec(mm, rss); arch_leave_lazy_mmu_mode(); /* Do the actual TLB flush before dropping ptl */ if (force_flush) tlb_flush_mmu_tlbonly(tlb); pte_unmap_unlock(start_pte, ptl); The tlb flushing doesn't seem to check the stats either, so why is add_mm_rss_vec isn't called after pte_unmap_unlock? And yes it looks offtopic (and there's no bug in the rss accounting, I was just reading around it just in case) but it's not, it's precisely the kind of issue I have with your patch because it'll introduce another case like above that I can't explain why it's done under a lock when it doesn't need it, and it's hard to guess it was just your dislike for down_read;up_write that made you choose to hold the lock for no good reason arbitrarily a bit longer. Thanks, Andrea -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-08-10 18:06 UTC|newest] Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-08-10 8:16 [PATCH] mm, oom: allow oom reaper to race with exit_mmap Michal Hocko 2017-08-10 8:16 ` Michal Hocko 2017-08-10 18:05 ` Andrea Arcangeli [this message] 2017-08-10 18:05 ` Andrea Arcangeli 2017-08-10 18:51 ` Michal Hocko 2017-08-10 18:51 ` Michal Hocko 2017-08-10 20:36 ` Michal Hocko 2017-08-10 20:36 ` Michal Hocko -- strict thread matches above, loose matches on Subject: below -- 2017-07-27 8:29 Manish Jaggi 2017-07-27 9:24 ` Michal Hocko 2017-07-24 7:23 Michal Hocko 2017-07-24 7:23 ` Michal Hocko 2017-07-24 14:00 ` Kirill A. Shutemov 2017-07-24 14:00 ` Kirill A. Shutemov 2017-07-24 14:15 ` Michal Hocko 2017-07-24 14:15 ` Michal Hocko 2017-07-24 14:51 ` Kirill A. Shutemov 2017-07-24 14:51 ` Kirill A. Shutemov 2017-07-24 16:11 ` Michal Hocko 2017-07-24 16:11 ` Michal Hocko 2017-07-25 14:17 ` Kirill A. Shutemov 2017-07-25 14:17 ` Kirill A. Shutemov 2017-07-25 14:26 ` Michal Hocko 2017-07-25 14:26 ` Michal Hocko 2017-07-25 15:07 ` Kirill A. Shutemov 2017-07-25 15:07 ` Kirill A. Shutemov 2017-07-25 15:15 ` Michal Hocko 2017-07-25 15:15 ` Michal Hocko 2017-07-25 14:26 ` Michal Hocko 2017-07-25 15:17 ` Kirill A. Shutemov 2017-07-25 15:17 ` Kirill A. Shutemov 2017-07-25 15:23 ` Michal Hocko 2017-07-25 15:23 ` Michal Hocko 2017-07-25 15:31 ` Kirill A. Shutemov 2017-07-25 15:31 ` Kirill A. Shutemov 2017-07-25 16:04 ` Michal Hocko 2017-07-25 16:04 ` Michal Hocko 2017-07-25 19:19 ` Andrea Arcangeli 2017-07-25 19:19 ` Andrea Arcangeli 2017-07-26 5:45 ` Michal Hocko 2017-07-26 5:45 ` Michal Hocko 2017-07-26 16:29 ` Andrea Arcangeli 2017-07-26 16:29 ` Andrea Arcangeli 2017-07-26 16:43 ` Andrea Arcangeli 2017-07-26 16:43 ` Andrea Arcangeli 2017-07-27 6:50 ` Michal Hocko 2017-07-27 6:50 ` Michal Hocko 2017-07-27 14:55 ` Andrea Arcangeli 2017-07-27 14:55 ` Andrea Arcangeli 2017-07-28 6:23 ` Michal Hocko 2017-07-28 6:23 ` Michal Hocko 2017-08-15 0:20 ` David Rientjes 2017-08-15 0:20 ` David Rientjes 2017-07-24 15:27 ` Michal Hocko 2017-07-24 15:27 ` Michal Hocko 2017-07-24 16:42 ` kbuild test robot 2017-07-24 18:12 ` Michal Hocko 2017-07-24 18:12 ` Michal Hocko 2017-07-25 15:26 ` Andrea Arcangeli 2017-07-25 15:26 ` Andrea Arcangeli 2017-07-25 15:45 ` Michal Hocko 2017-07-25 15:45 ` Michal Hocko 2017-07-25 18:26 ` Andrea Arcangeli 2017-07-25 18:26 ` Andrea Arcangeli 2017-07-26 5:45 ` Michal Hocko 2017-07-26 5:45 ` Michal Hocko 2017-07-26 16:39 ` Andrea Arcangeli 2017-07-26 16:39 ` Andrea Arcangeli 2017-07-27 6:32 ` Michal Hocko 2017-07-27 6:32 ` Michal Hocko
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=20170810180554.GT25347@redhat.com \ --to=aarcange@redhat.com \ --cc=akpm@linux-foundation.org \ --cc=andrea@kernel.org \ --cc=hughd@google.com \ --cc=kirill@shutemov.name \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mhocko@kernel.org \ --cc=mhocko@suse.com \ --cc=oleg@redhat.com \ --cc=penguin-kernel@I-love.SAKURA.ne.jp \ --cc=rientjes@google.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: linkBe 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.