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 25123C433FE for ; Tue, 8 Dec 2020 23:59:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9911423B5D for ; Tue, 8 Dec 2020 23:59:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9911423B5D 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 CBCB66B0036; Tue, 8 Dec 2020 18:59:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C45F66B005D; Tue, 8 Dec 2020 18:59:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0F7C6B0068; Tue, 8 Dec 2020 18:59:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 93ADE6B0036 for ; Tue, 8 Dec 2020 18:59:51 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5CDEB8249980 for ; Tue, 8 Dec 2020 23:59:51 +0000 (UTC) X-FDA: 77571785382.06.horse56_5d13d07273eb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 2D11210044BD6 for ; Tue, 8 Dec 2020 23:59:51 +0000 (UTC) X-HE-Tag: horse56_5d13d07273eb X-Filterd-Recvd-Size: 5683 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 23:59:50 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id y17so63292wrr.10 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=lYSs+yYIxAOCA8Sd9sBZT31sDFK2gCGV6lJtDuJIDTxroyzaNpGdW51V8okyh3mvoS ZoIpIyS4RLr7udWThj8vFpJ+3zjICieAdnDYnYBLTazMYhN8j104KV1hwrffzMu53fYQ siaZjTbBWrkcCHDFZiIlOzWLw5s+wec/G1h6k/EYBvse7en51cD7ugKoIqqS2kCX/xly hl78giZpUzfaTtVlNJcwGXPBj9tAiSbH1BR3bYheYyrr3QtPd5oqyvXsN8Dw1nTEEkOs Og1eBUuZozps8I7FzBvNNDJhW5fLIquimPHm3gI7iHTr+zf1LZnnqFGSfHpIa/tBIS5+ YIyQ== X-Gm-Message-State: AOAM5300DFqIrN0+huxfQRg7aYbYOUrjaK1/rTKqRzPS8jfY8zrx5pLN J1v0GHZJWQHTkiOEsWntIAdrkzkvCesjaGdNJLq7AA== X-Google-Smtp-Source: ABdhPJx/e96M5QxZfOV2yS34D1ceLVp3WIR5bIkqmCEwBy7gwJnwcD76VCWHfNTmg9pVDdfSVhJMj0viccbvch35sog= 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" 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, 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.