From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4641EC43460 for ; Wed, 21 Apr 2021 07:16:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8D016142F for ; Wed, 21 Apr 2021 07:16:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8D016142F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1C80B6B006C; Wed, 21 Apr 2021 03:16:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1667D6B006E; Wed, 21 Apr 2021 03:16:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 005F66B0070; Wed, 21 Apr 2021 03:16:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id DA8AD6B006C for ; Wed, 21 Apr 2021 03:16:19 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C11BE181AEF30 for ; Wed, 21 Apr 2021 07:16:18 +0000 (UTC) X-FDA: 78055515636.13.DE66CC6 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf11.hostedemail.com (Postfix) with ESMTP id E3B9A200024D for ; Wed, 21 Apr 2021 07:16:04 +0000 (UTC) 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: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E3B9A200024D X-Stat-Signature: yx7bmft9cgtn81gzf81e3pz9cgjncyx1 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618989364-436995 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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