Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp278701pxy; Wed, 21 Apr 2021 02:48:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIlqRUb+ofuk7fleRtNoQQM6rM+xXSR/XffLnDbIkw0VYx6ntySWuVtzcIZqSgQf4X52Uy X-Received: by 2002:a05:6402:51d0:: with SMTP id r16mr34060726edd.52.1618998492039; Wed, 21 Apr 2021 02:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618998492; cv=none; d=google.com; s=arc-20160816; b=lgf4j6vqlHNawMIw7ghHLBLdFkRG7n8AIbsvk8hHlFQPjw+SQyDPGkaspSPfcfQS/S i+wiUlBED1+XcmwrTzzrXZ7WAocbsAtQ+Nw2L1m6IIQKALlzqwqYJDgtAE79/poFCzKq 1VUTTVedlXg2wprPkB1TftGOnx9DZA/8Z2zVynzkBjHaO5ju5ZSzNtxjglqC5YK3v7gN M8VOeXbrPLwLldfM5LCPF1zZ9xmbJctVimo/Z5RCT3yKre6SV9WWsw0/FQTaR+9mOBpE K7VAEiM9TKUui9y7AzFXowklSRCg0gBMRgJQ9i0LPNIUjm86WZvyQRBP24Wkd1PbbO0N b0Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/t8yc2lQ3pLQ4sfUDYcnlZrhBPSE43fDoX7RlTCbrYU=; b=LnrTdNaUFAKTeR4Kp83bE6BEetmEqnONBAsZzxXjSyMxKUaolkPtbBps5Lav3aavwS xunbZVQRASPmbLuKdQyswnDm1/odEH90dHgs5pFeVVXUIpOTqqFfQAq/F5JG/lhJ61wU hrZ4b2PV0A6Dlp6HK/NvqLLmz8ORaU/lOVdIytBKloYEvm8Ntayr97bu3YzSpQdD6PYM 1ER2QIeeUFRdFp74zIE1gcXKqkbioN2KnJgTHMKybz1cPPPxukIYfkDmt0D7cFiCxNcu DouavL++XLuYGSGJcW7DXcR/agCoF4Uz+sYJUPNXZAtxdprYQkbOWBXuZT6DNkicDVv6 w38Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oz0tPCAn; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si1624144edc.166.2021.04.21.02.47.48; Wed, 21 Apr 2021 02:48:12 -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=@suse.com header.s=susede1 header.b=oz0tPCAn; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236438AbhDUHQx (ORCPT + 99 others); Wed, 21 Apr 2021 03:16:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:34748 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbhDUHQw (ORCPT ); Wed, 21 Apr 2021 03:16:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618989376; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/t8yc2lQ3pLQ4sfUDYcnlZrhBPSE43fDoX7RlTCbrYU=; b=oz0tPCAnFgexhSXdu2bypRgSNPkmuFx2oBUto0IsTOm7T3MUgl/JhML9WF6kinDHrFrVOJ IS5PbSD5CKpAsNC4PlCXPuwL+EcVCRnxa0oA0IGADjtUOAMQAdi/ymAjuKIk/ClNmYMU/+ v+8nf1NboN5d1MbJTAFteM/dOvHUqKo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3A005AEAC; Wed, 21 Apr 2021 07:16:16 +0000 (UTC) Date: Wed, 21 Apr 2021 09:16:15 +0200 From: Michal Hocko To: Shakeel Butt Cc: Johannes Weiner , Roman Gushchin , Linux MM , Andrew Morton , Cgroups , David Rientjes , LKML , Suren Baghdasaryan , Greg Thelen , Dragos Sbirlea , Priya Duraisamy Subject: Re: [RFC] memory reserve for userspace oom-killer Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 20-04-21 09:04:21, Shakeel Butt wrote: > On Mon, Apr 19, 2021 at 11:46 PM Michal Hocko wrote: > > > > On Mon 19-04-21 18:44:02, Shakeel Butt wrote: > [...] > > > memory.min. However a new allocation from userspace oom-killer can > > > still get stuck in the reclaim and policy rich oom-killer do trigger > > > new allocations through syscalls or even heap. > > > > Can you be more specific please? > > > > To decide when to kill, the oom-killer has to read a lot of metrics. > It has to open a lot of files to read them and there will definitely > be new allocations involved in those operations. For example reading > memory.stat does a page size allocation. Similarly, to perform action > the oom-killer may have to read cgroup.procs file which again has > allocation inside it. True but many of those can be avoided by opening the file early. At least seq_file based ones will not allocate later if the output size doesn't increase. Which should be the case for many. I think it is a general improvement to push those who allocate during read to an open time allocation. > Regarding sophisticated oom policy, I can give one example of our > cluster level policy. For robustness, many user facing jobs run a lot > of instances in a cluster to handle failures. Such jobs are tolerant > to some amount of failures but they still have requirements to not let > the number of running instances below some threshold. Normally killing > such jobs is fine but we do want to make sure that we do not violate > their cluster level agreement. So, the userspace oom-killer may > dynamically need to confirm if such a job can be killed. What kind of data do you need to examine to make those decisions? > [...] > > > To reliably solve this problem, we need to give guaranteed memory to > > > the userspace oom-killer. > > > > There is nothing like that. Even memory reserves are a finite resource > > which can be consumed as it is sharing those reserves with other users > > who are not necessarily coordinated. So before we start discussing > > making this even more muddy by handing over memory reserves to the > > userspace we should really examine whether pre-allocation is something > > that will not work. > > > > We actually explored if we can restrict the syscalls for the > oom-killer which does not do memory allocations. We concluded that is > not practical and not maintainable. Whatever the list we can come up > with will be outdated soon. In addition, converting all the must-have > syscalls to not do allocations is not possible/practical. I am definitely curious to learn more. [...] > > > 2. Mempool > > > > > > The idea is to preallocate mempool with a given amount of memory for > > > userspace oom-killer. Preferably this will be per-thread and > > > oom-killer can preallocate mempool for its specific threads. The core > > > page allocator can check before going to the reclaim path if the task > > > has private access to the mempool and return page from it if yes. > > > > Could you elaborate some more on how this would be controlled from the > > userspace? A dedicated syscall? A driver? > > > > I was thinking of simply prctl(SET_MEMPOOL, bytes) to assign mempool > to a thread (not shared between threads) and prctl(RESET_MEMPOOL) to > free the mempool. I am not a great fan of prctl. It has become a dumping ground for all mix of unrelated functionality. But let's say this is a minor detail at this stage. So you are proposing to have a per mm mem pool that would be used as a fallback for an allocation which cannot make a forward progress, right? Would that pool be preallocated and sitting idle? What kind of allocations would be allowed to use the pool? What if the pool is depleted? -- Michal Hocko SUSE Labs