Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1302861 > unrolled thread
| Started by | Michal Hocko <mhocko@kernel.org> |
|---|---|
| First post | 2016-01-06 16:50 +0100 |
| Last post | 2016-01-07 09:20 +0100 |
| Articles | 2 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/2] oom reaper: handle anonymous mlocked pages Michal Hocko <mhocko@kernel.org> - 2016-01-06 16:50 +0100
Re: [PATCH 2/2] oom reaper: handle anonymous mlocked pages Michal Hocko <mhocko@kernel.org> - 2016-01-07 09:20 +0100
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2016-01-06 16:50 +0100 |
| Subject | [PATCH 2/2] oom reaper: handle anonymous mlocked pages |
| Message-ID | <qNYvw-35F-7@gated-at.bofh.it> |
From: Michal Hocko <mhocko@suse.com>
__oom_reap_vmas current skips over all mlocked vmas because they need
a special treatment before they are unmapped. This is primarily done
for simplicity. There is no reason to skip over them for all mappings
though and reduce the amount of reclaimed memory. Anonymous mappings
are not visible by any other process so doing a munlock before unmap
is safe to do from the semantic point of view. munlock_vma_pages_all
is also safe to be called from the oom reaper context because it
doesn't sit on any locks but mmap_sem (for read).
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
mm/oom_kill.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1ece40b94725..913b68a44fd4 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -445,11 +445,16 @@ static bool __oom_reap_vmas(struct mm_struct *mm)
continue;
/*
- * mlocked VMAs require explicit munlocking before unmap.
- * Let's keep it simple here and skip such VMAs.
+ * mlocked VMAs require explicit munlocking before unmap
+ * and that is safe only for anonymous mappings because
+ * nobody except for the victim will need them locked
*/
- if (vma->vm_flags & VM_LOCKED)
- continue;
+ if (vma->vm_flags & VM_LOCKED) {
+ if (vma_is_anonymous(vma))
+ munlock_vma_pages_all(vma);
+ else
+ continue;
+ }
/*
* Only anonymous pages have a good chance to be dropped
--
2.6.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2016-01-07 09:20 +0100 |
| Message-ID | <qOdXB-5pq-21@gated-at.bofh.it> |
| In reply to | #1302861 |
On Wed 06-01-16 16:42:55, Michal Hocko wrote:
> Anonymous mappings
> are not visible by any other process so doing a munlock before unmap
> is safe to do from the semantic point of view.
I was too conservative here. I have completely forgoten about the lazy
mlock handling during try_to_unmap which would keep the page mlocked if
there is an mlocked vma mapping that page. So we can safely do what I
was proposing originally. I hope I am not missing anything now. Here is
the replacement patch
---
From 9aa92fc1c7f0f1c55d2efab0239dbb10a9dce001 Mon Sep 17 00:00:00 2001
From: Michal Hocko <mhocko@suse.com>
Date: Wed, 6 Jan 2016 10:48:39 +0100
Subject: [PATCH] oom reaper: handle mlocked pages
__oom_reap_vmas current skips over all mlocked vmas because they need a
special treatment before they are unmapped. This is primarily done for
simplicity. There is no reason to skip over them and reduce the amount
of reclaimed memory. This is safe from the semantic point of view
because try_to_unmap_one during rmap walk would keep tell the reclaim
to cull the page back and mlock it again.
munlock_vma_pages_all is also safe to be called from the oom reaper
context because it doesn't sit on any locks but mmap_sem (for read).
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
mm/oom_kill.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1ece40b94725..0e4af31db96f 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -445,13 +445,6 @@ static bool __oom_reap_vmas(struct mm_struct *mm)
continue;
/*
- * mlocked VMAs require explicit munlocking before unmap.
- * Let's keep it simple here and skip such VMAs.
- */
- if (vma->vm_flags & VM_LOCKED)
- continue;
-
- /*
* Only anonymous pages have a good chance to be dropped
* without additional steps which we cannot afford as we
* are OOM already.
@@ -461,9 +454,12 @@ static bool __oom_reap_vmas(struct mm_struct *mm)
* we do not want to block exit_mmap by keeping mm ref
* count elevated without a good reason.
*/
- if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED))
+ if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) {
+ if (vma->vm_flags & VM_LOCKED)
+ munlock_vma_pages_all(vma);
unmap_page_range(&tlb, vma, vma->vm_start, vma->vm_end,
&details);
+ }
}
tlb_finish_mmu(&tlb, 0, -1);
up_read(&mm->mmap_sem);
--
2.6.4
--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web