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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93080C433EF for ; Fri, 24 Jun 2022 09:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E54308E020C; Fri, 24 Jun 2022 05:59:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E02FF8E0205; Fri, 24 Jun 2022 05:59:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF1A18E020C; Fri, 24 Jun 2022 05:59:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C03EA8E0205 for ; Fri, 24 Jun 2022 05:59:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5592335457 for ; Fri, 24 Jun 2022 09:59:13 +0000 (UTC) X-FDA: 79612681386.26.85D77DD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf17.hostedemail.com (Postfix) with ESMTP id 8910040023 for ; Fri, 24 Jun 2022 09:59:12 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 29BB821A74; Fri, 24 Jun 2022 09:59:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1656064751; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YRx5MsPC3bOKBussEAACbRbCrT13pUlZg+D3y9hzeFQ=; b=k1jLteFpvAGft+ORFG/tzqlURXKLRNicj7+oUgUIuX8osjH4+RjNVm62/jfqHf/FKhN7zD JkM1/iDo+UtWtCT89LSvKZPXJRE/SPVqpxUdXuUhXgeFakRbgDUpIRPPRwwC/o9HRxOK/+ gqzcjpY9QSRIzgUY++eA0/TlwRk7dss= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D56122C1E2; Fri, 24 Jun 2022 09:59:10 +0000 (UTC) Date: Fri, 24 Jun 2022 11:59:10 +0200 From: Michal Hocko To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: Re: [RFC] Per file OOM-badness / RSS once more Message-ID: References: <20220624080444.7619-1-christian.koenig@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220624080444.7619-1-christian.koenig@amd.com> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656064752; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YRx5MsPC3bOKBussEAACbRbCrT13pUlZg+D3y9hzeFQ=; b=SEAGA3hZvqEoeG7n0XQNCbo08enREpuw+sJZhWnu6uk96rnzqBO0M6pAWQvIQ5iRYdwJfw +tXuJYiZ+mmU/CLjA3mop8mdGsL0T23Y2bogqMNLOUPFci9lKy0AhK4XOI4/JV65yoOOZR 0UGaIO29yLl6ib9wGnTpXv2/Br0uzLg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=k1jLteFp; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf17.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656064752; a=rsa-sha256; cv=none; b=JIKujPj93/pKJj8uwb8i3u8bKi/+8IqUfcLoASEJOo8w7hbUVKrWeU3QUNwEebor0zgd6B QMdRBdHhNyD5oPz0zf4yfLBIQVCXatH578bmcRNGhOL7um9bVoOA44MKF1c0PB2Ng/3a9J MYctnD3SoxvmnZNESmg+M4U8ABffVbg= X-Rspamd-Queue-Id: 8910040023 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=k1jLteFp; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf17.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: b1ti54ja8by9b4j376qz4qd9mouqz41i X-HE-Tag: 1656064752-121291 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 Fri 24-06-22 10:04:30, Christian König wrote: > Hello everyone, > > To summarize the issue I'm trying to address here: Processes can allocate > resources through a file descriptor without being held responsible for it. > > I'm not explaining all the details again. See here for a more deeply > description of the problem: https://lwn.net/ml/linux-kernel/20220531100007.174649-1-christian.koenig@amd.com/ > > With this iteration I'm trying to address a bunch of the comments Michal Hocko > (thanks a lot for that) gave as well as giving some new ideas. > > Changes made so far: > 1. Renamed the callback into file_rss(). This is at least a start to better > describe what this is all about. I've been going back and forth over the > naming here, if you have any better idea please speak up. > > 2. Cleanups, e.g. now providing a helper function in the fs layer to sum up > all the pages allocated by the files in a file descriptor table. > > 3. Using the actual number of allocated pages for the shmem implementation > instead of just the size. I also tried to ignore shmem files which are part > of tmpfs, cause that has a separate accounting/limitation approach. OK, this is better than the original approach there are still holes there though I am afraid. I am not sure your i_count hack is correct but that would be mostly an implementation detail. The scheme will over-account memory mapped files (including memfd). How much that matters will really differ. For the global OOM situations it is very likely that there will be barely any disk based page cache as it would be reclaimed by the time the oom killer is invoked. So this should be OK. Swap backed page cache (shmem and its users) is more tricky. It is swap bound and processes which map it will get "charged" in the form of swap entries while those which rely on read/write will just escape from the sight of the oom killer no matter how much memory they own via their shmem backed fd. This sounds rather serious to me and I hope I haven't missed anything subtle here that would keep those pages somehow visible. Anyway something to very carefully document. For the memcg OOM this gets even more tricky. Files can be shared among tasks accross memcgs. Something that is not really straightforward from the userspace POV because this is not strictly deterministic as first-one-first-charged logic is applied so a lot might depend on timing. This could also easily mean that a large part of the in memory state of the file is outside of the reclaim and therefore OOM scope of the memcg which is hitting the hard limit. This could result in tasks being killed just because they (co)operate on a large file outside of their memcg domain. To be honest I am not sure how big of a problem this would be in practice and the existing behavior has its own cons so to me it sounds like changing one set of deficiency with other. As we have discussed previously, there is unlikely a great solution but you a) need to document most prominent downsides so that people can at least see this is understood and documented behavior and b) think of the runaway situation wrt non mapped shmems memtioned above and see whether there is something we can do about that. -- Michal Hocko SUSE Labs