Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp907083imm; Fri, 28 Sep 2018 08:42:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV63o5ebSyFJiGBM6tNiCPo0TZzjb5Ye5l7ZNxO9Bc/SY4aelMkH04eNKUrXYx794scv/+7dw X-Received: by 2002:a17:902:8347:: with SMTP id z7-v6mr16739789pln.147.1538149372128; Fri, 28 Sep 2018 08:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538149372; cv=none; d=google.com; s=arc-20160816; b=SHy/1K9m744LQffO7NbmjJZ253flcy5/fIK670yO5+rv4alVKgUMetmKZiOJzVih/H Hj9t+oG8txdoNACo2aaH152cGFFtTF7A5/XNzHUK577Gds3edd1ny5DEj5FiqBOTCQRC FExg7fA/Pox/iMuZ0Mpu2whn4IE+eGUMfgzJGUjlHzRU42zYogW8N/iIaOwBOcH7KsOR 3lFmKbNVZsrBMZGFyizMZWeK1MtEHCNAHyKFqEasUMrWDRwwdHNLOXxg8+NRkMDj1+lt bRSwUrYRf/ybFFnuB9vhC4s5bwRoRt1FBNSj4iuYztQKdckDwWjdEipHRWL5YEOu7ykF GiPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=RlTnCH/Rk1/Z6gMp2PPQVr7YL+OA2bvMwusW1mhkJSw=; b=k9W+YE1xBLdW1w4eu7vCxSaPKuddcepnUbxsVYC78O30TPNJ0wKLRPk9HqLqx3x6qQ v867fAGyOkIUUuq3rQbqLYjEXhJZSp5ScZBSdNp/RnkT/PWwbiTHMpj1DfPFH8I3G445 BOKLcqn4BoWS5Wo4zhn3bFNTsROWPk3kbJRZARKvdNTox9t4OkKPy2tQdPdl2BB0rCVs wVSiW9EhT2vwo/CJSHUVK5QolF9O4oZ7lTessbKND0AWG6DHbld44NBhHkO5l0R9rn4v wQNjRlcRU0gJJir8FiA1QGLcQ8U5eam9WGKGuiVowj0Q6YEEuocaw2cHL9UdutqPhOHh vADQ== 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 s26-v6si3186918pfj.226.2018.09.28.08.42.36; Fri, 28 Sep 2018 08:42:52 -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 S1729522AbeI1WGE (ORCPT + 99 others); Fri, 28 Sep 2018 18:06:04 -0400 Received: from www.llwyncelyn.cymru ([82.70.14.225]:34322 "EHLO fuzix.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728953AbeI1WGD (ORCPT ); Fri, 28 Sep 2018 18:06:03 -0400 Received: from alans-desktop (82-70-14-226.dsl.in-addr.zen.co.uk [82.70.14.226]) by fuzix.org (8.15.2/8.15.2) with ESMTP id w8SFfgXA016685; Fri, 28 Sep 2018 16:41:43 +0100 Date: Fri, 28 Sep 2018 16:41:42 +0100 From: Alan Cox To: Marcus Linsner Cc: linux-kernel@vger.kernel.org Subject: Re: Howto prevent kernel from evicting code pages ever? (to avoid disk thrashing when about to run out of RAM) Message-ID: <20180928164142.715ea2a1@alans-desktop> In-Reply-To: References: Organization: Intel Corporation X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 Aug 2018 11:25:35 +0200 Marcus Linsner wrote: > Hi. How to make the kernel keep(lock?) all code pages in RAM so that > kswapd0 won't evict them when the system is under low memory > conditions ? > > The purpose of this is to prevent the kernel from causing lots of disk > reads(effectively freezing the whole system) when about to run out of > RAM, even when there is no swap enabled, but well before(in real time > minutes) OOM-killer triggers to kill the offending process (eg. ld)! Having no swap is not helping you at all. In Linux you can do several things. Firstly add some swap - even a swap file because if you have no swap you fill up memory with pages that are not backed by disk and the kernel has to pick less and less optimal things to swap out so begins to thrash. Even slowish swap is better than no swap as it can dump out little used data pages. You can tune the OOM killer to taste and you can even guide it on what to shoot first. You can use cgroups to constrain the resources some group of things are allowed to use. You can play with no overcommit mode, although that is much more about 'cannot fail' embedded applications usually. In that mode the kernel tightly constrains the resource overcommit permissible. It's very conservative and you end up needing a lot of 'just in case' wasted resource, although you can tune the amount you leverage the real resources. To be fair Linux *is* really bad at handling this case. What other systems did (being older and from the days where RAM wasn't reasonably assumed infinite) was two fold. The first was under high swap load to switch to swapping out entire processes, which with all the shared resources and fast I/O today isn't quite so relevant. The second was that it would ensure a process got a certain amount of real CPU time before it's pages could be booted out again (and would then boot out lots of them). That turns the thrashing into forward progress but still feels unpleasant. However you still need swap or you don't have anywhere to boot out all the dirty non code pages in order to manage progress. There is a reason swap exists. If you don't have enough RAM to run smoothly without swap, add swap (or RAM). Even then some things usually need swap - I've got things that make the compiler consume over 16GB building one file. With swap it's fine even on a 4GB machine. Alan