Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3169416ybi; Mon, 29 Jul 2019 02:06:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWTwAQUVLTMG3mMJKxRnoQ0oV7wFuL8ZRYEA1kvtCSslQcVlcZF7WK7L4GOrU28lJSujWm X-Received: by 2002:a62:ae01:: with SMTP id q1mr34609391pff.219.1564391185605; Mon, 29 Jul 2019 02:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564391185; cv=none; d=google.com; s=arc-20160816; b=cQm9dk6oJt+EnZQVZfejXJlDfRSxfHQOAekxapgRjPSAocy81KCnNjh1VaSnOhmxRP MvZK6Cs+80acQMrV/UTPx23JmDanktjxRrtyxrcj5X/OieRqt77245zE7m9Oo55IkP/l iGknI9HYy1G1fqAuEFoCUX5qBgQrGgy4af47hqbwuIikkmScWOE9YnnYEky2CvFxffdj 9mPw1Q/NCuGxhwjId+J+kkEcQxKpCrFDHs/f+0rszfI8RB6JNF6iZWeWrKZvJJeSe7cz TH3H9dDzTONEI4mH+oKxZqVDE/3L25wAEuthZl8jwET6HZSkAkHo1zSBVqCcE3tt2RMt vNBg== 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:dkim-signature; bh=pf+2UYjQfUCcdua9fj0MZ+S5GX0o3D3g2pJePzx5CR0=; b=MGmd95qWbnbLCs3KPgaUVCQWoxT9jm4CqYRy6qpUjXoP2SpULUQaoT4Fo9qUpWRB8U Gf7X0QE4BeK9eS2H6JZTptbokzMJ500pTpELd1mUvePC5ULpny/GlgHSWHBQ0rryP0po 9ti2RLoJp9l/A2bwLikqU4RbTJFOO0RoAxjbyCFmqTgThndDwZOD4pyRdSYwBEMFvtzA elYkCjuiGIPGQAoh7mO81vTQDtfeo7G+HUvV9oI23aHNlAZomjO2oJKG40rrwlcKl/dr LRcFHe3kVT3lzF8Qf5617eS2CoHSGFgvDNjF8dG2TVOO7ORbpdDDURqgNdzLlmpXI0Ea sBHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DhA+b9MJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si23495930pls.7.2019.07.29.02.06.10; Mon, 29 Jul 2019 02:06:25 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=DhA+b9MJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbfG2Iwj (ORCPT + 99 others); Mon, 29 Jul 2019 04:52:39 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:40244 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbfG2Iwj (ORCPT ); Mon, 29 Jul 2019 04:52:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=pf+2UYjQfUCcdua9fj0MZ+S5GX0o3D3g2pJePzx5CR0=; b=DhA+b9MJh5Ib8+w6zn2x8quHB ZyZHgZxgg/XbKrTxiGtCQdpM3cFg4XGuYsMDAYnNrVczBl/2Nv7OFHSh+mcrrbRB3CsZUW9MHNNrt hxLc2PPXet0jIl6v/iEkqoNQGqGfjh2y6wIj0U9uL3tu+m+ytwxBJ6GUe3EncfUmZufDkAo9NBGTl tk1ndEyADAno6POFOsRX31WBYzBYNw8SnR0TvvLv5MI4xEuVt9ZdiwKIZep53qL6gP/2JyPineZHB 7mr0SiV2fMHTMuyUrgACn2WQ2kRcORbE35cNGZ0PgwyTi6s5FaS5unCDnbS+bUNiukNg0Fm7iyQvt +9mKJQu6w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hs1OX-0008Ot-Ss; Mon, 29 Jul 2019 08:52:38 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5ABA72025E7AD; Mon, 29 Jul 2019 10:52:35 +0200 (CEST) Date: Mon, 29 Jul 2019 10:52:35 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Phil Auld Subject: Re: [PATCH v2] sched/core: Don't use dying mm as active_mm of kthreads Message-ID: <20190729085235.GT31381@hirez.programming.kicks-ass.net> References: <20190727171047.31610-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190727171047.31610-1-longman@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 27, 2019 at 01:10:47PM -0400, Waiman Long wrote: > It was found that a dying mm_struct where the owning task has exited > can stay on as active_mm of kernel threads as long as no other user > tasks run on those CPUs that use it as active_mm. This prolongs the > life time of dying mm holding up memory and other resources like swap > space that cannot be freed. Sure, but this has been so 'forever', why is it a problem now? > Fix that by forcing the kernel threads to use init_mm as the active_mm > if the previous active_mm is dying. > > The determination of a dying mm is based on the absence of an owning > task. The selection of the owning task only happens with the CONFIG_MEMCG > option. Without that, there is no simple way to determine the life span > of a given mm. So it falls back to the old behavior. > > Signed-off-by: Waiman Long > --- > include/linux/mm_types.h | 15 +++++++++++++++ > kernel/sched/core.c | 13 +++++++++++-- > mm/init-mm.c | 4 ++++ > 3 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 3a37a89eb7a7..32712e78763c 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -623,6 +623,21 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm) > return atomic_read(&mm->tlb_flush_pending) > 1; > } > > +#ifdef CONFIG_MEMCG > +/* > + * A mm is considered dying if there is no owning task. > + */ > +static inline bool mm_dying(struct mm_struct *mm) > +{ > + return !mm->owner; > +} > +#else > +static inline bool mm_dying(struct mm_struct *mm) > +{ > + return false; > +} > +#endif > + > struct vm_fault; Yuck. So people without memcg will still suffer the terrible 'whatever it is this patch fixes'. > /** > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 2b037f195473..923a63262dfd 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3233,13 +3233,22 @@ context_switch(struct rq *rq, struct task_struct *prev, > * Both of these contain the full memory barrier required by > * membarrier after storing to rq->curr, before returning to > * user-space. > + * > + * If mm is NULL and oldmm is dying (!owner), we switch to > + * init_mm instead to make sure that oldmm can be freed ASAP. > */ > - if (!mm) { > + if (!mm && !mm_dying(oldmm)) { > next->active_mm = oldmm; > mmgrab(oldmm); > enter_lazy_tlb(oldmm, next); > - } else > + } else { > + if (!mm) { > + mm = &init_mm; > + next->active_mm = mm; > + mmgrab(mm); > + } > switch_mm_irqs_off(oldmm, mm, next); > + } > > if (!prev->mm) { > prev->active_mm = NULL; Bah, I see we _still_ haven't 'fixed' that code. And you're making an even bigger mess of it. Let me go find where that cleanup went.