Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3827035imd; Mon, 29 Oct 2018 13:02:21 -0700 (PDT) X-Google-Smtp-Source: AJdET5c3Ze6mfTUFikCBCtKue/S5xR9HWz50fifKWxuYTSEBOrnl1GdWnpTTM2fyBT3pl7M9WiG3 X-Received: by 2002:a17:902:700c:: with SMTP id y12-v6mr15580607plk.185.1540843341634; Mon, 29 Oct 2018 13:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540843341; cv=none; d=google.com; s=arc-20160816; b=HCVzLRN1/lceq6d4w7sFGDUDQRC/i4vxCWXcdeMcWS78A1qhYHwgjuj6g7cmuP/yGZ aabYuHkSGCShHDiIeDjUnjD44V+LOsV0XsC87u+0+NwFxGPr78Z4ahI/aTNIoQaTTC25 8AkLdRboWOh3ATJqyBu10EWEZYULpfiQ1rvPTdUJi3mFo6r+eo7l9+l8o5zH5PM+Mqzt mlyOvytsdr5DS8c/ei+fEEsNXCDDv+vgr7dTKVFUyKuA192PvnjjE6SxMROY+WXFLrJU oPZUTLeQx0xnnWFhAeFOzhHmWRaZoNnhnbuCz8JhsiJA0NTBuJL5Gy5Zca48KKJiyNcF dhNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=DB6pT+RAuv3Bcs3mcWxDTapTeILQ4C3TS2vnDSjssFU=; b=pmJNRgv9YYgmQoD1XDLqiiMj23jSqQvb0VrWqlNTgX8Glw+PFEif311+X0JuVqAB8F IGyy8iSCzSu6pVaOWtU6DLu6aYrATQzvynXH0Hwa7iowXESkC1f49rNx2TyDCJZHdy4N UdW6cKHWdsCLZMD2SproGVVCLQD6Zon52ukS3nMNvXNWM9caD0a9uVUTUekLTRPgIS/0 zULsovQHEbPr7fQPOIBHR69jr4j6s9oeYdtt8Ug//J8MoQhyA/wnfSZX5V+86JcQtn0f lIAUcxp1oLbhNQtpLFZiwNRDwZpjG6og/Axo3jVUY8Y2CXmDHvppZcDOxk7aWATI+Jf5 RvUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dRnLkJR3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id q15-v6si20988073pgg.477.2018.10.29.13.02.05; Mon, 29 Oct 2018 13:02:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dRnLkJR3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729663AbeJ3Evk (ORCPT + 99 others); Tue, 30 Oct 2018 00:51:40 -0400 Received: from mail-ua1-f68.google.com ([209.85.222.68]:35717 "EHLO mail-ua1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbeJ3Evk (ORCPT ); Tue, 30 Oct 2018 00:51:40 -0400 Received: by mail-ua1-f68.google.com with SMTP id d8so2552884ual.2 for ; Mon, 29 Oct 2018 13:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=DB6pT+RAuv3Bcs3mcWxDTapTeILQ4C3TS2vnDSjssFU=; b=dRnLkJR3RiL/L8PWOOaXIFtME6i4rzFIZMP/mFIRV5kIJbk865INS5STtepD1JZsDQ Jq5VSbZJAy9MJrTQhwoohLpDNNyJhoOXzWk1B7UXwTuzBG3qatisgGwgmgjQIH89ww7W AJtz/77p8mfFI2OTbWAr0XpXQSftJIEhU4pLnCNUaZbEQqpHFARRJts904nnIhiwTWs1 jKmbz9dt/Sz6Yt1ULc55LoW2hSRuIke5xd4ewYfCXvlMoyLv3UvZIVMZf1Wg9i9WZ+ju mTwMbdi5socClmSvlrmVUF5VYZJTQBhY9oAkbY/+GUYvLF3PuGhPlrBEeMqW2FGNOru4 StFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=DB6pT+RAuv3Bcs3mcWxDTapTeILQ4C3TS2vnDSjssFU=; b=gODzTDtQPttS5mgScxOoua3nWqE645owg+Y+8cy82BhpWg3EGTyvtE0yxaVcbdXT10 TeLXPIkaB+Qx6eUfm7EIR8fyBUm4fGLyHuZNZWEkMzHjROIwPiC99++RRDpSJIdPVQU+ 5yW5qWRCwC4szlFoWQGyOQrmW+N68f7TUTWQAA1+lk2pcR0w02xBMuS235MgPF9mB8Gz qgERnDMyyKRkxc+sMg/ZCo/hbEvG4etiQqcKrHkR00zM6J1daRwumSUtdU0/K2t0O8pX 545s0H6THmS15WGHd9hSDSQmKBkmlNjn6t2Iw+edDoZ+19fXjPlHz390E0uyqnHS72q7 58Mg== X-Gm-Message-State: AGRZ1gL6hN7ynmEGzMbYvg38GGQt1a1cgZ1+ufh2T3McrxPp3RoqlGNH bq7qoEuoIluHfGQ9dKXEfxO8yv/MIzup7nqImf1E0C0XCa4= X-Received: by 2002:ab0:15a1:: with SMTP id i30mr7139243uae.11.1540843288013; Mon, 29 Oct 2018 13:01:28 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:f492:0:0:0:0:0 with HTTP; Mon, 29 Oct 2018 13:01:27 -0700 (PDT) In-Reply-To: References: <20181029175322.189042-1-dancol@google.com> From: Daniel Colascione Date: Mon, 29 Oct 2018 20:01:27 +0000 Message-ID: Subject: Re: [RFC PATCH] Minimal non-child process exit notification support To: Joel Fernandes Cc: LKML , Tim Murray Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for taking a look. On Mon, Oct 29, 2018 at 7:45 PM, Joel Fernandes wrote: > > On Mon, Oct 29, 2018 at 10:53 AM Daniel Colascione wrote: > > > > This patch adds a new file under /proc/pid, /proc/pid/exithand. > > Attempting to read from an exithand file will block until the > > corresponding process exits, at which point the read will successfully > > complete with EOF. The file descriptor supports both blocking > > operations and poll(2). It's intended to be a minimal interface for > > allowing a program to wait for the exit of a process that is not one > > of its children. > > > > Why might we want this interface? Android's lmkd kills processes in > > order to free memory in response to various memory pressure > > signals. It's desirable to wait until a killed process actually exits > > before moving on (if needed) to killing the next process. Since the > > processes that lmkd kills are not lmkd's children, lmkd currently > > lacks a way to wait for a proces to actually die after being sent > > SIGKILL; today, lmkd resorts to polling the proc filesystem pid > > Any idea why it needs to wait and then send SIGKILL? Why not do > SIGKILL and look for errno == ESRCH in a loop with a delay. I want to get polling loops out of the system. Polling loops are bad for wakeup attribution, bad for power, bad for priority inheritance, and bad for latency. There's no right answer to the question "How long should I wait before checking $CONDITION again?". If we can have an explicit waitqueue interface to something, we should. Besides, PID polling is vulnerable to PID reuse, whereas this mechanism (just like anything based on struct pid) is immune to it. > > entry. This interface allow lmkd to give up polling and instead block > > and wait for process death. > > Can we use ptrace(2) for the exit notifications? I am assuming you > already though about it but I'm curious what is the reason this is > better. Only one process can ptrace a given process at a time, so I don't like ptrace as a mechanism for anything except debugging. Relying on ptrace for exit notification would interfere with things like debuggers and crash dump collection systems. Besides, ptrace can do too much (like read and write process memory) and so requires very strong privileges not necessary for this mechanism. Besides: ptrace's interface is complicated and relies on repeated calls to various wait functions, whereas the interface in this patch is simple enough to use from the shell.