Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp476972yba; Fri, 12 Apr 2019 07:21:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjg2+Xs7//CEoerfjYkRxKUuy/esvV32xq95Qo/Ly2A6PVgzwIXlGrDmTM9dNh4AXCdpF/ X-Received: by 2002:aa7:9392:: with SMTP id t18mr57286421pfe.45.1555078903219; Fri, 12 Apr 2019 07:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555078903; cv=none; d=google.com; s=arc-20160816; b=u21pAc3mZIaD13fWbTrPojMuhgY1JDyAqmLYbdDAIlx6nsbTjOka2XdeIakRG7n1vO i2D0NgpNB8bilGAPHBANaYdAzqQFx4sC9pOmPbW+DG1PxEUmVEWCwKyEj2nCWkzXm0mY vvvLCqqtAnWSZQFdEd+ueDd56tZx1UmsQ+90cUp11Fv53VlVfbvB8xmaebhJBX+574L2 wKuaQo6+0zTeecnLgjBjw8OhreScE8ow9IKHj+4xsWde7Qu5nQeThB8SnfyDy7/huCX4 ZaE1oO7mXn8MmW8ncCHx4h7kAlv+VOYzk0N/0TgfUxqm91u52nHbX2E4zzGWKNkdbfYX FS/A== 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 :in-reply-to:references:mime-version:dkim-signature; bh=Hu0E9YTHRBKUOOI+2XbC7EkogUynbjLRnmfDiE1W9AI=; b=jQlWvzDLoyj0bk5bAxnzJamICkYq/vt/wFJboJ1DaTTGDedv7rcT5P50VFGh8v57ji Kkfe4vw4Eh02HT9XqTJv4ETOFXhb7rnnaWQZhSSAECjVvG8A/puybqSAp+gbsHckOgqr XzwtfJiafFI4PhzQQHTdocOFoUiGt5PbHZhjtzdkNT336yG4dSAB/UmU7zN6OWeF9jbP jyVOQz+bjGEueXd4Sl/r1GHe89frviJXon0+sprLySijQIsY5U2mHgTkHKTWW1TqHsJ0 geuvz79DTEm/65vz76ZirUY+LsJ493KtXahe8sNCzdBdNAeGOBiu/Bja+DTcX6ZvlTZo 3+Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=d6VGPVSD; 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 v4si36118733pgr.591.2019.04.12.07.21.26; Fri, 12 Apr 2019 07:21:43 -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=d6VGPVSD; 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 S1726952AbfDLOUf (ORCPT + 99 others); Fri, 12 Apr 2019 10:20:35 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:34323 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbfDLOUf (ORCPT ); Fri, 12 Apr 2019 10:20:35 -0400 Received: by mail-vk1-f193.google.com with SMTP id x84so2187501vkd.1 for ; Fri, 12 Apr 2019 07:20:34 -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=Hu0E9YTHRBKUOOI+2XbC7EkogUynbjLRnmfDiE1W9AI=; b=d6VGPVSDoYdeFeQh4b4EVL+visgZAsaKSJHQItQbuS36z4pY5JJiNCRw6zEW0NLzIp FlTGMYc13cootXo/0LS3ej4OnxDSTLfdEVcCX6k72HUOBruustw/yTNzyBuc4obvEbGG oBh38BVUFtC9FQeXcyFE0ZVe3TEfbAk1pBWb5JAEskeIhfnmlWmdU+X+D9M6wJu4i8iI slVu3Dg+Myc+S6KuxmDOofw0n0agj1Zo1HlODGQttpePEg4kyK4bY3IJnjklUmat35CT PxqlgNpzQ5SlyuRg13HOs8iYMHJnRoQXCoX5OYdMXhnH/RscD0347S3QJ4Q5Dq+HRNDO uAzg== 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=Hu0E9YTHRBKUOOI+2XbC7EkogUynbjLRnmfDiE1W9AI=; b=frJBK7bWRjUg+ILZiCEq5CET3KRHCrzWHZ/yjnXy+108c+FwbVF5FCedO5YTU/LZO8 jwxduHUE1dupPAZeTAvWfTosC6iBZoh/LynOP9I4mLgJuKYJzH9Nwg6z3a2lRpRLY7P3 NLb6m06Ma6Azad25iFjUm7SV8a9ne+6Jc1dZZuyri3pzsnKjl8pCSZCwxTE+UN9zMxFl nUcHh5MGldXZ63FwTNpG9eWIYTohhWg4Cu4PmzY+AL4VPYeDQwrmB3756FhfW7SuD7q7 jrmOFHTdBh0JKnxk8cXFf2fp36dGck1bobRjCIC9jsuNT61nbOy0lFK7zInmRYjLo3ZC 7SDg== X-Gm-Message-State: APjAAAV1RMsCXThrxXA3cTfoRusDu1JGwxoxomB1JxhhOjBSVPtPz2U4 zoyms+cTqxe6f6H42WurvhYSWzAiewYOQuknrHipcA== X-Received: by 2002:a1f:32c7:: with SMTP id y190mr32538150vky.15.1555078833745; Fri, 12 Apr 2019 07:20:33 -0700 (PDT) MIME-Version: 1.0 References: <20190411014353.113252-1-surenb@google.com> <20190411014353.113252-3-surenb@google.com> <20190411153313.GE22763@bombadil.infradead.org> <20190411173649.GF22763@bombadil.infradead.org> <20190412064925.GB13373@dhcp22.suse.cz> In-Reply-To: From: Daniel Colascione Date: Fri, 12 Apr 2019 07:20:21 -0700 Message-ID: Subject: Re: [RFC 2/2] signal: extend pidfd_send_signal() to allow expedited process killing To: Suren Baghdasaryan Cc: Michal Hocko , Matthew Wilcox , Andrew Morton , David Rientjes , yuzhoujian@didichuxing.com, Souptick Joarder , Roman Gushchin , Johannes Weiner , Tetsuo Handa , "Eric W. Biederman" , Shakeel Butt , Christian Brauner , Minchan Kim , Tim Murray , Joel Fernandes , Jann Horn , linux-mm , lsf-pc@lists.linux-foundation.org, LKML , kernel-team 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 On Fri, Apr 12, 2019 at 7:15 AM Suren Baghdasaryan wrote: > > On Thu, Apr 11, 2019 at 11:49 PM Michal Hocko wrote: > > > > On Thu 11-04-19 10:47:50, Daniel Colascione wrote: > > > On Thu, Apr 11, 2019 at 10:36 AM Matthew Wilcox wrote: > > > > > > > > On Thu, Apr 11, 2019 at 10:33:32AM -0700, Daniel Colascione wrote: > > > > > On Thu, Apr 11, 2019 at 10:09 AM Suren Baghdasaryan wrote: > > > > > > On Thu, Apr 11, 2019 at 8:33 AM Matthew Wilcox wrote: > > > > > > > > > > > > > > On Wed, Apr 10, 2019 at 06:43:53PM -0700, Suren Baghdasaryan wrote: > > > > > > > > Add new SS_EXPEDITE flag to be used when sending SIGKILL via > > > > > > > > pidfd_send_signal() syscall to allow expedited memory reclaim of the > > > > > > > > victim process. The usage of this flag is currently limited to SIGKILL > > > > > > > > signal and only to privileged users. > > > > > > > > > > > > > > What is the downside of doing expedited memory reclaim? ie why not do it > > > > > > > every time a process is going to die? > > > > > > > > > > > > I think with an implementation that does not use/abuse oom-reaper > > > > > > thread this could be done for any kill. As I mentioned oom-reaper is a > > > > > > limited resource which has access to memory reserves and should not be > > > > > > abused in the way I do in this reference implementation. > > > > > > While there might be downsides that I don't know of, I'm not sure it's > > > > > > required to hurry every kill's memory reclaim. I think there are cases > > > > > > when resource deallocation is critical, for example when we kill to > > > > > > relieve resource shortage and there are kills when reclaim speed is > > > > > > not essential. It would be great if we can identify urgent cases > > > > > > without userspace hints, so I'm open to suggestions that do not > > > > > > involve additional flags. > > > > > > > > > > I was imagining a PI-ish approach where we'd reap in case an RT > > > > > process was waiting on the death of some other process. I'd still > > > > > prefer the API I proposed in the other message because it gets the > > > > > kernel out of the business of deciding what the right signal is. I'm a > > > > > huge believer in "mechanism, not policy". > > > > > > > > It's not a question of the kernel deciding what the right signal is. > > > > The kernel knows whether a signal is fatal to a particular process or not. > > > > The question is whether the killing process should do the work of reaping > > > > the dying process's resources sometimes, always or never. Currently, > > > > that is never (the process reaps its own resources); Suren is suggesting > > > > sometimes, and I'm asking "Why not always?" > > > > > > FWIW, Suren's initial proposal is that the oom_reaper kthread do the > > > reaping, not the process sending the kill. Are you suggesting that > > > sending SIGKILL should spend a while in signal delivery reaping pages > > > before returning? I thought about just doing it this way, but I didn't > > > like the idea: it'd slow down mass-killing programs like killall(1). > > > Programs expect sending SIGKILL to be a fast operation that returns > > > immediately. > > > > I was thinking about this as well. And SYNC_SIGKILL would workaround the SYNC_SIGKILL (which, I presume, blocks in kill(2)) was proposed in many occasions while we discussed pidfd waits over the past six months or so. We've decided to just make pidfds pollable instead. The kernel already has several ways to express the idea that a task should wait for another task to die, and I don't think we need another. If you want a process that's waiting for a task to exit to help reap that task, great --- that's an option we've talked about --- but we don't need new interface to do it, since the kernel already has all the information it needs. > > current expectations of how quick the current implementation is. The > > harder part would what is the actual semantic. Does the kill wait until > > the target task is TASK_DEAD or is there an intermediate step that would > > we could call it end of the day and still have a reasonable semantic > > (e.g. the original pid is really not alive anymore). > > I think Daniel's proposal was trying to address that. With an input of > how many pages user wants to reclaim asynchronously and return value > of how much was actually reclaimed it contains the condition when to > stop and the reply how successful we could accomplish that. Since it > returns the number of pages reclaimed I assume the call does not > return until it reaped enough pages. Right. I want to punt as much "policy" as possible to userspace. Just using a user thread to do the reaping not only solves the policy problem (since it's userspace that controls priority, affinity, retries, and so on), but also simplifies the implementation kernel-side. I can imagine situations where, depending on device energy state or even charger or screen state we might want to reap more or less aggressively, or not at all. I wouldn't want to burden the kernel with having to get that right when userspace could make the decision.