Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3562754pxu; Tue, 8 Dec 2020 15:45:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJylQ+WVmbEGWDvmOMZ2FrP9eGJ9nmqMVZ8mfDChQQBrRY03Zfz5Sv4Cscj/r3WKGmGGdXmP X-Received: by 2002:a17:906:fb1a:: with SMTP id lz26mr126814ejb.194.1607471129684; Tue, 08 Dec 2020 15:45:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607471129; cv=none; d=google.com; s=arc-20160816; b=EN6S6Q30VXPEFp2sjH6NNpgJmpPDuYu03iRaengx0ATA8b2bRvpk+vwA5yooNekbif qKNATFyut7IPhuYbpcyQrf3oBoRlMuZX1sH+GlktSaLaInG34B/isExj94YPV3Yu6kof /rdksy/coIDsGP3FzhjMvnra8L9ck3PBy2reHqYBBjCH0/GUskfruhvepzcIj+bzT7GT nyAfe8HVq3VvOcadgjgndBPpshFIYIYS5rEBhc3iqB/8LdP5MxGcvoXp5sMildn1GUJ1 uSMz8aFgoTdrMQJCN1I2OXDAeU2xgA1b+h1Hul39tc+n6k8HxAUVeJULjOHTohzNG65g 6jbg== 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=SiRldqdmzeS1Mv5WIXPh/peTbx9BtSi92k54Z67KE4M=; b=aE1+MM6sRDFLvvyiKkVQf5xf4QePF1kJJmc43ftJ8YUu7koo3oe7iYLNp4QC1nKBhJ kuPPVDezGbz+wh+2x0qHw6GSQmyiG0hf+pBp+ZHCktCueiV7vIcHtYgMYNwv9TC5Ehhq wo1jhcQ5Xoiw4StnrT9RvAgoufIfRfqIJcMMPg353Ry0qotVKAmb2mM9ly/XFmVXmQwo DoZrBI7ffLvhCFLJsTmrxZ4BbuvUQj2I3u1eo84BaUEJ+++UVerG5CehEtSDXjKgfk6Y ydoCQS+Ev0JUiiuCmFGfZ7wZQ4VvPshuxTTsuI3ugKljkmWv9QM/1ZZvfm4Z20+vrXHR K6DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J8WFN1IB; 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 a24si36508edy.25.2020.12.08.15.45.07; Tue, 08 Dec 2020 15:45:29 -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=J8WFN1IB; 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 S1731718AbgLHXlb (ORCPT + 99 others); Tue, 8 Dec 2020 18:41:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbgLHXlb (ORCPT ); Tue, 8 Dec 2020 18:41:31 -0500 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E266C0613CF for ; Tue, 8 Dec 2020 15:40:50 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id m13so217463ljo.11 for ; Tue, 08 Dec 2020 15:40: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=SiRldqdmzeS1Mv5WIXPh/peTbx9BtSi92k54Z67KE4M=; b=J8WFN1IBnvwJjf12CXxBMDGUB3Y35X5pWzS6o8L22oagYz7MBuIqKJ8M3+uxSnnwBm Qu19kBkNmE+C0LfknE96xiDXXmhtG+u8kyfhxt8dQ593nkLH3ITnJMkIWnK14JzgSBby DCJOmGaR1qXvUi9NfH0pd00gvvLN3R8OAMXFHW7RKsD945aTqQzk+FRpyxj5XmZ02K7b H0ggvh86gYSgUGmJ/tlOgvZWXLYkifZ+Pjzy8ucCtSVXYw+IQZZRqkNq9yMsqRYHmWYt 9HJGf1WAYXzgov4yYFec1982+NIcdtZPBf8Sy/LRPsvlZ/P+y8WShE//ElA4TAFmLI+z ZzKQ== 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=SiRldqdmzeS1Mv5WIXPh/peTbx9BtSi92k54Z67KE4M=; b=mSqk8cYY/nRZxd5RFZLGYEkBCrwQeTmJH1wuB6wfkCa4KOghkv62Et2E3Keman0xL3 6JAr3t1c32fk/OjDrQSryUx/2iHNx16G9gUUbaRYa7f1Ul69vf/klzFOcr00gnWHjiz+ DJJ/AJRtQ7QDynevGqpHCaBZ+Xq7dsZgSLCg/GDAeZb7GbMdmNKz2Df7JF8pVdGvA8UB UDt/uRwzC9yzeE4e7XveonXcA+rvPWvfIEhyAETgURmkd54b3/kXL9ov/8atZRdEEyuW gENlVAGAkf+mzO2c+OSPUsK/NZHJI9kpTwugMtmU+vk/IjNOgwA8j9UEGQXTh+8Fz1u7 6+Rw== X-Gm-Message-State: AOAM533Hig/FBt3sYqV4M8wToCpMGqrLO1Bk3gPR8RKyu01Ea+3Iri4C FeacOrq7jnVFIU0XrT052qzysiRBz9d5t5xwnPPMTw== X-Received: by 2002:a2e:50c:: with SMTP id 12mr24546ljf.226.1607470848935; Tue, 08 Dec 2020 15:40:48 -0800 (PST) MIME-Version: 1.0 References: <20201124053943.1684874-1-surenb@google.com> <20201124053943.1684874-3-surenb@google.com> In-Reply-To: <20201124053943.1684874-3-surenb@google.com> From: Jann Horn Date: Wed, 9 Dec 2020 00:40:22 +0100 Message-ID: Subject: Re: [PATCH 2/2] mm/madvise: add process_madvise MADV_DONTNEER support To: Suren Baghdasaryan 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, 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.