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 CB4FFC433F5 for ; Tue, 31 May 2022 22:01:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 355E86B0071; Tue, 31 May 2022 18:01:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 307096B0073; Tue, 31 May 2022 18:01:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA8F6B0074; Tue, 31 May 2022 18:01:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0C6B06B0071 for ; Tue, 31 May 2022 18:01:05 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id A830960676 for ; Tue, 31 May 2022 22:01:04 +0000 (UTC) X-FDA: 79527409248.12.0480A53 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by imf17.hostedemail.com (Postfix) with ESMTP id DFF8940069 for ; Tue, 31 May 2022 22:00:28 +0000 (UTC) Received: by mail-ot1-f49.google.com with SMTP id r12-20020a056830448c00b0060aec7b7a54so10490229otv.5 for ; Tue, 31 May 2022 15:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=1kcpHZfon90bWFf3C0opWYOsOsDgVYWIWfKF1sbIHOg=; b=PzDb+I+odIVJv+v3SJAjJiieVhfK9TLxSG7HEepT0URrxw1QQp7kRmiwJBPWRRavIc 4OMfjNbouVwJ9QQpQgLBXk6+QrfrsPci7ETu9MqS7ke/cmB5AaDwyt0mTTrETEI0nla8 ZoLP0cqrGh6Dw6Q5ps0yJtVdbye1Xjh4O23j3NOeVtWJfStBz4VKNrCPsD2YUn78wnbi Ukl+m69RJ4e1Q6zPLsNeTDpLPDG05ZQrka2NfxXfSb0vOdwt0Bvb0jIKeCOCB3zfJalh 4mvF/uQXHPN8cAyYKnxmvof/pxdnJb1AtX2kW5llJ/84g0tUGQEq+0RBuVEWhFw0MnUm /27Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1kcpHZfon90bWFf3C0opWYOsOsDgVYWIWfKF1sbIHOg=; b=Nk79Ao7hwkqsa0IDawSKfgmKzSElJ34mB0S9+2u3hl71hHlNmC5D+DmRfG3+W5YTNY N+3Lqoi4U1V7F5FfOumZK+sR6CxmP0H62ZVN5W1x8Kqj3cKHz/mCtCvuA4d1+GxviFnV vRBlDXOoKZM79386ilOyvWKdlYter/hr/wTQedSRHWDexwG4tsIFRIPaLj7PqKoMkztl rKkiInEI5UrQ5vkXR+OQ5Omh4da5s4vCoOaKuVdTSj/tGyswRjCthNlhNaVngl9M6/CY J+F6xOcxtxZIHdJJv3vigziV5ovMgfpSx1NTQJ8aZJsCZBnYXTkNjoKb88PpfV8Q81xL Xn1Q== X-Gm-Message-State: AOAM532Xr3aix6qwVdeDWYIaGHEMsf6JqIwE0jptWeTnbmHNQ3RZfJKc /7OtpBlb4tKzxzgBh6XjJqKwfBnNRfF8Ls6aVkA= X-Google-Smtp-Source: ABdhPJyKVYOkJ1d9Y7SW5ELtHTlhTKMcjbccQa1ILmaqZpJll1OzACOy0Pf6i7ZX6i42bY3GxbQOusF+tYcIkZKsQbg= X-Received: by 2002:a9d:6b98:0:b0:60b:c54:e22b with SMTP id b24-20020a9d6b98000000b0060b0c54e22bmr18226057otq.357.1654034462389; Tue, 31 May 2022 15:01:02 -0700 (PDT) MIME-Version: 1.0 References: <20220531100007.174649-1-christian.koenig@amd.com> In-Reply-To: <20220531100007.174649-1-christian.koenig@amd.com> From: Alex Deucher Date: Tue, 31 May 2022 18:00:51 -0400 Message-ID: Subject: Re: Per file OOM badness To: =?UTF-8?Q?Christian_K=C3=B6nig?= , Maling list - DRI developers Cc: linux-media , LKML , Intel Graphics Development , amd-gfx list , nouveau , linux-tegra@vger.kernel.org, Linux-Fsdevel , linux-mm , Andrey Grodzovsky , Hugh Dickens , Alexander Viro , Daniel Vetter , "Deucher, Alexander" , Andrew Morton , Christian Koenig Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: DFF8940069 X-Stat-Signature: xat6k17peufs8thepk79rpcpxkr3cd3o X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PzDb+I+o; spf=pass (imf17.hostedemail.com: domain of alexdeucher@gmail.com designates 209.85.210.49 as permitted sender) smtp.mailfrom=alexdeucher@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam08 X-HE-Tag: 1654034428-124211 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: + dri-devel On Tue, May 31, 2022 at 6:00 AM Christian K=C3=B6nig 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= . > > Especially for the DRM graphics driver subsystem this is rather > problematic. Modern games tend to allocate huge amounts of system memory > through the DRM drivers to make it accessible to GPU rendering. > > But even outside of the DRM subsystem this problem exists and it is > trivial to exploit. See the following simple example of > using memfd_create(): > > fd =3D memfd_create("test", 0); > while (1) > write(fd, page, 4096); > > Compile this and you can bring down any standard desktop system within > seconds. > > The background is that the OOM killer will kill every processes in the > system, but just not the one which holds the only reference to the memory > allocated by the memfd. > > Those problems where brought up on the mailing list multiple times now > [1][2][3], but without any final conclusion how to address them. Since > file descriptors are considered shared the process can not directly held > accountable for allocations made through them. Additional to that file > descriptors can also easily move between processes as well. > > So what this patch set does is to instead of trying to account the > allocated memory to a specific process it adds a callback to struct > file_operations which the OOM killer can use to query the specific OOM > badness of this file reference. This badness is then divided by the > file_count, so that every process using a shmem file, DMA-buf or DRM > driver will get it's equal amount of OOM badness. > > Callbacks are then implemented for the two core users (memfd and DMA-buf) > as well as 72 DRM based graphics drivers. > > The result is that the OOM killer can now much better judge if a process > is worth killing to free up memory. Resulting a quite a bit better system > stability in OOM situations, especially while running games. > > The only other possibility I can see would be to change the accounting of > resources whenever references to the file structure change, but this woul= d > mean quite some additional overhead for a rather common operation. > > Additionally I think trying to limit device driver allocations using > cgroups is orthogonal to this effort. While cgroups is very useful, it > works on per process limits and tries to enforce a collaborative model on > memory management while the OOM killer enforces a competitive model. > > Please comment and/or review, we have that problem flying around for year= s > now and are not at a point where we finally need to find a solution for > this. > > Regards, > Christian. > > [1] https://lists.freedesktop.org/archives/dri-devel/2015-September/08977= 8.html > [2] https://lkml.org/lkml/2018/1/18/543 > [3] https://lkml.org/lkml/2021/2/4/799 > >