Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1277485 > unrolled thread
| Started by | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| First post | 2015-11-25 16:40 +0100 |
| Last post | 2015-11-27 16:10 +0100 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] vmscan: do not throttle kthreads due to too_many_isolated Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-11-25 16:40 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Vlastimil Babka <vbabka@suse.cz> - 2015-11-25 16:50 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-11-25 17:30 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-11-26 09:20 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Michal Hocko <mhocko@kernel.org> - 2015-11-27 14:00 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Vladimir Davydov <vdavydov@virtuozzo.com> - 2015-11-27 14:50 +0100
Re: [PATCH] vmscan: do not throttle kthreads due to too_many_isolated Michal Hocko <mhocko@kernel.org> - 2015-11-27 16:10 +0100
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Date | 2015-11-25 16:40 +0100 |
| Subject | [PATCH] vmscan: do not throttle kthreads due to too_many_isolated |
| Message-ID | <qyKkN-87J-13@gated-at.bofh.it> |
Block device drivers often hand off io request processing to kernel
threads (example: device mapper). If such a thread calls kmalloc, it can
dive into direct reclaim path and end up waiting for too_many_isolated
to return false, blocking writeback. This can lead to a dead lock if the
pages were isolated by processes performing memcg reclaim, because they
call wait_on_page_writeback upon encountering a page under writeback,
which will never finish if bio_endio is to be called by the kernel
thread stuck in the reclaimer, waiting for the isolated pages to be put
back.
I've never encountered such a dead lock on vanilla kernel, neither have
I tried to reproduce it. However, I faced it with an out-of-tree block
device driver, which uses a kernel thread for completing bios: the
kernel thread got stuck busy-checking too_many_isolated on the DMA zone,
which had only 3 inactive and 68 isolated file pages (2163 pages were
free); the pages were isolated by memcg processes waiting for writeback
to finish. I don't see anything that could prevent this in case of e.g.
device mapper.
Let's fix this problem by making too_many_isolated always return false
for kernel threads. Apart from fixing the possible dead lock in case of
the legacy cgroup hierarchy, this makes sense even if the unified
hierarchy is used, where processes performing memcg reclaim will never
call wait_on_page_writeback, because kernel threads might be responsible
for cleaning pages necessary for reclaim - BTW throttle_direct_reclaim
never throttles kernel threads for the same reason.
Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
---
mm/vmscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 9d553b07bb86..0f1318a52b23 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1457,7 +1457,7 @@ static int too_many_isolated(struct zone *zone, int file,
{
unsigned long inactive, isolated;
- if (current_is_kswapd())
+ if (current->flags & PF_KTHREAD)
return 0;
if (!sane_reclaim(sc))
--
2.1.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 | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2015-11-25 16:50 +0100 |
| Message-ID | <qyKuu-8c2-19@gated-at.bofh.it> |
| In reply to | #1277485 |
On 11/25/2015 04:36 PM, Vladimir Davydov wrote: > Block device drivers often hand off io request processing to kernel > threads (example: device mapper). If such a thread calls kmalloc, it can > dive into direct reclaim path and end up waiting for too_many_isolated > to return false, blocking writeback. This can lead to a dead lock if the Shouldn't such allocation lack __GFP_IO to prevent this and other kinds of deadlocks? And/or have mempools? PF_KTHREAD looks like a big hammer to me that will solve only one potential problem... -- 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] | [next] | [standalone]
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Date | 2015-11-25 17:30 +0100 |
| Message-ID | <qyL7c-gt-23@gated-at.bofh.it> |
| In reply to | #1277502 |
On Wed, Nov 25, 2015 at 04:45:13PM +0100, Vlastimil Babka wrote: > On 11/25/2015 04:36 PM, Vladimir Davydov wrote: > > Block device drivers often hand off io request processing to kernel > > threads (example: device mapper). If such a thread calls kmalloc, it can > > dive into direct reclaim path and end up waiting for too_many_isolated > > to return false, blocking writeback. This can lead to a dead lock if the > > Shouldn't such allocation lack __GFP_IO to prevent this and other kinds of > deadlocks? And/or have mempools? Not necessarily. loopback is an example: it can call grab_cache_write_begin -> add_to_page_cache_lru with GFP_KERNEL. > PF_KTHREAD looks like a big hammer to me that will solve only one > potential problem... This problem can result in processes hanging forever. Any ideas how this could be fixed in a better way? Thanks, Vladimir -- 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] | [next] | [standalone]
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Date | 2015-11-26 09:20 +0100 |
| Message-ID | <qyZWy-2oi-39@gated-at.bofh.it> |
| In reply to | #1277561 |
On Wed, Nov 25, 2015 at 07:27:57PM +0300, Vladimir Davydov wrote: > On Wed, Nov 25, 2015 at 04:45:13PM +0100, Vlastimil Babka wrote: > > On 11/25/2015 04:36 PM, Vladimir Davydov wrote: > > > Block device drivers often hand off io request processing to kernel > > > threads (example: device mapper). If such a thread calls kmalloc, it can > > > dive into direct reclaim path and end up waiting for too_many_isolated > > > to return false, blocking writeback. This can lead to a dead lock if the > > > > Shouldn't such allocation lack __GFP_IO to prevent this and other kinds of > > deadlocks? And/or have mempools? > > Not necessarily. loopback is an example: it can call > grab_cache_write_begin -> add_to_page_cache_lru with GFP_KERNEL. Anyway, kthreads that use GFP_NOIO and/or mempool aren't safe either, because it isn't an allocation context problem: the reclaimer locks up not because it tries to take an fs/io lock the caller holds, but because it waits for isolated pages to be put back, which will never happen, since processes that isolated them depend on the kthread making progress. This is purely a reclaimer heuristic, which kmalloc users are not aware of. My point is that, in contrast to userspace processes, it is dangerous to throttle kthreads in the reclaimer, because they might be responsible for reclaimer progress (e.g. performing writeback). Regarding side effects of this patch. Well, there aren't many kthreads out there, so I don't believe this can put the system under the risk of thrashing because of isolating too many reclaimable pages. Thanks, Vladimir > > > PF_KTHREAD looks like a big hammer to me that will solve only one > > potential problem... > > This problem can result in processes hanging forever. Any ideas how this > could be fixed in a better way? -- 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] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2015-11-27 14:00 +0100 |
| Message-ID | <qzqN3-2YK-1@gated-at.bofh.it> |
| In reply to | #1278063 |
On Thu 26-11-15 11:16:24, Vladimir Davydov wrote: > On Wed, Nov 25, 2015 at 07:27:57PM +0300, Vladimir Davydov wrote: > > On Wed, Nov 25, 2015 at 04:45:13PM +0100, Vlastimil Babka wrote: > > > On 11/25/2015 04:36 PM, Vladimir Davydov wrote: > > > > Block device drivers often hand off io request processing to kernel > > > > threads (example: device mapper). If such a thread calls kmalloc, it can > > > > dive into direct reclaim path and end up waiting for too_many_isolated > > > > to return false, blocking writeback. This can lead to a dead lock if the > > > > > > Shouldn't such allocation lack __GFP_IO to prevent this and other kinds of > > > deadlocks? And/or have mempools? > > > > Not necessarily. loopback is an example: it can call > > grab_cache_write_begin -> add_to_page_cache_lru with GFP_KERNEL. AFAIR loop driver reduces the gfp_maks via inode mapping. > Anyway, kthreads that use GFP_NOIO and/or mempool aren't safe either, > because it isn't an allocation context problem: the reclaimer locks up > not because it tries to take an fs/io lock the caller holds, but because > it waits for isolated pages to be put back, which will never happen, > since processes that isolated them depend on the kthread making > progress. This is purely a reclaimer heuristic, which kmalloc users are > not aware of. > > My point is that, in contrast to userspace processes, it is dangerous to > throttle kthreads in the reclaimer, because they might be responsible > for reclaimer progress (e.g. performing writeback). Wouldn't it be better if your writeback kthread did PF_MEMALLOC/__GFP_MEMALLOC instead because it is in fact a reclaimer so it even get to the reclaim. There way too many allocations done from the kernel thread context to be not throttled (just look at worker threads). -- 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] | [next] | [standalone]
| From | Vladimir Davydov <vdavydov@virtuozzo.com> |
|---|---|
| Date | 2015-11-27 14:50 +0100 |
| Message-ID | <qzrzr-3wF-3@gated-at.bofh.it> |
| In reply to | #1278792 |
On Fri, Nov 27, 2015 at 01:50:05PM +0100, Michal Hocko wrote: > On Thu 26-11-15 11:16:24, Vladimir Davydov wrote: > > On Wed, Nov 25, 2015 at 07:27:57PM +0300, Vladimir Davydov wrote: > > > On Wed, Nov 25, 2015 at 04:45:13PM +0100, Vlastimil Babka wrote: > > > > On 11/25/2015 04:36 PM, Vladimir Davydov wrote: > > > > > Block device drivers often hand off io request processing to kernel > > > > > threads (example: device mapper). If such a thread calls kmalloc, it can > > > > > dive into direct reclaim path and end up waiting for too_many_isolated > > > > > to return false, blocking writeback. This can lead to a dead lock if the > > > > > > > > Shouldn't such allocation lack __GFP_IO to prevent this and other kinds of > > > > deadlocks? And/or have mempools? > > > > > > Not necessarily. loopback is an example: it can call > > > grab_cache_write_begin -> add_to_page_cache_lru with GFP_KERNEL. > > AFAIR loop driver reduces the gfp_maks via inode mapping. Yeah, it does, missed that, thanks for pointing this out. But it doesn't really make much difference, because it still can get stuck in too_many_isolated, although it does reduce the chance of this happening. When I hit it, DMA only got 3 inactive file pages and 68 isolated file pages, as I mentioned in the comment to the patch, so even >> 3 wouldn't save us. > > > Anyway, kthreads that use GFP_NOIO and/or mempool aren't safe either, > > because it isn't an allocation context problem: the reclaimer locks up > > not because it tries to take an fs/io lock the caller holds, but because > > it waits for isolated pages to be put back, which will never happen, > > since processes that isolated them depend on the kthread making > > progress. This is purely a reclaimer heuristic, which kmalloc users are > > not aware of. > > > > My point is that, in contrast to userspace processes, it is dangerous to > > throttle kthreads in the reclaimer, because they might be responsible > > for reclaimer progress (e.g. performing writeback). > > Wouldn't it be better if your writeback kthread did PF_MEMALLOC/__GFP_MEMALLOC > instead because it is in fact a reclaimer so it even get to the reclaim. The driver we use is similar to loop. It works as a proxy to fs it works on top of. Allowing it to access emergency reserves would deplete them quickly, just like in case of plain loop. The problem is not about our driver, in fact. I'm pretty sure one can hit it when using memcg along with loop or dm-crypt for instance. > > There way too many allocations done from the kernel thread context to be > not throttled (just look at worker threads). What about throttling them only once then? diff --git a/mm/vmscan.c b/mm/vmscan.c index 97ba9e1cde09..9253f4531b9c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1578,6 +1578,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, /* We are about to die and free our memory. Return now. */ if (fatal_signal_pending(current)) return SWAP_CLUSTER_MAX; + + if (current->flags & PF_KTHREAD) + break; } lru_add_drain(); -- 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] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2015-11-27 16:10 +0100 |
| Message-ID | <qzsOS-4wM-23@gated-at.bofh.it> |
| In reply to | #1278805 |
On Fri 27-11-15 16:40:03, Vladimir Davydov wrote: > On Fri, Nov 27, 2015 at 01:50:05PM +0100, Michal Hocko wrote: > > On Thu 26-11-15 11:16:24, Vladimir Davydov wrote: [...] > > > Anyway, kthreads that use GFP_NOIO and/or mempool aren't safe either, > > > because it isn't an allocation context problem: the reclaimer locks up > > > not because it tries to take an fs/io lock the caller holds, but because > > > it waits for isolated pages to be put back, which will never happen, > > > since processes that isolated them depend on the kthread making > > > progress. This is purely a reclaimer heuristic, which kmalloc users are > > > not aware of. > > > > > > My point is that, in contrast to userspace processes, it is dangerous to > > > throttle kthreads in the reclaimer, because they might be responsible > > > for reclaimer progress (e.g. performing writeback). > > > > Wouldn't it be better if your writeback kthread did PF_MEMALLOC/__GFP_MEMALLOC > > instead because it is in fact a reclaimer so it even get to the reclaim. > > The driver we use is similar to loop. It works as a proxy to fs it works > on top of. Allowing it to access emergency reserves would deplete them > quickly, just like in case of plain loop. OK, I see. I thought it would be using only a very limited amount of memory for the writeback. > The problem is not about our driver, in fact. I'm pretty sure one can > hit it when using memcg along with loop or dm-crypt for instance. I am not familiar much with neither but from a quick look the loop driver doesn't use mempools tool, it simply relays the data to the underlaying file and relies on the underlying fs to write all the pages and only prevents from the recursion by clearing GFP_FS and GFP_IO. Then I am not really sure how can we guarantee a forward progress. The GFP_NOFS allocation might loop inside the allocator endlessly and so the writeback wouldn't make any progress. This doesn't seem to be only memcg specific. The global case would just replace the deadlock by a livelock. I certainly must be missing something here. > > There way too many allocations done from the kernel thread context to be > > not throttled (just look at worker threads). > > What about throttling them only once then? This still sounds way too broad to me and I am even not sure it solves the problem. If anything I think we really should make it specific only to those callers who are really required to make a forward progress. What about PF_LESS_THROTTLE? NFS is already using this flag for a similar purpose and we indeed do not throttle at few places during the reclaim. So I would expect current_may_throttle(current) check there although I must confess I have no idea about the whole condition right now. > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 97ba9e1cde09..9253f4531b9c 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -1578,6 +1578,9 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, > /* We are about to die and free our memory. Return now. */ > if (fatal_signal_pending(current)) > return SWAP_CLUSTER_MAX; > + > + if (current->flags & PF_KTHREAD) > + break; > } > > lru_add_drain(); > > -- > 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> -- 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