From patchwork Tue Feb 6 09:04:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10202505 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 DBE61601A1 for ; Tue, 6 Feb 2018 09:05:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D395228AB6 for ; Tue, 6 Feb 2018 09:05:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C81E228AC3; Tue, 6 Feb 2018 09:05:28 +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 3A03828ABB for ; Tue, 6 Feb 2018 09:05:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E1C5894DC; Tue, 6 Feb 2018 09:05:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0077.outbound.protection.outlook.com [104.47.42.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 69171894DC; Tue, 6 Feb 2018 09:05:26 +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=Iaujd61Td5+s1jHDy5p6m8eF/rJGbXosEbDhEMcKNeM=; b=gT5gvRzHXLR27yQgsr+fWyMLZh5pWPSeMOP1pv53p6xKs4GRieDGD7M3C3RuTWj7S5lDgat4jEbaGGASY2heVJKH68d2lEnu7e6THBzQGlWgsrJ+n4zYuDZK9TLUTZCDrNcYBDBnARQjf8HpcKsget5GhQGQMP8XhVAR5mRNCfg= Received: from DM5PR12CA0012.namprd12.prod.outlook.com (2603:10b6:4:1::22) by CY4PR12MB1447.namprd12.prod.outlook.com (2603:10b6:910:f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 09:05:24 +0000 Received: from CO1NAM03FT008.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::203) by DM5PR12CA0012.outlook.office365.com (2603:10b6:4:1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.464.11 via Frontend Transport; Tue, 6 Feb 2018 09:05:24 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; shipmail.org; dkim=none (message not signed) header.d=none; shipmail.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 CO1NAM03FT008.mail.protection.outlook.com (10.152.80.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.464.13 via Frontend Transport; Tue, 6 Feb 2018 09:05:23 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server id 14.3.361.1; Tue, 6 Feb 2018 03:05:09 -0600 From: Roger He To: , Subject: [PATCH 1/5] drm/ttm: check if the free swap space is under limit 256MB Date: Tue, 6 Feb 2018 17:04:30 +0800 Message-ID: <1517907874-21248-2-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517907874-21248-1-git-send-email-Hongbo.He@amd.com> References: <1517907874-21248-1-git-send-email-Hongbo.He@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)(39380400002)(376002)(39860400002)(396003)(346002)(2980300002)(428003)(189003)(199004)(7696005)(76176011)(104016004)(110136005)(48376002)(50466002)(105586002)(53936002)(4326008)(51416003)(575784001)(2906002)(81166006)(81156014)(47776003)(5660300001)(26005)(77096007)(59450400001)(54906003)(6666003)(8676002)(53416004)(86362001)(106466001)(68736007)(186003)(36756003)(8936002)(356003)(72206003)(316002)(305945005)(336011)(97736004)(2950100002)(16586007)(50226002)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1447; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT008; 1:kC3pTdJjlLHGPpEpcr/Iu4spskDxfRkmBrCEeO00fVG2mW7kvswjdEJHm5nFBSkB4ctAlOg+2eZo22JRBKl6qnhBsYHNsdRCXAs7Q2qJMZIlMk8MCPQEw56bd4Qvaebu X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8dd72409-8e65-47cc-857d-08d56d40c1dd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:CY4PR12MB1447; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1447; 3:AhHuI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7h8QJuY0qOuduYa6k+9lTeji3WVcuuNhvFIW1YN3YpbsnAmMvHBpSTPE2P71EAgeqDE1RzIx/dq66C7mpEeGOiZKZD8kZSb8ZNHruM+pwoi2enaJiQlW8eZniASJrqu73tXzsiaacbtHI1rgtfIoqbFsuK1DjDOFH1/759RERRorRF9k24YWRZg8jp0m7nbSjHe2vR7Tsnhz1ZyqwyNVwO7rN49oT2vYENjfuJIOXd8qzTBiuy11ThnaRd5czNjGt4I7GT71Q+Sqcmc7rp5PnzmlPV4g7S8qbxrS1uU6Ayb0iZEd0ZetYKHtPDX5Kqy1UeDVexTOx1zAKXvCbIJ/8TX6VcShO7s678q4bFvXvQ8L89EenD5uP7QIm8kVdpHtIKvZT7M/7Vnh0Y/v2NFqu77o0R+SPvDJEmcuDb5B42H8m9mTyc8JdUqyTQmwow2yhzquThn98+MWK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3002001)(3231101)(2400082)(944501161)(93006095)(93003095)(10201501046)(6055026)(6041288)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR12MB1447; BCL:0; PCL:0; RULEID:; SRVR:CY4PR12MB1447; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1447; 4:cYw6N+pRlT6vG3p+v/LcroZmqmxADHOiFn5Yt+ilUvNe7Kn/c5OStF7kzUbzAyNAbZDW+tcmBgbVPBhmeJ3Td0qu0IFh5wGJXn+3T5d5qKKc92bh0NxORG8Ux3U962dloFPQHoX4cyJ2GQauVCsPUS6NVR00WpVlupOmJ6a4FwoElCBY9QnAo6nxpZj1d76pNq+XQ8uIoeEQE0zj38tu4icC5eeDnUCeknllTlm7igxEFsbU+uL2Zq920HEvXW2B2ils+kJkB662etrSa2G3AZC8B8VQ4waSNdfDoAhZic3jMJhg4uNuskTjlKnXhoc1 X-Forefront-PRVS: 0575F81B58 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1447; 23:1FOp2Gx7cl7ZwoirCEnHeR2qX/KYo5NJoQXwd4Ro8?= =?us-ascii?Q?TNbsUiEFt7S4y7LFua3x5lvsmO479oqrhoHp4q7LxMcm7P903OzfI967z+S1?= =?us-ascii?Q?61/TQ56vrlCbuSbY429lIEEMGB5EJE1p7pMnFC/1TYOFhm33DLfXlPU93dvb?= =?us-ascii?Q?tG2vpDnAdKLTdXgf4j0M7tHuqvHcTPvdAjwP0nUoK1LSuPx51sWd3d5uQAte?= =?us-ascii?Q?xeHyR12efP6Nyd3pZ+M17CAf1weRYzKk8lipBqq8eVag4g6rjCNoGvvgpT4k?= =?us-ascii?Q?y9T3Znr2JFHMb9GfdZJthdckOgoi1YpOyoDE+Xns9/9TYIK+7+m/x40F9BLR?= =?us-ascii?Q?4916fD6sWV9I+iEsvlWhyTH9hFsOCkHFgef5fbcqblQQ3Ahb9Ufxiz/aiB1D?= =?us-ascii?Q?CPxogBIajIj63Uu1PIlHWo63m+xjjf1xUfAhd3olxJfn/XVLuadMjvfjb2MS?= =?us-ascii?Q?ibM5mGfwMwaae9n05eYZqsrJH9MltvAE3YsmuYGeal/pvFLwy0MRd8v248iW?= =?us-ascii?Q?Gp2K14Qop0WLoxAL7cSzTwWgSc5pWPjIpyKAN3RYWrv0MhOZATMBkVcvISji?= =?us-ascii?Q?2UQ1VcsqMD+wo4FVsxdyrxK8wIYC+1aLnPw9tgjJUIGWLCWbt7BHezMtmn7v?= =?us-ascii?Q?rp2t202cPFnyZM+JJTGU8ESphWi45zr3u2e5xSo3xC8p3XBATmEYTnnWmrcc?= =?us-ascii?Q?/15xTkUSsRjmpg2Vvzrphd/LTn4oo/c1W32wijtpgzO4sQLft0WkOVgu3ptL?= =?us-ascii?Q?q15Jc4eOZ5W7bG6b9uDYlvw5rCPm9PA5Psl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snXZksHqEg5k2klR9xKyasOQvQ0cg5ADZInhKiR9zZOdllp0=; 7:SdrGsa2nmf0iwMM1roj9/QgDPWbZUHGSShevbIPqdmYQz0wtPKDuF5ndMG1/+WypJTjMYP1MsMJ+MLyMYKiWa28NRTqq6MfJyzFLjZye933Lmj6580GgXBU/rtIYWUdCjgFPYZL9m7tfpTlJcjp74rYLMivYKtAXIploGRn8wE1hQtXv4kO1LpvDnAZX8hjsTYAza6QPJZC3miFr5yIJ+pkYiTJXZL3RxmFaeMbjDLRJS2iJnOmG5FtZr7bBKHQZ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1447; 20:hRzk/dIVzMkqN124x3V60qwXxcMlSaKexTQy0F5dGBh88cPJyjMkRQAyQpdHVuJI70P7VHcHwqJ/FLR+0vxxTg3C+93xZJqApYO0qiDok1kDFDimYyR1ELZIX3gH86DPEGvZ/Cl8XlTajCfE3+Bg2JfJjXBe6APwaig3jkDFNEv6xwAzUT9by+kcLFdl20xQATRwPjrSnRXYxCnVJIIY1zQafumx+/Lg9F9wV8+NXIypniYXUUqoX3uEHq8M6S07 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 09:05:23.8616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8dd72409-8e65-47cc-857d-08d56d40c1dd 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: CY4PR12MB1447 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roger He , Christian.Koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP for avoid OOM. if free swap space is less than 256MB, reject the TTM page allocation. Otherwise, swap space will be full of swapped pages and then system memory will be filled up with ttm pages. and then any memory allocation request will trigger OOM. to cover two cases: a. If total swap space > 256MB and at that time free swap space is under 256MB but available system mem > its lower limit, allow TTM allocation; b. if total swap space < 256 or no swap disk at all, check the available system mem, if it is bigger than its threshold, allow TTM allocation. Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_memory.c | 31 ++++++++++++++++++++++++++++++- include/drm/ttm/ttm_memory.h | 3 +++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index aa0c381..e19e727 100644 --- a/drivers/gpu/drm/ttm/ttm_memory.c +++ b/drivers/gpu/drm/ttm/ttm_memory.c @@ -36,6 +36,7 @@ #include #include #include +#include #define TTM_MEMORY_ALLOC_RETRIES 4 @@ -374,7 +375,8 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) } si_meminfo(&si); - + /* keep consistent with each zone->emer_mem */ + glob->sys_mem_limit = si.totalram >> 2; ret = ttm_mem_init_kernel_zone(glob, &si); if (unlikely(ret != 0)) goto out_no_zone; @@ -469,6 +471,30 @@ void ttm_mem_global_free(struct ttm_mem_global *glob, } EXPORT_SYMBOL(ttm_mem_global_free); + +#define FREE_SWAP_SPACE (256 << 8) +/* + * check if the free swap space is under limit 256MB. + * + * a. if free swap space is under 256MB but available system mem is + * bigger than its lower limit, allow TTM allocation; + * + * b. if no swap disk at all or less than 256MB at the beginning, check + * the available system mem, if bigger than its threshold, allow TTM + * allocation. + */ +static bool +ttm_check_over_swaplimit(struct ttm_mem_global *glob) +{ + bool ret = false; + + if (get_nr_swap_pages() < FREE_SWAP_SPACE + && si_mem_available() < glob->sys_mem_limit) + ret = true; + + return ret; +} + static int ttm_mem_global_reserve(struct ttm_mem_global *glob, struct ttm_mem_zone *single_zone, uint64_t amount, bool reserve) @@ -478,6 +504,9 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob, unsigned int i; struct ttm_mem_zone *zone; + if (ttm_check_over_swaplimit(glob)) + return ret; + spin_lock(&glob->lock); for (i = 0; i < glob->num_zones; ++i) { zone = glob->zones[i]; diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index 8936285..ad7cf63 100644 --- a/include/drm/ttm/ttm_memory.h +++ b/include/drm/ttm/ttm_memory.h @@ -49,6 +49,8 @@ * @work: The workqueue callback for the shrink queue. * @lock: Lock to protect the @shrink - and the memory accounting members, * that is, essentially the whole structure with some exceptions. + * @sys_mem_limit: if free ram is under this threshold and free swap space is + * less than its limit, reject any TTM allocation request * @zones: Array of pointers to accounting zones. * @num_zones: Number of populated entries in the @zones array. * @zone_kernel: Pointer to the kernel zone. @@ -67,6 +69,7 @@ struct ttm_mem_global { struct workqueue_struct *swap_queue; struct work_struct work; spinlock_t lock; + uint64_t sys_mem_limit; struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES]; unsigned int num_zones; struct ttm_mem_zone *zone_kernel;