From patchwork Thu Jan 18 16:47:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10173709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF0A360230 for ; Thu, 18 Jan 2018 16:49:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0481204FE for ; Thu, 18 Jan 2018 16:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94A3720952; Thu, 18 Jan 2018 16:49:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A6A4204FE for ; Thu, 18 Jan 2018 16:49:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8926D6E68F; Thu, 18 Jan 2018 16:49:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0072.outbound.protection.outlook.com [104.47.37.72]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA3E16E5B5; Thu, 18 Jan 2018 16:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Gq80lFheLSXLNloY4sMk7h/afh3hMPZNoB65r8WGcBM=; b=SpnUNBOdTK3ozdT4zsabXbh+z419hvHJlZ6GHkMiQ8w2/kXafnZBcgwXWasOjj5jMDE+eXcTV1WceXN50uPg6qt34z7R5S4h4LpZWjp/Y8HH+VFz5NI0ysClR7ezWeYNfCnrSoC6qpWNlEei6PTFHZHi93gfOCnwWe3p8n9A294= Received: from DM3PR12CA0081.namprd12.prod.outlook.com (10.161.151.153) by BN6PR1201MB0051.namprd12.prod.outlook.com (10.174.114.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 18 Jan 2018 16:49:18 +0000 Received: from CO1NAM03FT012.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::207) by DM3PR12CA0081.outlook.office365.com (2603:10b6:0:57::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Thu, 18 Jan 2018 16:49:18 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.17) by CO1NAM03FT012.mail.protection.outlook.com (10.152.80.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.345.12 via Frontend Transport; Thu, 18 Jan 2018 16:49:18 +0000 Received: from agrodzovsky-All-Series.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Thu, 18 Jan 2018 10:49:16 -0600 From: Andrey Grodzovsky To: , , , Subject: [PATCH 3/4] drm/gem: adjust per file OOM badness on handling buffers Date: Thu, 18 Jan 2018 11:47:51 -0500 Message-ID: <1516294072-17841-4-git-send-email-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516294072-17841-1-git-send-email-andrey.grodzovsky@amd.com> References: <1516294072-17841-1-git-send-email-andrey.grodzovsky@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(376002)(39380400002)(346002)(396003)(39860400002)(2980300002)(428003)(189003)(199004)(6666003)(2950100002)(97736004)(478600001)(106466001)(105586002)(72206003)(4326008)(51416003)(68736007)(76176011)(59450400001)(7696005)(2906002)(356003)(36756003)(48376002)(5660300001)(54906003)(53416004)(2201001)(8936002)(77096007)(305945005)(47776003)(110136005)(575784001)(86362001)(8676002)(316002)(81166006)(81156014)(104016004)(26005)(16586007)(50466002)(53936002)(50226002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0051; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT012; 1:DXdrSn5PoerUBMbHXqxqzLPp6eWZv9BYqFcVE2Tqdt2xMuLsRosTNhnGFSQ7imoxbgZV5US0CXNKp9bYD7uNe8D1xB72DQzShiV+IpkNB8k3dGdFO1OK/0+FZ7Aq1lYR X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 61be75ec-1e9d-4030-3f9c-08d55e936a7f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060); SRVR:BN6PR1201MB0051; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051;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ErfS6TAFfzwx3H9CBFfKQRBy9j9BMLlD8TveDM2h1p0NJwFpodbWFhnfQW9H6bkF7voNKtc5DD2WQi/tkgxRPnatOrpxkgZVS6vYXE+tHSeT69NoXyilHSTlqZicRYE67t62KIBzdytZMQpeBqJelSmoD4zyyQq2t4yoU+Ze9MfPKJRpuTU1ZTEpKRDEiBZaUOdHBQhw+FhlMKqKdmwyknWkoq6V7BFyYxZiBkYXYDLeckBhr6H9f5St3ifVZc9+S3uTaloQPMhx9jN53VvUdJoBHWnN9p7ucrXdoqO/U1Gbgl7tmhvGSokjsR6SWn9gj56GAijcVI8EGpH3sexyr97qaEH1BOzzU+lqk8WFP6EObFFB7FzXiZfCl9rVGDK13l6KKYjgO7XUpvT/BNObFgYbaqqFYS5TQvpjKkddxVPzv8gdu73pKkDT70xopzz1AyQTGnKx4rmrSNqNNaj4 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93003095)(3231023)(944501161)(3002001)(10201501046)(6055026)(6041268)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:BN6PR1201MB0051; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BN6PR1201MB0051; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051; 4:sg8OtXqCTzZG0GqNoww4j2xWd3gwqYQgOUC3jYuDB5hdB18McdKf415o31hnyoANUc0EPYBFEwYEJRazF/Z4Pr0IiFRzNw9Ke7mjjTpLHnlmg5d8m1hkQ53Ul0Uw00aP1Rm9ntLsAeOjlrOzx48DlmYsqvnxq6QmLCzHEQKW14l8Zo8RHs/VuX5WGSbAeIO1/sTPfXLJyAoQ2792WXtuZ8NbGM7t78ggVtgnjpbfCEQaNlTw+hMKs6HN8JDAi46QCwKPIR89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MyQi8Gr8tzxlFUAq1R7ySuG8xrHLFr4I7g=; 7:Umv5aNvo8fBpGJ2TwZ7vW86AP4Ja8W+IHwb8UYTPK2k5UoO+vw29LdzBLPXIGx6ITby8eNOAubiITu13oNp4ti8LSlnSwPoE71fxCt4gHOIWJ1dKA3MbsM92BkGdSs+74cBYRUG+stx6sLGS2eXGnYdk1VLljktiqd7qD8F54Uh0TaEBmyBpjkP460YJQekdNxPmLZd7DKX62DJsE0wUcaPzmKWD94zwVYvJB59WDrNpCDHs2F1t/cqgZu6xMeca SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0051; 20:eQurHGewbNuU+YZa09HQr+NM1pqKLAiEu/YB+h9ZtOHUj+2KAoGtKJ/DKT5GvSzAtbMB9tRHDCS8cuySNc/wkDHHmp9IaGEd55bN/yOXNNz9s0wpgoluSHlgrVyKeZoS8/HwntocgFIbTpFPXFb78xd20v9KxOcx3/Ympe4Hs0qvQT8hdkR6A4la+BQ7K718U5CW9XDE2uTO8J2hjYPT485qJ1b4TqKxETIFFTesudY8s508rg9MQOjGgKQP4iJ+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 16:49:18.0845 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61be75ec-1e9d-4030-3f9c-08d55e936a7f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0051 Cc: Christian.Koenig@amd.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Large amounts of VRAM are usually not CPU accessible, so they are not mapped into the processes address space. But since the device drivers usually support swapping buffers from VRAM to system memory we can still run into an out of memory situation when userspace starts to allocate to much. This patch gives the OOM another hint which process is holding how many resources. Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/drm_file.c | 12 ++++++++++++ drivers/gpu/drm/drm_gem.c | 8 ++++++++ include/drm/drm_file.h | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index b3c6e99..626cc76 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -747,3 +747,15 @@ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) spin_unlock_irqrestore(&dev->event_lock, irqflags); } EXPORT_SYMBOL(drm_send_event); + +long drm_oom_badness(struct file *f) +{ + + struct drm_file *file_priv = f->private_data; + + if (file_priv) + return atomic_long_read(&file_priv->f_oom_badness); + + return 0; +} +EXPORT_SYMBOL(drm_oom_badness); diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 01f8d94..ffbadc8 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -264,6 +264,9 @@ drm_gem_object_release_handle(int id, void *ptr, void *data) drm_gem_remove_prime_handles(obj, file_priv); drm_vma_node_revoke(&obj->vma_node, file_priv); + atomic_long_sub(obj->size >> PAGE_SHIFT, + &file_priv->f_oom_badness); + drm_gem_object_handle_put_unlocked(obj); return 0; @@ -299,6 +302,8 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle) idr_remove(&filp->object_idr, handle); spin_unlock(&filp->table_lock); + atomic_long_sub(obj->size >> PAGE_SHIFT, &filp->f_oom_badness); + return 0; } EXPORT_SYMBOL(drm_gem_handle_delete); @@ -417,6 +422,9 @@ drm_gem_handle_create_tail(struct drm_file *file_priv, } *handlep = handle; + + atomic_long_add(obj->size >> PAGE_SHIFT, + &file_priv->f_oom_badness); return 0; err_revoke: diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 0e0c868..ac3aa75 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -317,6 +317,8 @@ struct drm_file { /* private: */ unsigned long lock_count; /* DRI1 legacy lock count */ + + atomic_long_t f_oom_badness; }; /** @@ -378,4 +380,6 @@ void drm_event_cancel_free(struct drm_device *dev, void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e); void drm_send_event(struct drm_device *dev, struct drm_pending_event *e); +long drm_oom_badness(struct file *f); + #endif /* _DRM_FILE_H_ */