Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1055812pxv; Thu, 1 Jul 2021 16:10:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAqqfggLWiz/YfNMymZyRxrf/IM0qK9JQzOWfsUTihkyz3S/PE87LbumPhmLybi7OO4Wq9 X-Received: by 2002:a05:6402:458:: with SMTP id p24mr2896980edw.142.1625181033890; Thu, 01 Jul 2021 16:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625181033; cv=none; d=google.com; s=arc-20160816; b=KQiKJUZ6+4UJEPLxiGBeieGhBJqdgV5oRfobrW33gXu3fdr2IpebVDNZbFEPQeaKoD 0N8PMkQo1ecGLRo+2W/bySUmvBCJLXFSTbHLWVfwMA9QTyq/eXWb+Oyt8PIbRlp0dK5s tN0D/W8E8GzPhNLeJVYaqtd76dB69LsGtqgabKaNmbOye3XOrnoX7ho1ckF1otpV/k7M azVsJFmRk7XvkNuGm8g8+9JMOETFxsAzcS24blJ1cZ9r+o7Hibs3aKowLr+ng6nZ5CoP TO9oaJDEqZt+5qQb0S5qRKUXjm7bbZcj/Y0FoCc3zskOqGkUE761kd7iRRXpRmEUbAzx YG1A== 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=JVFwhu0Nl1U9FivJTXYgbITws6r7aJBlzJ81RHuWBSo=; b=DYqH64LYOMYEABnM3M+GkoLlUikwD2j1l6RemHZ36+FrVZ/RG06lWejpyqSNG0Sgb3 Rd9Wd1IbJzoattspnF/9HBNt+s0upkna9VpeVEDJGuTGSJ0xsWoIrQVvQFZcl1cqjuKM xM4ZdbFyxEtBiC85qSyBnksgF1pPoQXZKQKdLZsjSb0lioIdYIsNqhZ/E0jEam72MRhx IJXUeU/4iCcj7cBFFrzBu4BJqcUI1jtrxYMYAvU3wqGfSsfNqML9P2Rz6vyIg1T/UtsO KiPvVjG3OLCLxkQYkzS/39sajqPP5x3YCI+9ZLsaxd5euStRMk1g1j6hLblapfuUylfz +cvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lYp1QR+V; 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 el8si1299010ejc.275.2021.07.01.16.10.10; Thu, 01 Jul 2021 16:10:33 -0700 (PDT) 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=lYp1QR+V; 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 S230006AbhGAXKp (ORCPT + 99 others); Thu, 1 Jul 2021 19:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232827AbhGAXKp (ORCPT ); Thu, 1 Jul 2021 19:10:45 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E4BC061764 for ; Thu, 1 Jul 2021 16:08:13 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id k184so13460027ybf.12 for ; Thu, 01 Jul 2021 16:08:13 -0700 (PDT) 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=JVFwhu0Nl1U9FivJTXYgbITws6r7aJBlzJ81RHuWBSo=; b=lYp1QR+VzXen7d2xJF2fbcLqhi1ay1+vCQpxCfKI+F1Y7rAEbyh89MNhAJooFga14A 2CH/m1K/T8X3/uyuzQjJDfWZHqlboXl4tsagwV7koZJU7jeAfOYCnWCgWa/O4R5fwY3k yYnfPUXeE/8aSQXjZhSXs6EvokPk/NMTM5PpcQaBWdcNl0Dl55TWRBjo3DMictyRffxP FNevKNKq8Ym1jcjlF+kQrzoOANVGeNb9pQxesajua1x+gbaUcYlzLUHWX9Mz/Ee+5Yf1 2ZFBoRILOFE+9MK5DbKOXMVrix+YZBY/am2DjjhmAb4abHoU+TtwSZ7pcjhIfuwthRJm tOjg== 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=JVFwhu0Nl1U9FivJTXYgbITws6r7aJBlzJ81RHuWBSo=; b=GBGO7PnaZ1GW/6Non3ihRCCj4pj+1+6GpkMezHb180c+mXzmQIKtqDtConEGdOE5XK 79bLi1KgrpNLA9DMrluGUQyTI+DLvLWPvXtDZP4qNSg81cqh3Nw2XrbIRacLqLlcjSV7 LroUze7IV2pxX/FNv1LICktcrwsoEeI+uYHbla+PwCzM8iadpR6G3ES6XgOZESIczqnu 1CdEkFhYjwmwg1mR/sOC7XZqr1I2CEoApDh3mPvkQnYPoLUkzv2nxgo0mvhjsFnwbdyN hB2jZ8Q09ttgbfaU9vWV9kU9lD8lMYuhB7xj65Rezq7F4dN1vRtOnxGIUyllPegpFkK6 5Sfw== X-Gm-Message-State: AOAM533iYXPJ1y9n0D8ZGZILGzWPWlV1o+aTwS7nfehtIp//dr/3hf05 tdyHLUuC76hSB2q8ic7vtnj3jSiB8vcg5TLQbpTIjg== X-Received: by 2002:a25:2341:: with SMTP id j62mr3050343ybj.190.1625180892125; Thu, 01 Jul 2021 16:08:12 -0700 (PDT) MIME-Version: 1.0 References: <20210623192822.3072029-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 1 Jul 2021 16:08:01 -0700 Message-ID: Subject: Re: [PATCH 1/1] mm: introduce process_reap system call To: Andy Lutomirski Cc: Andrew Morton , Michal Hocko , Michal Hocko , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Minchan Kim , Christian Brauner , Christoph Hellwig , Oleg Nesterov , David Hildenbrand , Jann Horn , Shakeel Butt , Tim Murray , Linux API , Linux-MM , LKML , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ) On Wed, Jun 30, 2021 at 5:46 PM Andy Lutomirski wrote: > > On Wed, Jun 30, 2021 at 11:51 AM Suren Baghdasaryan wrote: > > > > On Wed, Jun 30, 2021 at 11:26 AM Andy Lutomirski wrote: > > > > > > On Wed, Jun 23, 2021 at 12:28 PM 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. A mechanism to free resources of the target > > > > process in a more predictable way would improve system's ability to > > > > control its memory pressure. > > > > Introduce process_reap system call that reclaims memory of a dying process > > > > from the context of the caller. This way the memory in freed in a more > > > > controllable way with CPU affinity and priority of the caller. The workload > > > > of freeing the memory will also be charged to the caller. > > > > The operation is allowed only on a dying process. > > > > > > At the risk of asking a potentially silly question, should this just > > > be a file in procfs? > > > > Hmm. I guess it's doable if procfs will not disappear too soon before > > memory is released... syscall also supports parameters, in this case > > flags can be used in the future to support PIDs in addition to PIDFDs > > for example. > > Before looking more in that direction, a silly question from my side: > > why procfs interface would be preferable to a syscall? > > It avoids using a syscall nr. (Admittedly a syscall nr is not *that* > precious of a resource.) It also makes it possible to use a shell > script to do this, which is maybe useful. I see. Not really sure if the shell usage is a big usecase for this operation but let's see if more people like that approach. For my specific usecase one syscall (process_reap) is better than three syscalls (open, write, close) and the possibility to extend the functionality using flags might be of value for the future. > > --Andy