From patchwork Fri Feb 9 10:00:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "He, Hongbo" X-Patchwork-Id: 10208713 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 E2602602D8 for ; Fri, 9 Feb 2018 10:01:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDD5929819 for ; Fri, 9 Feb 2018 10:01:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B241F2981F; Fri, 9 Feb 2018 10:01:42 +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 A98CB29819 for ; Fri, 9 Feb 2018 10:01:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED1D86E7B3; Fri, 9 Feb 2018 10:01:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0065.outbound.protection.outlook.com [104.47.34.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8D83D6E7BD for ; Fri, 9 Feb 2018 10:01:39 +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=Ir3IRarUrVcHaYcpfByX27rdK4fvh8Tm3A3miFDDa7g=; b=nlroY9McoLCnP+84O/m3wZpmetrGvi3bbOQ23IgGhlwqX/Eg9s946rmgwyvkq1gj+FsJuQPoA+xwwSosJgWmtjyTrMqu4KBsejuvJ5CFcUZUobR6rI2xfGVlXXgW0CTU2PBjew+OukD8PRPOXQ2jzUS4US3wivnz37fBZa6+BvM= Received: from CY4PR12CA0033.namprd12.prod.outlook.com (2603:10b6:903:129::19) by SN1PR12MB0366.namprd12.prod.outlook.com (2a01:111:e400:5145::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Fri, 9 Feb 2018 10:01:37 +0000 Received: from CO1NAM03FT027.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::203) by CY4PR12CA0033.outlook.office365.com (2603:10b6:903:129::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.485.10 via Frontend Transport; Fri, 9 Feb 2018 10:01:37 +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 SATLEXCHOV01.amd.com (165.204.84.17) by CO1NAM03FT027.mail.protection.outlook.com (10.152.80.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.485.12 via Frontend Transport; Fri, 9 Feb 2018 10:01:37 +0000 Received: from roger-build-server.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.361.1; Fri, 9 Feb 2018 04:01:35 -0600 From: Roger He To: Subject: [PATCH 3/3] drm/ttm: check if free mem space is under the lower limit Date: Fri, 9 Feb 2018 18:00:52 +0800 Message-ID: <1518170452-31111-3-git-send-email-Hongbo.He@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518170452-31111-1-git-send-email-Hongbo.He@amd.com> References: <1518170452-31111-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)(39860400002)(39380400002)(396003)(376002)(346002)(2980300002)(428003)(189003)(199004)(5660300001)(76176011)(47776003)(7696005)(305945005)(59450400001)(81156014)(81166006)(36756003)(53936002)(4326008)(54906003)(316002)(16586007)(8676002)(97736004)(104016004)(50466002)(105586002)(2906002)(86362001)(336011)(575784001)(106466001)(68736007)(186003)(2351001)(53416004)(51416003)(50226002)(2950100002)(8936002)(72206003)(6916009)(26005)(356003)(77096007)(478600001)(6666003)(48376002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0366; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CO1NAM03FT027; 1:/aL9YkLnP1G0WvLrYZjpRiM/DzwFG4/SWxxMWo6r7EOdPFr49UFfZ6wHr5VRQeJ8pEW6IjaDmIa11Wpnqe4QyhcNrqN6aqYTq9baoWXgYTTkuu3W2hCuEBYq1gWLFC9j X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1f39fafd-ae34-4568-4c94-08d56fa41bc3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060); SRVR:SN1PR12MB0366; X-Microsoft-Exchange-Diagnostics: 1;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6FzrBE2aw0TAXu8Ud6Uw0dKLuOU1vsZHB5si25Z+AGkJNeQrToemp9PjUm6ce2D9d3xUrw8Oq3G9Rlpnh8MiGqTYY6lj7ZmWBfuPn8aNU+B0/FI82mdZaczxc/he7PLcLqum4qv9P17ikbbjBA49sQgy8kL8snxbCyLPVXYMXZ9zEC1uzx56c0G/oJVnb2zxBJjevip00bGwETymGrzSZzFTHeq7QO4J5lw2t2SZIYE3FNYBFM2EY7d7X3/CYm9Dr/ICPoS06rkxYoTXeAMlT387uDn4ApOrUWbYPsbF/CTWrC3NPOSdcxR6esE5wABfZXdpoYjaDN5YtX902lQS6dWXExsdkVETDpmKXwG1SbPm80DSgpsWEa2ifYcbRSqN/SVa3LijXwrxmYKqe7b6LZkFaVJYe3UkSOpTdiVSYub+crQ8Fm1DLHZ67cvNCXY1hpnPsKTD3xA 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)(3231101)(2400082)(944501161)(93006095)(93003095)(3002001)(10201501046)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:SN1PR12MB0366; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0366; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0366; 4:HHFLqTNpUlaXbWTScSEri/cJZ0ylDjyQHO8Oa2IIvKU/al4TOq9Ofg1BdXnBHUcYkT26wBw8rOr68AHOihOJGIUDaEfsjrYj+fgJZ8/2VrxdEQbeDrbGHyPQn6rVPTjKtyhcCWsHrfEqz6bIlXIVUZ1yqVnbAB3Do6tHFzvLsSkzEnr8yKMys9Q+u4sG7a08wtb8/+iiLpFrCMF95yaLmIIcfpHlbE3QrGixMPGq+d1cyE/XTVGupgZmSs24o+9ADCM4ym0ko/EHiCyhbN4v9fN0RfhTzwprrgyXClSRCLIKYoBPP213q1dXv1s6j+Df X-Forefront-PRVS: 057859F9C5 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0366; 23:QNWdlPBPmc63atS4K930EQZtCNsUsasoq3ddxCNM4?= =?us-ascii?Q?xorBg0Lf/fSz1t3nmwTBsiGzBNiix8G4Vun5/NwVEaqWia3Sjtbbf+oRW5TI?= =?us-ascii?Q?iwKOb4bkAMzI++CmlIqt5ovcqbG8+szsc8mUVJKe0ui1P2CV52zAHdSBJSUy?= =?us-ascii?Q?Eqgc5uM7AhOx4nm2Bm48suUCX4MlefK2+F0dC87HkDgx27QpP6SpYPDDkBQV?= =?us-ascii?Q?hTIrco8dhV0+BrMKxxgVik1RGauI1XeAv5rMish5LfUN2zoVljxDj7JmM4Tq?= =?us-ascii?Q?heZqEhLd7Rxa8kn6adW9U4AmlPxrcRtDQEIMY7Z619XN39nvejJUx/Zn9YuY?= =?us-ascii?Q?zMWTxBvdGQauZj5qh0P1/5o/tCRg6Cd9h4oIqH9L3PTjEh5zOr5qCWb8uD9L?= =?us-ascii?Q?ElCEiQI6cSpRk1gFNEc9FtlUZcHpsLPaeUaRB7a5dZutNL6wrgN2A3hk6t6X?= =?us-ascii?Q?9JTm0xk27yBI5iczhZnpMgVeJWSDXJibpV2C2f4L+FQspNrb5T5mT1o3XObT?= =?us-ascii?Q?9/Fx1AnqyILhtF7xpSGREaxSJhOcPX6uRdARTXodnzmZ/ctPG39JA534Nv3v?= =?us-ascii?Q?Uda/ZsiRAxAuJCpA704yWjL9AOdia+VZ922XrNxpeylz1OqrDp82SbF+L3Kq?= =?us-ascii?Q?x+u7ZRlTnWMQj4FWEZRkjFcuH0a+X3z/tteW+Ucko6JjMEJG1bLBboaQIA5y?= =?us-ascii?Q?In/JxtJwBUZ7yGzI6LJBaGNZX2M4tbf22pu7W8acsAm1WCH8CcIzKGXnmixF?= =?us-ascii?Q?w4FNvEPboqEC/qngOFXnIFThYMnv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eR9u3KNMQG3pggj7/Fqx66Jk63lj7QfJuMaT0DlzWeJbU8055TuZ8/h8IkPt07k7HnnS1KY=; 7:KBIoy9d2MM8eHyjtFjCFbKGYwPwnqDB2ctCYtGFrQz5SNfI3/K8MpZmM7cQve1WNlURX+8VAzz4cz8+PPrRzDkSwFa9VimfwKSR/1hnBC4KWiGfNu6dL+Tehydn6Krh01D72ldTbXXlCKb8ah/Dcp20zluYxN2Hnf/QGgXM99Pw4vOjUx2rFEGgz665xMUQvh3YruZ8ghPUeBPRh3ThGjgI5jouGkFEIjjHGT9dCwmXXhETTSA4aZwi3V2wbdhx/ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0366; 20:80j1UNw+FYHF7tSMPm1OqcSVR/xZtYcgA9BwOik9yns08TpvfYSDcYrDmq1JuBaNBDadl+4EGcvlv7KS5Hg7RkKMxXifBGQtPBL95IkwEM8PEHDMMINwOkF5vn0Ic4Y3ZrIPrAXKKeDtR/zTd1y+iU80VD3vlVW6t3/EM+XK4daOXA+aJhE1Slt49PcdJ37zW9Ur6reRWF1E7mr4aP41IDeQbXcB8qQi55WvQGLHylL9TC180BXmbWJ/RVZqbIEM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2018 10:01:37.1865 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1f39fafd-ae34-4568-4c94-08d56fa41bc3 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=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0366 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 the free mem space and the lower limit both include two parts: system memory and swap space. For the OOM triggered by TTM, that is the case as below: first swap space is full of swapped out pages and soon system memory also is filled up with ttm pages. and then any memory allocation request will run into OOM. to cover two cases: a. if no swap disk at all or free swap space is under swap mem limit but available system mem is bigger than sys mem limit, allow TTM allocation; b. if the available system mem is less than sys mem limit but free swap space is bigger than swap mem limit, allow TTM allocation. v2: merge two memory limit(swap and system) into one v3: keep original behavior except ttm_opt_ctx->flags with TTM_OPT_FLAG_FORCE_ALLOC v4: always set force_alloc as tx->flags & TTM_OPT_FLAG_FORCE_ALLOC Signed-off-by: Roger He --- drivers/gpu/drm/ttm/ttm_memory.c | 35 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/ttm/ttm_page_alloc.c | 4 ++++ drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 ++++ include/drm/ttm/ttm_memory.h | 5 +++++ 4 files changed, 48 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c index aa0c381..0d41a99 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 @@ -375,6 +376,11 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) si_meminfo(&si); + /* lower limit of swap space and 256MB is enough */ + glob->lower_mem_limit = 256 << 8; + /* lower limit of ram and keep consistent with each zone->emer_mem */ + glob->lower_mem_limit += si.totalram >> 2; + ret = ttm_mem_init_kernel_zone(glob, &si); if (unlikely(ret != 0)) goto out_no_zone; @@ -469,6 +475,35 @@ void ttm_mem_global_free(struct ttm_mem_global *glob, } EXPORT_SYMBOL(ttm_mem_global_free); +/* + * check if the available mem is under lower memory limit + * + * a. if no swap disk at all or free swap space is under swap_mem_limit + * but available system mem is bigger than sys_mem_limit, allow TTM + * allocation; + * + * b. if the available system mem is less than sys_mem_limit but free + * swap disk is bigger than swap_mem_limit, allow TTM allocation. + */ +bool +ttm_check_under_lowerlimit(struct ttm_mem_global *glob, + uint64_t num_pages, bool force_alloc) +{ + bool ret = false; + int64_t available; + + if (force_alloc) + return false; + + available = get_nr_swap_pages() + si_mem_available(); + available -= num_pages; + if (available < glob->lower_mem_limit) + ret = true; + + return ret; +} +EXPORT_SYMBOL(ttm_check_under_lowerlimit); + static int ttm_mem_global_reserve(struct ttm_mem_global *glob, struct ttm_mem_zone *single_zone, uint64_t amount, bool reserve) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 5edcd89..bd312e6 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -1100,6 +1100,10 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) if (ttm->state != tt_unpopulated) return 0; + if (ttm_check_under_lowerlimit(mem_glob, ttm->num_pages, + ctx->flags & TTM_OPT_FLAG_FORCE_ALLOC)) + return -ENOMEM; + ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags, ttm->caching_state); if (unlikely(ret != 0)) { diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index b122f6e..fc32096 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -940,6 +940,10 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev, if (ttm->state != tt_unpopulated) return 0; + if (ttm_check_under_lowerlimit(mem_glob, num_pages, + ctx->flags & TTM_OPT_FLAG_FORCE_ALLOC)) + return -ENOMEM; + INIT_LIST_HEAD(&ttm_dma->pages_list); i = 0; diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index 8936285..5ada921 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. + * @lower_mem_limit: include lower limit of swap space and lower limit of + * system memory. * @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 lower_mem_limit; struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES]; unsigned int num_zones; struct ttm_mem_zone *zone_kernel; @@ -90,4 +93,6 @@ extern void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page, uint64_t size); extern size_t ttm_round_pot(size_t size); extern uint64_t ttm_get_kernel_zone_memory_size(struct ttm_mem_global *glob); +extern bool ttm_check_under_lowerlimit(struct ttm_mem_global *glob, + uint64_t num_pages, bool force_alloc); #endif