Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5513912ioo; Wed, 1 Jun 2022 07:07:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+T0GXkX7pvxAbE6HK73T8T3BrmHtr+0eWTGhCwzwJnamqc77kB+yd+4PWoeneXl+aTskZ X-Received: by 2002:a17:903:c3:b0:163:bfde:eec3 with SMTP id x3-20020a17090300c300b00163bfdeeec3mr45958plc.152.1654092457680; Wed, 01 Jun 2022 07:07:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654092457; cv=none; d=google.com; s=arc-20160816; b=lgVk1F2c9mD+3nmiwz4AdZOCLgn9iTemUOM9oQmkcY2hRoe7ffpAKFiiKGCF9Bllep QTM811XK17x/ZNQve6sMPuWJzZvmJXrn9Od8hhCqbiJ/UP/PUlOhZjTZCYJNqh3o3wlj fYxETZZO3F7HMura1CX2f+e6lt0/h5EBmNfBhjFuHPBFgmSwr+0ZJdUqVjftE+dZjBRw W4vuV4jqK8G3HtXq2XqVCYz3w2VGwLIzYZgt3GXPQ+eseTX/GF2GkD6p33rT+vlYJfI1 ranhfSw2/AMWc3tnYYCLpeNAg4VzJeRvMFJS/ylQbU4VKx+dbsnekd9cx/SaIeaFTkuq 88dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1kcpHZfon90bWFf3C0opWYOsOsDgVYWIWfKF1sbIHOg=; b=scUnmGPU0tYt42+rv8vAzcSBbwnl7M6qrMM7QtEYO62oyXGxcI7xaQLfmBOq9HUM1h q7F/iUTAbvvkJegn2PkMDgPZG7UQ/qRKG/Ti9vj2X3sgxhBqmQ3W4gZtfVP8MJP+YQNE DaqvwBQ3ud6yMlh8S3dPStDAeYal63ikoB30SIoQ3Frc8/bJvt7hh1CbZ4tVTdTmgcBN vlAkHlV4oltlh+3mw0Fyw1ThbCRMj3L5mX+q9NfRnFe4KrQm8BMIGYp3YrtAFbGSx6Vk MIfsVUl/1N7FBZhcpbpTG/RIOlGzjs9E20F40qZxpWPv8L6OOs0EKUfrh855IUw63e1h CDVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PzDb+I+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l14-20020a170902f68e00b0015823058edasi2686348plg.464.2022.06.01.07.07.16; Wed, 01 Jun 2022 07:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PzDb+I+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348284AbiEaWBG (ORCPT + 99 others); Tue, 31 May 2022 18:01:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348273AbiEaWBE (ORCPT ); Tue, 31 May 2022 18:01:04 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC7AE54005; Tue, 31 May 2022 15:01:03 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id c15-20020a9d684f000000b0060b097c71ecso10478654oto.10; 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=4K5uBr0uKC5fMJU8tMKYQaSj83q774YtxcwlIR9PmrdFIuHy0oCE4jQzQERuxW9UYX vatFnLMgawLC1Zor/J9p1609FF3XVglekoyxBMGyzhY7Lzs5DkRN4WHBizTm2ohoatuh AR8kt9KZOgnaXc5bMS1lFBsCr+MjDIo287c7iQizP3B6mGT+1ptt28bSovbkS5ztfA6d 3dgQGSdZBhgP/SfBm2BPAkold6vn4aFibRBDN34u5BSVXWLf33Uw8Pon9nU00gJMte6i qjcy1BvCmMwpoN2pXP7Z+N8z74CqIrkC226e9LVOlERUE2NQWyHL3kgCLxZWoSgMctkx NgMg== X-Gm-Message-State: AOAM530XF7ncc/WMnz5BiD/PJA6+y2TUy7ljfYIxy9U62zk5VwRg0i4H kxZLqnToe8IldBDKbUWs66FPz411TL1LiJMaKyk= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + 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 > >