Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp152712pxy; Tue, 4 May 2021 21:43:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7I0LLi04TJwpFY25+TKFM+uJH2Jw54UqgXgJjjqDiCdAJ1J5ZOf/k/BVg4bQM560EIrkj X-Received: by 2002:a17:906:36d9:: with SMTP id b25mr25800615ejc.530.1620189822789; Tue, 04 May 2021 21:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620189822; cv=none; d=google.com; s=arc-20160816; b=nx0bSH+1i/nYch7YmLRCrOvZIXYUdYLE32RZH8FvPJ+NklBG++AUSZeS5Nw/F1e5Nl hLw/nV72zhY4yGfeZ2+1f6lztq4rZhb8RHCrMlTJwVh6pb1jDzX5VVUhcsK9tSFCZtA8 NEdlibxgti5NCcA7MzllSgCZ/wRuJcxEAZgyB4u2TlaMSyvGQAOoCdQdgWdcDFFTghrt m1NoscoG1MwVS6CYX5g6PFw80jJnhtCWLhx0vAfBHh/+MoK1r7pfabV9ojkt284bTPkm IlzMxw70pkHgXX2ly4Dl5R0Xlqe/Fgl6Zn/ETH7BoSW9zO17d1Tk99D5emEA2i5nEzt6 VWEw== 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=dpyffmzF28xsaxMRD2G97jPnI0ZZ1SR5Rjf3NGEtBIA=; b=Bt8/e2wfQbw4A5LjmhHYtSaF4z8nv/z42pY1591at5LrbYaUNxIvU0X0Bom+0EnHGo JPx/0N6BnCnVw9AxDFwBqu0pWeAucSRhDzLU4+sAefWTPOfXToB0gVsXRvavNWBwny5q A44BCRP3t0qG7V6gDmU8lVDZmcfkXJarCH8rw36Gs85i3nqvj/wYLqEkyQRPzxd/V2X4 k2W6tqBPBvnw6y+p1JvXyWomJbrSepLCwTPLWA9w8Q/FIOqHtJLZe67UvKBWA0h6f9DM SyQc/S4Ra+ohwAvytGTlDH7lu9Izll/EP5O6caGSadOZqKjb2cUohdJn1WAFLUjVsgdE aMjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WeyYZGSl; 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 n24si4038390ejd.654.2021.05.04.21.43.11; Tue, 04 May 2021 21:43:42 -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=WeyYZGSl; 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 S231592AbhEECqa (ORCPT + 99 others); Tue, 4 May 2021 22:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbhEECq3 (ORCPT ); Tue, 4 May 2021 22:46:29 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BF9C06174A for ; Tue, 4 May 2021 19:45:33 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id j10so407975lfb.12 for ; Tue, 04 May 2021 19:45:33 -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=dpyffmzF28xsaxMRD2G97jPnI0ZZ1SR5Rjf3NGEtBIA=; b=WeyYZGSlF4U/HwB/qVfj/2M1q/SsBc/SKWwZXb07+k3IHswE46B/RH47b+4Tq/22n6 cJqgiZYKFSa5CPgEvKu1v6InVgLl9uy97j0IGcSYidqkwZt6CFst4uMGSHPwu20HAKYq Srmc6a9Mbxc5pqZ3svXSYaZ5RtOwasDrY7ezpwc4tBuj53FCQ7EXSZovm0/gpUO9iwwZ su3SMw/cUk3m4xk7brfxW7WSf+TvhBnlJfhA51FDVlT9bJtegtxVRO1lbNIEX7//gEUN FRgRk4VDGYIxofh5nMP1MByGTUdj7rDMqT1gLLmVQXIUNvw57IUDi13+DvQbRNS+CFpc hdyQ== 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=dpyffmzF28xsaxMRD2G97jPnI0ZZ1SR5Rjf3NGEtBIA=; b=G6Bn+TRM9P9zIxk8h4CEcV5C+6I1Cc0j4FHzGjXpGhbHsdqN+zi06yTjLwR9wEs+v/ Sr46ECgPrZ+m9YU5WFwHU5uuMRbtTmUViB1A4XSDBsH5IfDRcVC4SJhmAX52vGl0Jnu0 06ErDBw2GIZ0oQxWzC57pto7wj44rXVpsoQZrIq9sLvJSSbFotPieFy+R+OHGR/OBFCP WsOZ79n45x6FY4e/tyRBPBLK7uzTzYo2vCqyo2eWhwQ2jp1mgTFCn+lRnK7wkUuYRMwc XT/gSNPwTOIFseyx15MSXRTSJo5qh2JzE8BJNzABvPHZKFFtP12pSuWCYCqGogp2LH1a yq3A== X-Gm-Message-State: AOAM53331OcrSFbOAqpDxh8I9rAp3resmaHly2XVXBY9I/OlqMEuJk+M QM3ZCN0fS4uaa7zXLFJZl4EScPdffVpJRV4/vdVRUg== X-Received: by 2002:a05:6512:208b:: with SMTP id t11mr16856183lfr.358.1620182731040; Tue, 04 May 2021 19:45:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shakeel Butt Date: Tue, 4 May 2021 19:45:19 -0700 Message-ID: Subject: Re: [RFC] memory reserve for userspace oom-killer To: Suren Baghdasaryan Cc: Michal Hocko , Johannes Weiner , Roman Gushchin , Linux MM , Andrew Morton , Cgroups , David Rientjes , LKML , Greg Thelen , Dragos Sbirlea , Priya Duraisamy Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 4, 2021 at 6:26 PM Suren Baghdasaryan wrote: > > On Tue, May 4, 2021 at 5:37 PM Shakeel Butt wrote: > > > > On Wed, Apr 21, 2021 at 7:29 AM Michal Hocko wrote: > > > > > [...] > > > > > What if the pool is depleted? > > > > > > > > This would mean that either the estimate of mempool size is bad or > > > > oom-killer is buggy and leaking memory. > > > > > > > > I am open to any design directions for mempool or some other way where > > > > we can provide a notion of memory guarantee to oom-killer. > > > > > > OK, thanks for clarification. There will certainly be hard problems to > > > sort out[1] but the overall idea makes sense to me and it sounds like a > > > much better approach than a OOM specific solution. > > > > > > > > > [1] - how the pool is going to be replenished without hitting all > > > potential reclaim problems (thus dependencies on other all tasks > > > directly/indirectly) yet to not rely on any background workers to do > > > that on the task behalf without a proper accounting etc... > > > -- > > > > I am currently contemplating between two paths here: > > > > First, the mempool, exposed through either prctl or a new syscall. > > Users would need to trace their userspace oom-killer (or whatever > > their use case is) to find an appropriate mempool size they would need > > and periodically refill the mempools if allowed by the state of the > > machine. The challenge here is to find a good value for the mempool > > size and coordinating the refilling of mempools. > > > > Second is a mix of Roman and Peter's suggestions but much more > > simplified. A very simple watchdog with a kill-list of processes and > > if userspace didn't pet the watchdog within a specified time, it will > > kill all the processes in the kill-list. The challenge here is to > > maintain/update the kill-list. > > IIUC this solution is designed to identify cases when oomd/lmkd got > stuck while allocating memory due to memory shortages and therefore > can't feed the watchdog. In such a case the kernel goes ahead and > kills some processes to free up memory and unblock the blocked > process. Effectively this would limit the time such a process gets > stuck by the duration of the watchdog timeout. If my understanding of > this proposal is correct, Your understanding is indeed correct. > then I see the following downsides: > 1. oomd/lmkd are still not prevented from being stuck, it just limits > the duration of this blocked state. Delaying kills when memory > pressure is high even for short duration is very undesirable. Yes I agree. > I think > having mempool reserves could address this issue better if it can > always guarantee memory availability (not sure if it's possible in > practice). I think "mempool ... always guarantee memory availability" is something I should quantify with some experiments. > 2. What would be performance overhead of this watchdog? To limit the > duration of a process being blocked to a small enough value we would > have to have quite a small timeout, which means oomd/lmkd would have > to wake up quite often to feed the watchdog. Frequent wakeups on a > battery-powered system is not a good idea. This is indeed the downside i.e. the tradeoff between acceptable stall vs frequent wakeups. > 3. What if oomd/lmkd gets stuck for some memory-unrelated reason and > can't feed the watchdog? In such a scenario the kernel would assume > that it is stuck due to memory shortages and would go on a killing > spree. This is correct but IMHO killing spree is not worse than oomd/lmkd getting stuck for some other reason. > If there is a sure way to identify when a process gets stuck > due to memory shortages then this could work better. Hmm are you saying looking at the stack traces of the userspace oom-killer or some metrics related to oom-killer? It will complicate the code. > 4. Additional complexity of keeping the list of potential victims in > the kernel. Maybe we can simply reuse oom_score to choose the best > victims? Your point of additional complexity is correct. Regarding oom_score I think you meant oom_score_adj, I would avoid putting more policies/complexity in the kernel but I got your point that the simplest watchdog might not be helpful at all. > Thanks, > Suren. > > > > > I would prefer the direction which oomd and lmkd are open to adopt. > > > > Any suggestions?