[PATCH -v2 -mm] memcg: do not trigger OOM fromadd_to_page_cache_locked

From: Michal Hocko
Date: Tue Nov 27 2012 - 15:54:32 EST


On Tue 27-11-12 14:48:13, Johannes Weiner wrote:
[...]
> > >diff --git a/include/linux/gfp.h b/include/linux/gfp.h
> > >index 10e667f..aac9b21 100644
> > >--- a/include/linux/gfp.h
> > >+++ b/include/linux/gfp.h
> > >@@ -152,6 +152,9 @@ struct vm_area_struct;
> > > /* 4GB DMA on some platforms */
> > > #define GFP_DMA32 __GFP_DMA32
> > >
> > >+/* memcg oom killer is not allowed */
> > >+#define GFP_MEMCG_NO_OOM __GFP_NORETRY
>
> Could we leave this within memcg, please? An extra flag to
> mem_cgroup_cache_charge() or the like. GFP flags are about
> controlling the page allocator, this seems abusive. We have an oom
> flag down in try_charge, maybe just propagate this up the stack?

OK, what about the patch bellow?
I have dropped Kame's Acked-by because it has been reworked. The patch
is the same in principle.

> > >diff --git a/mm/filemap.c b/mm/filemap.c
> > >index 83efee7..ef14351 100644
> > >--- a/mm/filemap.c
> > >+++ b/mm/filemap.c
> > >@@ -447,7 +447,13 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
> > > VM_BUG_ON(!PageLocked(page));
> > > VM_BUG_ON(PageSwapBacked(page));
> > >
> > >- error = mem_cgroup_cache_charge(page, current->mm,
> > >+ /*
> > >+ * Cannot trigger OOM even if gfp_mask would allow that normally
> > >+ * because we might be called from a locked context and that
> > >+ * could lead to deadlocks if the killed process is waiting for
> > >+ * the same lock.
> > >+ */
> > >+ error = mem_cgroup_cache_charge_no_oom(page, current->mm,
> > > gfp_mask & GFP_RECLAIM_MASK);
> > > if (error)
> > > goto out;
>
> Shmem does not use this function but also charges under the i_mutex in
> the write path and fallocate at least.

Right you are
---