linux_old1/drivers/misc/mic/scif
Michal Hocko 93065ac753 mm, oom: distinguish blockable mode for mmu notifiers
There are several blockable mmu notifiers which might sleep in
mmu_notifier_invalidate_range_start and that is a problem for the
oom_reaper because it needs to guarantee a forward progress so it cannot
depend on any sleepable locks.

Currently we simply back off and mark an oom victim with blockable mmu
notifiers as done after a short sleep.  That can result in selecting a new
oom victim prematurely because the previous one still hasn't torn its
memory down yet.

We can do much better though.  Even if mmu notifiers use sleepable locks
there is no reason to automatically assume those locks are held.  Moreover
majority of notifiers only care about a portion of the address space and
there is absolutely zero reason to fail when we are unmapping an unrelated
range.  Many notifiers do really block and wait for HW which is harder to
handle and we have to bail out though.

This patch handles the low hanging fruit.
__mmu_notifier_invalidate_range_start gets a blockable flag and callbacks
are not allowed to sleep if the flag is set to false.  This is achieved by
using trylock instead of the sleepable lock for most callbacks and
continue as long as we do not block down the call chain.

I think we can improve that even further because there is a common pattern
to do a range lookup first and then do something about that.  The first
part can be done without a sleeping lock in most cases AFAICS.

The oom_reaper end then simply retries if there is at least one notifier
which couldn't make any progress in !blockable mode.  A retry loop is
already implemented to wait for the mmap_sem and this is basically the
same thing.

The simplest way for driver developers to test this code path is to wrap
userspace code which uses these notifiers into a memcg and set the hard
limit to hit the oom.  This can be done e.g.  after the test faults in all
the mmu notifier managed memory and set the hard limit to something really
small.  Then we are looking for a proper process tear down.

[akpm@linux-foundation.org: coding style fixes]
[akpm@linux-foundation.org: minor code simplification]
Link: http://lkml.kernel.org/r/20180716115058.5559-1-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Acked-by: Christian König <christian.koenig@amd.com> # AMD notifiers
Acked-by: Leon Romanovsky <leonro@mellanox.com> # mlx and umem_odp
Reported-by: David Rientjes <rientjes@google.com>
Cc: "David (ChunMing) Zhou" <David1.Zhou@amd.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Mike Marciniszyn <mike.marciniszyn@intel.com>
Cc: Dennis Dalessandro <dennis.dalessandro@intel.com>
Cc: Sudeep Dutt <sudeep.dutt@intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Cc: Dimitri Sivanich <sivanich@sgi.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "Jérôme Glisse" <jglisse@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-22 10:52:44 -07:00
..
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
scif_api.c misc: mic: SCIF Fix scif_get_new_port() error handling 2018-08-05 16:29:11 +02:00
scif_debugfs.c misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_dma.c mm, oom: distinguish blockable mode for mmu notifiers 2018-08-22 10:52:44 -07:00
scif_epd.c misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_epd.h the rest of drivers/*: annotate ->poll() instances 2017-11-28 11:06:58 -05:00
scif_fd.c the rest of drivers/*: annotate ->poll() instances 2017-11-28 11:06:58 -05:00
scif_fence.c misc: mic: silence uninitialized variable warning 2016-04-30 13:53:19 -07:00
scif_main.c misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_main.h sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
scif_map.h misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_mmap.c misc: mic: scif: use vma_pages(). 2016-08-30 14:45:50 +02:00
scif_nm.c misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_nodeqp.c misc: mic: fix memory leak 2015-10-17 21:42:29 -07:00
scif_nodeqp.h misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_peer_bus.c misc: mic: SCIF RMA nodeqp and minor miscellaneous changes 2015-10-04 12:54:54 +01:00
scif_peer_bus.h misc: mic: Add support for kernel mode SCIF clients 2015-10-04 12:46:06 +01:00
scif_ports.c misc: mic: SCIF open close bind and listen APIs 2015-05-24 12:13:36 -07:00
scif_rb.c locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE() 2017-10-25 11:01:08 +02:00
scif_rb.h
scif_rma.c iommu/iova: Make dma_32bit_pfn implicit 2017-09-27 17:09:57 +02:00
scif_rma.h misc: mic: SCIF RMA header file 2015-10-04 12:54:54 +01:00
scif_rma_list.c locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE() 2017-10-25 11:01:08 +02:00
scif_rma_list.h misc: mic: SCIF RMA list operations 2015-10-04 12:54:54 +01:00