Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3571866pxu; Tue, 8 Dec 2020 16:03:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkuVamuA+FHZPshJtu+ghMUvMke702eKAfXMEk+Q/hEE6AOfkjJNiZ5xlDwjuwQlXyq0Ka X-Received: by 2002:a50:9ea4:: with SMTP id a33mr407512edf.70.1607472201544; Tue, 08 Dec 2020 16:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607472201; cv=none; d=google.com; s=arc-20160816; b=yoFtG+uZ+WCDiwmVf0nqoKEOP+PDHLkF+k/l+rcDxYGa0fPeXdUu2F2YHg0JhJdJJB ubdeJs10+rZeK/VBw5JmXmPo9Nq45dmx6dUtmuZ7J+xajtwVfNmwSlJlIPFrxXdpj5r7 ssCRAfimkV5Fts/9WDt5cI5b7drfh7fCNi9j4TkF9/uMI1p/F9HEfgvOrrqI8jUzSJxJ ttLGXEt9D1/hsY6ChqApeLM+L3wqOHydqcH0hmX0Cyr12egk1RKkADZx/shOcVWSQ+TS z7MHh3euXe6LZvKLPlfjNEYfTWXeuhIa3ELrms6+2YIflt8KbtI7QratgJMKGZwjm+Pn aWiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jlUeL94EMQ2mw/JUtxwCrK3jcneUAYJBBgQnd4y+zNg=; b=VcaAt6/Bm3GJuMYaFgGEyfVjzBUW6MxDGwZp9B3S1Mox3zxoCC8a4q2j3XpCO0sYmi 07eGDOge4Kr5cA9SJKn7dy+WV9ffSGeclc8TUphK5iEPRFrVygOna9+HBmBKTs51w4yz DL2Nv2fK5uTG8qcT2p2h3385nAD4QvYBg8CqpOseeUZFKqJDNDjhLBvGRCsPuVlne6Wm 2Rp5fctrMl/ZiHS0Wuic3NSP2LwWUiBJZZSQ68L2Q6rKmBFTVMLiHeE9g3lqO6AGZ6ui GzfQg6pDG/iYaOHxWTmG/+aU7cRlLdt8mKgGZyUzWY4jaLeFXS7HlKgz7xDYhFtxw6Uh O7LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Edq1CVvP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si30302edj.165.2020.12.08.16.02.59; Tue, 08 Dec 2020 16:03:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Edq1CVvP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730770AbgLIAAb (ORCPT + 99 others); Tue, 8 Dec 2020 19:00:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730255AbgLIAAa (ORCPT ); Tue, 8 Dec 2020 19:00:30 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D070C0613CF for ; Tue, 8 Dec 2020 15:59:50 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id t4so54517wrr.12 for ; Tue, 08 Dec 2020 15:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jlUeL94EMQ2mw/JUtxwCrK3jcneUAYJBBgQnd4y+zNg=; b=Edq1CVvPQKilfg2eDpW2y/52GBtWVJoIisqFyyH4DiApGXBvGccrYZnb4ppeJREqR7 3PUoGbsEeb9wev7096enOgV+BT6P9oNUGTZUxnQdtg7eWts6tYgZ6nZ+e9ur/fIcajhX 5DqIYLAYauN54V4uaCEp5/EK0rMZB3AawHE/aQKf/+m5xxd3/3fiJECHLKADzmRb6/nz ugiCHzkpN7TbNyk6Cj+kZMQCQtZ6OAm8GCmKxlMA5ZuSiF3UDJbWKyeMwVhQp0Vr9dR6 ESYN4wHypyOw/kE4fXkrUhGE+dPCIwqLdKMnfujJLrDCjo2bBm7pAg7RqqOAIn8xUQVM 8isQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jlUeL94EMQ2mw/JUtxwCrK3jcneUAYJBBgQnd4y+zNg=; b=RiOLGsTpKOzNFpIzm8AytDduu0Ex8pOcN36HxsMdiS5918aYMd/PJjZxBV0GQcoQRt KOp6wEX/cleX/TFrEawQDPDePIq+ViZAaB3B1oXUqWpn8mqu+Evvlf6yFRk/sf0cCH/W 1w2+lI5FY8HcDul9azmVkQ541j2vvSIbURsNgJzVV9H9vrl7OIxlD1TzE9kK8BptJ72t Lhs77RXAARselFrgqh3/yiU33kTYJNTE5qJZntYGsLCrU3/TB1xuH0C0EiQIzIYYTCx2 N63lNtRYAjX1kZBCamJ849X/AYNUEpcGBfEq9hwpUm2oNY6z/61NrCXnJYNvdWws8FWV TP3A== X-Gm-Message-State: AOAM530f6GAmFyF+cEfpsw1P4HiniOpJEijLC1JTq5y+/HhU6CkVgn1V fA45vg4hridJwZswrVNY9nr0n20BkO1gIS3vTWIcqQ== X-Received: by 2002:a5d:51d2:: with SMTP id n18mr575805wrv.92.1607471989205; Tue, 08 Dec 2020 15:59:49 -0800 (PST) MIME-Version: 1.0 References: <20201124053943.1684874-1-surenb@google.com> <20201124053943.1684874-3-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 8 Dec 2020 15:59:38 -0800 Message-ID: Subject: Re: [PATCH 2/2] mm/madvise: add process_madvise MADV_DONTNEER support To: Jann Horn Cc: Andrew Morton , Michal Hocko , Michal Hocko , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Minchan Kim , Christian Brauner , Oleg Nesterov , Tim Murray , Linux API , Linux-MM , kernel list , kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 8, 2020 at 3:40 PM Jann Horn wrote: > > On Tue, Nov 24, 2020 at 6:50 AM Suren Baghdasaryan wrote: > > In modern systems it's not unusual to have a system component monitoring > > memory conditions of the system and tasked with keeping system memory > > pressure under control. One way to accomplish that is to kill > > non-essential processes to free up memory for more important ones. > > Examples of this are Facebook's OOM killer daemon called oomd and > > Android's low memory killer daemon called lmkd. > > For such system component it's important to be able to free memory > > quickly and efficiently. Unfortunately the time process takes to free > > up its memory after receiving a SIGKILL might vary based on the state > > of the process (uninterruptible sleep), size and OPP level of the core > > the process is running. > > In such situation it is desirable to be able to free up the memory of the > > process being killed in a more controlled way. > > Enable MADV_DONTNEED to be used with process_madvise when applied to a > > dying process to reclaim its memory. This would allow userspace system > > components like oomd and lmkd to free memory of the target process in > > a more predictable way. > > > > Signed-off-by: Suren Baghdasaryan > [...] > > @@ -1239,6 +1256,23 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > > goto release_task; > > } > > > > + if (madvise_destructive(behavior)) { > > + /* Allow destructive madvise only on a dying processes */ > > + if (!signal_group_exit(task->signal)) { > > + ret = -EINVAL; > > + goto release_mm; > > + } > > Technically Linux allows processes to share mm_struct without being in > the same thread group, so I'm not sure whether this check is good > enough? AFAICS the normal OOM killer deals with this case by letting > __oom_kill_process() always kill all tasks that share the mm_struct. Thanks for the comment Jann. You are right. I think replacing !signal_group_exit(task->signal) with task_will_free_mem(task) would address both your and Oleg's comments. IIUC, task_will_free_mem() calls __task_will_free_mem() on the task itself and on all processes sharing the mm_struct ensuring that they are all dying.