From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD5F2C4361B for ; Tue, 8 Dec 2020 23:40:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6680823A7C for ; Tue, 8 Dec 2020 23:40:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6680823A7C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 909BA6B0036; Tue, 8 Dec 2020 18:40:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BA3C6B005D; Tue, 8 Dec 2020 18:40:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D0DD6B0068; Tue, 8 Dec 2020 18:40:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 67B646B0036 for ; Tue, 8 Dec 2020 18:40:51 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 327BD3626 for ; Tue, 8 Dec 2020 23:40:51 +0000 (UTC) X-FDA: 77571737502.12.bag31_090cc44273eb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 1269418017187 for ; Tue, 8 Dec 2020 23:40:51 +0000 (UTC) X-HE-Tag: bag31_090cc44273eb X-Filterd-Recvd-Size: 5119 Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 23:40:50 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id f24so201598ljk.13 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=jX9+qKIRqJrqgIr/QdMXVDru7edFWT2zD2+rREmJspR6epH+0tyn6qaRox96Vu4gPF g9TiRONmeM6PUbMBMFIdN2B2F+TBXX801+Z2Hk1ouqyrD4xSbozxTqY3rbvJsKSGfFh8 TMigtjD9Tt2HKFNFOwbdoK/u9w6xshuzuAz5qElGs3tou7Zd5newSHyfIpx4/3nh3y3s zyiTeu8vAfSBGaTNyp/xy2yxxJdRonp9xP+7kKIF5wL4IQYfWyj4cmphxtfU+SYUBqGy vdvXc1IxSdSQrJs3h7z5XTBn3NVOgCsFRekIrAw/Z8tzIcb2+uch8hRT4s303iH+r7vu RD1A== X-Gm-Message-State: AOAM532D/O4DpocF47nLwWrMsnYUmBUTt5Lnh6+UXN5V1KGEehyhc6tX 9yrlDCH2fNzF9ifo/HODpmoAsV2U3FXA3QDmMFiYFg== X-Google-Smtp-Source: ABdhPJzMw3FBB9dkB8UpPSjMu0vXES+Fd7QlsOOkEOw3dcInEyxdT6BtmJ4I838fJVgg/iRcwJCA3XFDJD8xaoO+mtg= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.