Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3243858imm; Tue, 17 Jul 2018 01:13:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcvhH0R6k2Y8i4oHu58/bBytYMx3IcsxRdwCO2+MsIw/jkzkAjNgMqK1cd3MNgyoFsxuqAp X-Received: by 2002:a17:902:1005:: with SMTP id b5-v6mr642882pla.207.1531815180909; Tue, 17 Jul 2018 01:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531815180; cv=none; d=google.com; s=arc-20160816; b=L80WIpfq6+G7OjhCYD2c+LHbVrF7toF2i+muCPkOsiJKNXc6scpZdFKsWq76GTmEfR imMovCJpb46J/gzdWW2iYiY4aYhrb+NMI/OSqWX2XezSUpz7kEE+pcOUrairD0Q70B5M oIZdjCe8+jksyBD5yblpHtA1upzN5NsQUgCD3JN1O3idS/Ebu+Zykyubm39zzXa3qUf/ 5gSaHOhruGBCXN7VVR6mWBv8eOhlu2jFpfV0+UBHx2NHMCwuhHaa0jFUHb5B1rDKVsHs skwh9X/SNWGge9TYCO35HyJfgjKx/q8/5GhWUE+PuO/Frfxx6+4LgMjzS9mW1hUmZDBc AVLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=ISS1mXMemjNYi2kFNhwL0h87ANC1LD2qoYNBXponAOE=; b=gz3ll8t2piwUvJLpYnMi0a5Xt+bqQ0Gm1hK8z5cgeErO4Qasp18sbuVEjGERz1uvCg B2yucnQ83cTyrPpAIkJPu63yX9+WZi3+EwxyCivbGj89JrmkUx2u7Py34QKAYuAivLIw vRE6BBH6+LZOxlVqpX5QgW5O0UJULq1ONLsvyjvmpKX6ZygU3Ntzqp5A/3gCdjXkSdte F+CQtcXcNVpsJ1db6dS0B3TaR/JYnAIqMvL3DaWp8KrZiFf9KuEplrK4TWML/SEmaK+h MiQc3c1/w/rzDSg6XXq9YAJ63d6+bvnZM5fr/PmLKt3+4lWn/LxRqUtIQUnXfSErqxlj PZ7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7-v6si310521pfj.245.2018.07.17.01.12.44; Tue, 17 Jul 2018 01:13:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729729AbeGQInc (ORCPT + 99 others); Tue, 17 Jul 2018 04:43:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:33150 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729621AbeGQInc (ORCPT ); Tue, 17 Jul 2018 04:43:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D1015AD1A; Tue, 17 Jul 2018 08:12:06 +0000 (UTC) Date: Tue, 17 Jul 2018 10:12:01 +0200 From: Michal Hocko To: Andrew Morton Cc: LKML , linux-mm@kvack.org, "David (ChunMing) Zhou" , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Alex Deucher , David Airlie , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Doug Ledford , Jason Gunthorpe , Mike Marciniszyn , Dennis Dalessandro , Sudeep Dutt , Ashutosh Dixit , Dimitri Sivanich , Boris Ostrovsky , Juergen Gross , =?iso-8859-1?B?Suly9G1l?= Glisse , Andrea Arcangeli , Felix Kuehling , kvm@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-rdma@vger.kernel.org, xen-devel@lists.xenproject.org, Christian =?iso-8859-1?Q?K=F6nig?= , David Rientjes , Leon Romanovsky Subject: Re: [PATCH] mm, oom: distinguish blockable mode for mmu notifiers Message-ID: <20180717081201.GB16803@dhcp22.suse.cz> References: <20180716115058.5559-1-mhocko@kernel.org> <20180716161249.c76240cd487c070fb271d529@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180716161249.c76240cd487c070fb271d529@linux-foundation.org> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 16-07-18 16:12:49, Andrew Morton wrote: > On Mon, 16 Jul 2018 13:50:58 +0200 Michal Hocko wrote: > > > From: Michal Hocko > > > > 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 fruid. __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 assume device driver developers are wondering "what does this mean > for me". As I understand it, the only time they will see > blockable==false is when their driver is being called in response to an > out-of-memory condition, yes? So it is a very rare thing. Yes, this is the case right now. Maybe we will grow other users in future. Those other potential users is the reason why I used blockable rather than oom parameter name. > Any suggestions regarding how the driver developers can test this code > path? I don't think we presently have a way to fake an oom-killing > event? Perhaps we should add such a thing, given the problems we're > having with that feature. The simplest way is to wrap an 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. > > 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. > > > > ... > > > > +static inline int mmu_notifier_invalidate_range_start_nonblock(struct mm_struct *mm, > > + unsigned long start, unsigned long end) > > +{ > > + int ret = 0; > > + if (mm_has_notifiers(mm)) > > + ret = __mmu_notifier_invalidate_range_start(mm, start, end, false); > > + > > + return ret; > > } > > nit, > > { > if (mm_has_notifiers(mm)) > return __mmu_notifier_invalidate_range_start(mm, start, end, false); > return 0; > } > > would suffice. Sure. Fixed > > > > ... > > > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -3074,7 +3074,7 @@ void exit_mmap(struct mm_struct *mm) > > * reliably test it. > > */ > > mutex_lock(&oom_lock); > > - __oom_reap_task_mm(mm); > > + (void)__oom_reap_task_mm(mm); > > mutex_unlock(&oom_lock); > > What does this do? There is no error to be returned here as the comment above explains * Nothing can be holding mm->mmap_sem here and the above call * to mmu_notifier_release(mm) ensures mmu notifier callbacks in * __oom_reap_task_mm() will not block. -- Michal Hocko SUSE Labs