Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2294409imc; Tue, 12 Mar 2019 10:46:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpm3IYJCcOLcvSzMkOEXDLzbPDIUnd3Y3lcVFYWM/0DEPlDKYUUGaDca6nYL8HFXnI3KqJ X-Received: by 2002:a63:1766:: with SMTP id 38mr36288233pgx.204.1552412801510; Tue, 12 Mar 2019 10:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412801; cv=none; d=google.com; s=arc-20160816; b=ULCo7SF4rfPydGoOeWtjdKXKljeqLYAuPo5ZvxOQXtruWmvjt0+dwTdxpGj7yvypk6 6tKYTbjPA8WeKs97p6CP6Vpq/4fgLPabF1Jf0BC0EDHyxwh0fsaM1Lk64L39i+R+uol1 fwwJNnlYxNrjyAC4M9pdG9ZdPnG8bzDYK6EaE2JflMw2tEOQHX5ztXGYUH6yccDHvJwi f4I8qLb8xwPXsnm6SbMGEHpsPQq5InmZBJaDLF5Y77cmt6mdDK3oKy9m4B9GpQYTutkj v/V4iTWoJJijpVav4BFkzFw4Ol+gYQgicSNCeG3izj5gWfogpoKWXfKNpUFsmDghLr49 5DYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HccK+fYLtqpEZfMwiBe6D8C3e7wDwbf9WW50Z/PProI=; b=m5B/oJJq8mALLkcgiLbicXLf7QAJWBitN2/lUxfjKELSq2cvVrqebVFRyCWSW+pzKC xd9GxRqJphtTRRKj3SEUjAkQHs65cxAdROqVEBWOqnkoPli5ukKjOctq9xCZRbNuiUZq /td0Czyy6baOOwrUyBtiPY4koVpxScl/GS9jwUWhc+Dhw+POCF3S7PxqqPVv8znBgErK f1MONvmwb3unyYV8abWeUf7/xdTeSty4sHNKKo0ca7wr94n7nmYhJF3rNPGvTTA/S3HD W2ADcduPlxuuXXFPlGapfHmQoNuW7xn8p+8HsXoGOTxqyZbH6NmbzUjZ6dzcbHJh0JKl mcOA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi9si8272326plb.174.2019.03.12.10.46.24; Tue, 12 Mar 2019 10:46:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728960AbfCLRp2 (ORCPT + 99 others); Tue, 12 Mar 2019 13:45:28 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:36055 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbfCLRp0 (ORCPT ); Tue, 12 Mar 2019 13:45:26 -0400 Received: by mail-oi1-f194.google.com with SMTP id t206so2837019oib.3 for ; Tue, 12 Mar 2019 10:45:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HccK+fYLtqpEZfMwiBe6D8C3e7wDwbf9WW50Z/PProI=; b=UXNMbyYBza5sJEFoi1/vcgDkbRLTW1TfQ7IWFmCzFM9vheV8fRROMdOmbLAejVlrUp 9aSZfDWZvU/PVz+jnc2ofMq4GYdqNKDT5/4GcTtA3u8fcrpko5Gs2/KD//JeR49SlgSr hYer0d2p/b3AM1yQ8qvRW8CD1SbfFLdtlz0NRjEHUQz6xkWGL4QKM+CW5C/rdw7Fcz/3 it6oMNcPj7aBu6y1Fw8F38EOeFQQn1JJwAUPDoNEUpNKDtnqnnmp+Y+LydZxMvfI2lU5 bahUvBbQ4Xo/2rvZcDClJEVOdSGkC9n3Q7b7nJJPS7Dm4UUE4cRkLqciXDebAzrBy23+ X29w== X-Gm-Message-State: APjAAAVpPzP+4G5V7ZwlE3Gu2ens9gHpOvXjnNQmcce+Ifn7dEGV3sgy HE1Ycx6Eq7zZ8DpPeFJ5vu8= X-Received: by 2002:aca:6cc9:: with SMTP id h192mr2487951oic.161.1552412726061; Tue, 12 Mar 2019 10:45:26 -0700 (PDT) Received: from sultan-box.localdomain ([107.193.118.89]) by smtp.gmail.com with ESMTPSA id x3sm3536175otg.52.2019.03.12.10.45.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 10:45:25 -0700 (PDT) Date: Tue, 12 Mar 2019 10:45:20 -0700 From: Sultan Alsawaf To: Tim Murray Cc: Michal Hocko , Suren Baghdasaryan , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Ingo Molnar , Peter Zijlstra , LKML , devel@driverdev.osuosl.org, linux-mm Subject: Re: [RFC] simple_lmk: Introduce Simple Low Memory Killer for Android Message-ID: <20190312174520.GA9276@sultan-box.localdomain> References: <20190310203403.27915-1-sultan@kerneltoast.com> <20190311174320.GC5721@dhcp22.suse.cz> <20190311175800.GA5522@sultan-box.localdomain> <20190311204626.GA3119@sultan-box.localdomain> <20190312080532.GE5721@dhcp22.suse.cz> <20190312163741.GA2762@sultan-box.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 12, 2019 at 10:17:43AM -0700, Tim Murray wrote: > Knowing whether a SIGKILL'd process has finished reclaiming is as far > as I know not possible without something like procfds. That's where > the 100ms timeout in lmkd comes in. lowmemorykiller and lmkd both > attempt to wait up to 100ms for reclaim to finish by checking for the > continued existence of the thread that received the SIGKILL, but this > really means that they wait up to 100ms for the _thread_ to finish, > which doesn't tell you anything about the memory used by that process. > If those threads terminate early and lowmemorykiller/lmkd get a signal > to kill again, then there may be two processes competing for CPU time > to reclaim memory. That doesn't reclaim any faster and may be an > unnecessary kill. > ... > - offer a way to wait for process termination so lmkd can tell when > reclaim has finished and know when killing another process is > appropriate Should be pretty easy with something like this: diff --git a/include/linux/sched.h b/include/linux/sched.h index 1549584a1..6ac478af2 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1199,6 +1199,7 @@ struct task_struct { unsigned long lowest_stack; unsigned long prev_lowest_stack; #endif + ktime_t sigkill_time; /* * New fields for task_struct should be added above here, so that diff --git a/kernel/fork.c b/kernel/fork.c index 9dcd18aa2..0ae182777 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -435,6 +435,8 @@ void put_task_stack(struct task_struct *tsk) void free_task(struct task_struct *tsk) { + ktime_t sigkill_time = tsk->sigkill_time; + pid_t pid = tsk->pid; #ifndef CONFIG_THREAD_INFO_IN_TASK /* * The task is finally done with both the stack and thread_info, @@ -455,6 +457,9 @@ void free_task(struct task_struct *tsk) if (tsk->flags & PF_KTHREAD) free_kthread_struct(tsk); free_task_struct(tsk); + if (sigkill_time) + printk("%d killed after %lld us\n", pid, + ktime_us_delta(ktime_get(), sigkill_time)); } EXPORT_SYMBOL(free_task); @@ -1881,6 +1886,7 @@ static __latent_entropy struct task_struct *copy_process( p->sequential_io = 0; p->sequential_io_avg = 0; #endif + p->sigkill_time = 0; /* Perform scheduler related setup. Assign this task to a CPU. */ retval = sched_fork(clone_flags, p); diff --git a/kernel/signal.c b/kernel/signal.c index 5d53183e2..1142c8811 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1168,6 +1168,8 @@ static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struc } out_set: + if (sig == SIGKILL) + t->sigkill_time = ktime_get(); signalfd_notify(t, sig); sigaddset(&pending->signal, sig);