Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4396372ybi; Tue, 30 Jul 2019 01:16:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxVHourDO7GdPln7MFi5c6UBMvBM8PvgcRxXRy+9VSqi0NnJU7oYMvcVcAAVWUaQpXH2nt X-Received: by 2002:aa7:93a8:: with SMTP id x8mr41994574pff.49.1564474583848; Tue, 30 Jul 2019 01:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564474583; cv=none; d=google.com; s=arc-20160816; b=qu1W3oFMES9j7k7RQbk0WROD5v3rK+3WKktu3uMpkBNwHsiMnMsxx0Mxz6ExNFQnxO lQqE6szUr6oM8Zz9iGufwZLGI1qcfd4hHv1fng7tMobPbKGtWThamxDo01v8+SIGj49/ ekfiIle+mepF5rtlAYySvWNJz6pUejFI4dENRL3+4s3OmP7xGZYeKCo0yga2sUcVpbbb E/pEcSVIwhHdWjAb5mTfMcylK3TlH8K+ZIyds2o+ovOV0KVqSjWtet3Jg2r3PTLqtR/t smubNcWV4agvmShlJqNPiiZvKIdRkkay1xwND16WPTabVb+h50d+VueTjKWnCwb/8Dp9 49QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=vA0RUcGnOsNwMHxKlpsyfm3KKPd5xhRHpuGm3uKT3t0=; b=zg44xBPuJGvLvsxxfe/sZHER+SDMWQzFCX3h6WGuOhucrIg3ZIZ/KEhf2x2nCugybg 744sSZOULRlSG9/jhlDuA432vHia4iuhNIWh8dGFZ4NRROI+7qaiJ+gFU5PoTsrn9mh3 LqH3w3BIM5GW1ke3yrPw80a3YITgDDynnchbD34/Tw2LN4hVFXyE3PinvymDFwSuw/FW +X0JnErmsLk6e1v36yCKL1wF6SIsJGZKd79hy9TgXQP6FOEcYIvRQaUo1/23uUnyC75l nr6U3M3VS7CNKiKIR1glgCkxlRU3fg0c7bJ2giqxLwzQd0sBsXXhrm2yXdl554cxvfKb tJmg== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si30561063pfn.43.2019.07.30.01.16.08; Tue, 30 Jul 2019 01:16:23 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729786AbfG2VmX (ORCPT + 99 others); Mon, 29 Jul 2019 17:42:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60134 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727681AbfG2VmX (ORCPT ); Mon, 29 Jul 2019 17:42:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D74D308FC47; Mon, 29 Jul 2019 21:42:23 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-160.bos.redhat.com [10.18.17.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7831260167; Mon, 29 Jul 2019 21:42:21 +0000 (UTC) Subject: Re: [PATCH v3] sched/core: Don't use dying mm as active_mm of kthreads To: Rik van Riel , Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Phil Auld , Michal Hocko References: <20190729210728.21634-1-longman@redhat.com> From: Waiman Long Organization: Red Hat Message-ID: <3e2ff4c9-c51f-8512-5051-5841131f4acb@redhat.com> Date: Mon, 29 Jul 2019 17:42:20 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 29 Jul 2019 21:42:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/29/19 5:21 PM, Rik van Riel wrote: > On Mon, 2019-07-29 at 17:07 -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 some resources that cannot be freed >> on a mostly idle system. > On what kernels does this happen? > > Don't we explicitly flush all lazy TLB CPUs at exit > time, when we are about to free page tables? There are still a couple of calls that will be done until mm_count reaches 0: - mm_free_pgd(mm); - destroy_context(mm); - mmu_notifier_mm_destroy(mm); - check_mm(mm); - put_user_ns(mm->user_ns); These are not big items, but holding it off for a long time is still not a good thing. > Does this happen only on the CPU where the task in > question is exiting, or also on other CPUs? What I have found is that a long running process on a mostly idle system with many CPUs is likely to cycle through a lot of the CPUs during its lifetime and leave behind its mm in the active_mm of those CPUs.  My 2-socket test system have 96 logical CPUs. After running the test program for a minute or so, it leaves behind its mm in about half of the CPUs with a mm_count of 45 after exit. So the dying mm will stay until all those 45 CPUs get new user tasks to run. > > If it is only on the CPU where the task is exiting, > would the TASK_DEAD handling in finish_task_switch() > be a better place to handle this? I need to switch the mm off the dying one. mm switching is only done in context_switch(). I don't think finish_task_switch() is the right place. -Longman