From: Michal Hocko <mhocko@kernel.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: akpm@linux-foundation.org, rientjes@google.com,
hannes@cmpxchg.org, guro@fb.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm, oom: do not rely on TIF_MEMDIE for memory reserves access
Date: Wed, 2 Aug 2017 08:10:22 +0200 [thread overview]
Message-ID: <20170802061022.GA25318@dhcp22.suse.cz> (raw)
In-Reply-To: <20170801165242.GA15518@dhcp22.suse.cz>
On Tue 01-08-17 18:52:42, Michal Hocko wrote:
> On Wed 02-08-17 00:30:33, Tetsuo Handa wrote:
[...]
> > > - if (gfp_pfmemalloc_allowed(gfp_mask))
> > > - alloc_flags = ALLOC_NO_WATERMARKS;
> > > + /*
> > > + * Distinguish requests which really need access to whole memory
> > > + * reserves from oom victims which can live with their own reserve
> > > + */
> > > + reserves = gfp_pfmemalloc_allowed(gfp_mask);
> > > + if (reserves) {
> > > + if (tsk_is_oom_victim(current))
> > > + alloc_flags = ALLOC_OOM;
> >
> > If reserves == true due to reasons other than tsk_is_oom_victim(current) == true
> > (e.g. __GFP_MEMALLOC), why dare to reduce it?
>
> Well the comment above tries to explain. I assume that the oom victim is
> special here. a) it is on the way to die and b) we know that something
> will be freeing memory on the background so I assume this is acceptable.
I was thinking about this some more. It is not that hard to achive the
original semantic. The code is slightly uglier but acceptable I guess
What do you think about the following?
---
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3510e06b3bf3..7ae0f6d45614 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3627,21 +3627,31 @@ static bool oom_reserves_allowed(struct task_struct *tsk)
return true;
}
-bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
+/*
+ * Distinguish requests which really need access to full memory
+ * reserves from oom victims which can live with a portion of it
+ */
+static inline int __gfp_pfmemalloc_flags(gfp_t gfp_mask)
{
if (unlikely(gfp_mask & __GFP_NOMEMALLOC))
- return false;
-
+ return 0;
if (gfp_mask & __GFP_MEMALLOC)
- return true;
+ return ALLOC_NO_WATERMARKS;
if (in_serving_softirq() && (current->flags & PF_MEMALLOC))
- return true;
- if (!in_interrupt() &&
- ((current->flags & PF_MEMALLOC) ||
- oom_reserves_allowed(current)))
- return true;
+ return ALLOC_NO_WATERMARKS;
+ if (!in_interrupt()) {
+ if (current->flags & PF_MEMALLOC)
+ return ALLOC_NO_WATERMARKS;
+ else if (oom_reserves_allowed(current))
+ return ALLOC_OOM;
+ }
- return false;
+ return 0;
+}
+
+bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
+{
+ return __gfp_pfmemalloc_flags(gfp_mask) > 0;
}
/*
@@ -3794,7 +3804,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
unsigned long alloc_start = jiffies;
unsigned int stall_timeout = 10 * HZ;
unsigned int cpuset_mems_cookie;
- bool reserves;
+ int reserves;
/*
* In the slowpath, we sanity check order to avoid ever trying to
@@ -3900,17 +3910,9 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
if (gfp_mask & __GFP_KSWAPD_RECLAIM)
wake_all_kswapds(order, ac);
- /*
- * Distinguish requests which really need access to whole memory
- * reserves from oom victims which can live with their own reserve
- */
- reserves = gfp_pfmemalloc_allowed(gfp_mask);
- if (reserves) {
- if (tsk_is_oom_victim(current))
- alloc_flags = ALLOC_OOM;
- else
- alloc_flags = ALLOC_NO_WATERMARKS;
- }
+ reserves = __gfp_pfmemalloc_flags(gfp_mask);
+ if (reserves)
+ alloc_flags = reserves;
/*
* Reset the zonelist iterators if memory policies can be ignored.
--
Michal Hocko
SUSE Labs
--
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-02 6:10 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 9:03 [PATCH 0/2] mm, oom: do not grant oom victims full memory reserves access Michal Hocko
2017-07-27 9:03 ` [PATCH 1/2] mm, oom: do not rely on TIF_MEMDIE for " Michal Hocko
2017-08-01 15:30 ` Tetsuo Handa
2017-08-01 16:52 ` Michal Hocko
2017-08-02 6:10 ` Michal Hocko [this message]
2017-08-03 1:39 ` Tetsuo Handa
2017-08-03 7:06 ` Michal Hocko
2017-08-03 8:03 ` Tetsuo Handa
2017-08-03 8:21 ` Michal Hocko
2017-08-02 8:29 ` [PATCH v2 " Michal Hocko
2017-08-03 9:37 ` Mel Gorman
2017-08-03 11:00 ` Michal Hocko
2017-08-03 12:22 ` Mel Gorman
2017-07-27 9:03 ` [PATCH 2/2] mm: replace TIF_MEMDIE checks by tsk_is_oom_victim Michal Hocko
2017-07-27 14:01 ` Tetsuo Handa
2017-07-27 14:08 ` Tetsuo Handa
2017-07-27 14:18 ` Michal Hocko
2017-07-27 14:45 ` Michal Hocko
2017-07-27 14:55 ` Roman Gushchin
2017-07-29 8:33 ` kbuild test robot
2017-07-31 6:46 ` Michal Hocko
2017-08-01 12:16 ` [PATCH 0/2] mm, oom: do not grant oom victims full memory reserves access Michal Hocko
2017-08-01 12:23 ` Roman Gushchin
2017-08-01 12:29 ` Michal Hocko
2017-08-01 12:42 ` Roman Gushchin
2017-08-01 12:54 ` Michal Hocko
2017-08-07 14:21 ` Michal Hocko
-- strict thread matches above, loose matches on Subject: below --
2017-08-10 7:50 [PATCH v2 " Michal Hocko
2017-08-10 7:50 ` [PATCH 1/2] mm, oom: do not rely on TIF_MEMDIE for " 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=20170802061022.GA25318@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).