Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp707950rwb; Tue, 29 Nov 2022 04:29:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NM2TT/bh37WCWaTwLE+ub40Yyzv8V1gVoTP0Z5Opm1BBvZcavt5YjfNYh1RlhoFSBxCel X-Received: by 2002:a17:906:f114:b0:7c0:7d70:facd with SMTP id gv20-20020a170906f11400b007c07d70facdmr6137443ejb.645.1669724952227; Tue, 29 Nov 2022 04:29:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669724952; cv=pass; d=google.com; s=arc-20160816; b=Mf7QUOalIiaaUZXlKZSqc6WzMGLoToOIekrFgdmzj+OAQW0NLopvOXArPGicx8RY6C dlBRv3AW4O91n8O501PmTkgIJUy2I3wmdCmFjrWvQl4zretZpsieElPBQSIRJHiMLYxl KVsFX5K2GVBS4G9J4kP0lp52vqOhlKRChLB9IQL828c9j2Arhe19mpE8Dh2pFnepjBWB 5az9u4i9x2G8vrM3a37eN22KPHvE1rqLGLuB/1oblwEc4S9Zz+bZeVxhKa5M5BZ2LEsX iMjHMlMrfIIZDs0lWWmx+ZT/GbsE63E44bzAokmNg48EN+bToHTmF5kgFoCUGqlTylOC Dl2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=fhuc1l7CUHV4DxPqVA92IroD520wmBqtTwhR+v5JUm4=; b=oDi4j02dM9ZQgLmTetlJsHh0BEnacalcBvWUYWLOWgnkEeEJg2nfpYdGavVd1WSSFH Z7wy2bODCm5WzVPd+neYhvoewAI5IcKGfYTPphWuLWH4KhGm8St8uPO0xBJW0ZJE3vRg 8788IgxxufiK6+mgBD4iHoD0uvXLgAUWgW1mj1c/euNXXREDGeURZFYR/OJTNQhtkHya oc9NEjUc62YEYLGndLVLLKfBwrQcO4TGzQIU9ps5oRqId5j0bcFliktuemRaloUnR4Ik ydinDYrBo/ljHubcvglNrKWREMpvbNhxRCuYr1uDJagK2ooJRPNPrsmVd9H2RKE6uczy 8kAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=JfP5WCpk; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go18-20020a1709070d9200b0078de536a3cdsi12763248ejc.119.2022.11.29.04.28.52; Tue, 29 Nov 2022 04:29:12 -0800 (PST) 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=@amd.com header.s=selector1 header.b=JfP5WCpk; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233726AbiK2MIw (ORCPT + 83 others); Tue, 29 Nov 2022 07:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233918AbiK2MIO (ORCPT ); Tue, 29 Nov 2022 07:08:14 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2059.outbound.protection.outlook.com [40.107.92.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2531B1209A for ; Tue, 29 Nov 2022 04:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bqb3pRQOFj8WNa9OzN+0LuBiTbud1xBYoeZIOGgIORmMTNHF2b+Ci+1PX47BfkLOa1K0ruBZv061wMso7Ryy7wXENHCeNBPohrrCYKgqq7xf/LkkPvK49gLnZ4Z07sGp5eTmotk7k2YBTjkE5kW9Bttm6xr+IEjsM6QENvH7NVip2+k/8iR60A3hkM36VeLT5Y/rbNrvuYvoZ0t+0E4c7XWsiAlwIW6OlTp+Ai+HwdP8/QuKTVFd4AwSCTF3OWRT2Ac2pTx6/fYG+6ISjZHx2hP6WqZo5t9CJTzGC3RtrUAKiFYysLggvjxuUwoTOL2cnc3/l1lmeb83f6pun6ZXOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fhuc1l7CUHV4DxPqVA92IroD520wmBqtTwhR+v5JUm4=; b=N511HV/qJxBC8nfKjlyQxTYoCIFBm8MfBcUbSca7gwyeTxTpPSH6lbKbV0cnWc78M8rUBq/3XoKjnoeYl3k9aWQx0adC91WjfKTz+ViUxhOXWoL5KHGP7Eny3yBmpEsyQJPlcd6/WXa5l+dgYJT9t1t6u9ql8bLZcP6+kmSTFjd86VzOz7QwEZNb1LbxnvSv7qytNItAlZvZsrkODb7qH5l6kxFdwmdvjKenAumzhw/AJ+d41WzdOrFnZ+G1n8xHGpUqM+WOlBSV4Ap65niJVOL4hrSNXAFDsUTp1vtT/nDPkmiUiVePnlP0Qsa48l/p0XvFklRJxb4yFTVdpRnVVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fhuc1l7CUHV4DxPqVA92IroD520wmBqtTwhR+v5JUm4=; b=JfP5WCpkxWLxLvd2o07PkMvqcOqwwNoGn5Ctym6/lbqIuE+upIE7CCBae/eDjkPkddqOWZwIUXMW8zP/amCF6HA6WrRCYKn94ExU4Zo3P31tAdSIp7wcDWuQnOgkH+lPEPmeDRdqszBcXhGl+k6VEJ8VPdxQuoYbBSMl5DEEvV4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by PH0PR12MB7885.namprd12.prod.outlook.com (2603:10b6:510:28f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Tue, 29 Nov 2022 12:07:49 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::7d43:3f30:4caf:7421]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::7d43:3f30:4caf:7421%7]) with mapi id 15.20.5857.023; Tue, 29 Nov 2022 12:07:49 +0000 Message-ID: Date: Tue, 29 Nov 2022 13:07:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: =?UTF-8?B?UmU6IOWbnuWkjTogW1BBVENIIHY0XSBkcm06IE9wdGltaXNlIGZvciBj?= =?UTF-8?Q?ontinuous_memory_allocation?= Content-Language: en-US To: "Pan, Xinhui" , "amd-gfx@lists.freedesktop.org" Cc: "daniel@ffwll.ch" , "matthew.auld@intel.com" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "Paneer Selvam, Arunpravin" , "intel-gfx@lists.freedesktop.org" References: <20221129105655.125571-1-xinhui.pan@amd.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR2P281CA0052.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:93::15) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8PR12MB3587:EE_|PH0PR12MB7885:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e982c81-4539-45cb-c89f-08dad2025595 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1qe8MJjh3isONq6/mI5Q1NpUwBFOgQZCeTn8oVaebCvWtiKEzfQIrY/3uxjM5hHYKkcW85iaB0OR1WYMNhSiQslS+ebJwVdlT1GnnaxV8DUBe2FbbDsWezGdd9Jwz0ccmZQEcAGvhiq31U9NS7Po2wtRqunmfASjBt6wT9sefMu/TGwuu2Igcuu4TF1Xb/52V2x1Ru1n7dKpbVRxonpFcvzG/BASxqxf6TFtRKoZzQUf3PzobDYSYWdQ3WJQFQr5idToGNCJvqomL3E8rhjV16znGRsS8UKnCtZkUwnvPe4IlFQj77MerLOMnGPgtxPCoPq6SDtC1odUga6DA43Ydd4QgfilyCZZ3ZO3m9e71Dr4mpPVUwEvKfTAAXDwxt6YEM6uzZtm0lyq2JVqirKTEYKaEwwj8cFCeB6g7jNkvqq+GY+b2hZX+tIy8b9RltVGBB102yI2RxTwDOy8LFW+VV2cz2nc2n3f2emTJSmc+WUk608eTfnQtLkmMi4D1BrNj/1jrkk0qAQzhOpvVPeQRn9qInogsMqz5KZlchcqt7b0b0sjstO4bljdZZD0Q3/CxULwoRZaR2yxQBLuKYyvklYsMXaLQqEfdC7VEmsj/mdepy53UnJSHDoT5O3tHzsLwyQQ0ftycFe7v/qSY4HIFy8VvWymE9oKzC0fbchvS3Bp0NPGsLtIoAG6YS8dNktQ5j0NhdUSC09/prsciPN4Efof7VRGMGpRN/Yq2Zazrcc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(366004)(346002)(396003)(39860400002)(451199015)(31686004)(66899015)(224303003)(8936002)(6506007)(5660300002)(41300700001)(2906002)(4326008)(31696002)(86362001)(36756003)(66946007)(316002)(110136005)(54906003)(478600001)(6486002)(38100700002)(66556008)(83380400001)(2616005)(6666004)(66476007)(186003)(6512007)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZXJVR1ZuSXpQaWNoVkhFRjdrWDNMS3FPZWJNcjN3QnJSTGdHVm0ybVdiQzQx?= =?utf-8?B?emI0bnpURVRWazN0ZldRV2tpR1ljTFVLS2w5NXlaTDJkL0kwcnMxekFaVFha?= =?utf-8?B?WGVJbTZjcDlKMjhSVTVacUNlaXUzMGQreTVzejBUL01DRkZ3T29oVThTKzlE?= =?utf-8?B?M2J3RXVFLzdsUmc2dk9UTmpiaUg1YTRNWi93RDJhWXRCNHd1MFBlMkJGZEtE?= =?utf-8?B?Qm9OdE1KcjQyRkh2V0xZeER2TnA3MEl3WFZ0QUdvMFRHRWVNdEY3RHhKQWg5?= =?utf-8?B?WHZ4MWRsRVkvTlVlRHNacGd0K3AzdFRHN0s5NU9SLzhzalZHSVQrbStKZDNG?= =?utf-8?B?YiszTlE5Qm9zV2dhcVhZR0JVdnYxM0xHNW9TWTVEYUhmay9KZVoyMittaUZO?= =?utf-8?B?OVdiNERocWpYMUNMS2wwZEhKL3cvQ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network-Message-Id: 2e982c81-4539-45cb-c89f-08dad2025595 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2022 12:07:49.6181 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QjMOU9/jjfpr2fJPUS7COHIR53J1aPoUXE98pc4yXyesnbZUpsRMjssK+jCi6SqN X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7885 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 Am 29.11.22 um 12:54 schrieb Pan, Xinhui: > [AMD Official Use Only - General] > > comments inline. > > ________________________________________ > 发件人: Koenig, Christian > 发送时间: 2022年11月29日 19:32 > 收件人: Pan, Xinhui; amd-gfx@lists.freedesktop.org > 抄送: daniel@ffwll.ch; matthew.auld@intel.com; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; Paneer Selvam, Arunpravin; intel-gfx@lists.freedesktop.org > 主题: Re: [PATCH v4] drm: Optimise for continuous memory allocation > > Am 29.11.22 um 11:56 schrieb xinhui pan: >> Currently drm-buddy does not have full knowledge of continuous memory. >> >> Lets consider scenario below. >> order 1: L R >> order 0: LL LR RL RR >> for order 1 allocation, it can offer L or R or LR+RL. >> >> For now, we only implement L or R case for continuous memory allocation. >> So this patch aims to implement the rest cases. >> >> Adding a new member leaf_link which links all leaf blocks in asceding >> order. Now we can find more than 2 sub-order blocks easier. >> Say, order 4 can be combined with corresponding order 4, 2+2, 1+2+1, >> 0+1+2+0, 0+2+1+0. > Well that description is a bit confusing and doesn't make to much sense > to me. > > When you have two adjacent free order 0 blocks then those should be > automatically combined into an order 1. This is a fundamental property > of the buddy allocator, otherwise the whole algorithm won't work. > > [xh] sorry, The order above is not 4, should be 3. > order 3 can be combined with corresponding order 3, 2+2, 1+2+1, 0+1+2+0, 0+2+1+0 > the order 0 + 1 + 2 + 0 case does not have two same order 0 adjacent. they are in different tree. > looks like below > order 3: L3 R3 > order 2: L2 (R2)* L2* > order 1: L1 (R1) L1 > order 0: L0 (R0) (L0) > R0 + R1+R2 +L0 with () around combined to be order 3. > R2 + L2 with * followed combined to be order 3. > etc.... > > When you have the case of a free order 1 block with two adjacent free > order 0 blocks then we a fragmented address space. In this case the best > approach is to fail the allocation and start to swap things out. > > [xh] Eviction is expensive. No, it isn't. Eviction is part of the algorithm to clean this up. When we can't find any free room then evicting and moving things back in is the best we can do to de-fragment the address space. This is expected behavior. Regards, Christian. > And if it still fails to find the continuous memory with this approach, then let's evict. > > So what exactly is the goal here? > > Regards, > Christian. > >> Signed-off-by: xinhui pan >> --- >> change from v3: >> reworked totally. adding leaf_link. >> >> change from v2: >> search continuous block in nearby root if needed >> >> change from v1: >> implement top-down continuous allocation >> --- >> drivers/gpu/drm/drm_buddy.c | 108 +++++++++++++++++++++++++++++++++--- >> include/drm/drm_buddy.h | 1 + >> 2 files changed, 102 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c >> index 11bb59399471..8edafb99b02c 100644 >> --- a/drivers/gpu/drm/drm_buddy.c >> +++ b/drivers/gpu/drm/drm_buddy.c >> @@ -80,6 +80,7 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size) >> { >> unsigned int i; >> u64 offset; >> + LIST_HEAD(leaf); >> >> if (size < chunk_size) >> return -EINVAL; >> @@ -136,6 +137,7 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size) >> goto out_free_roots; >> >> mark_free(mm, root); >> + list_add_tail(&root->leaf_link, &leaf); >> >> BUG_ON(i > mm->max_order); >> BUG_ON(drm_buddy_block_size(mm, root) < chunk_size); >> @@ -147,6 +149,7 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size) >> i++; >> } while (size); >> >> + list_del(&leaf); >> return 0; >> >> out_free_roots: >> @@ -205,6 +208,9 @@ static int split_block(struct drm_buddy *mm, >> mark_free(mm, block->left); >> mark_free(mm, block->right); >> >> + list_add(&block->right->leaf_link, &block->leaf_link); >> + list_add(&block->left->leaf_link, &block->leaf_link); >> + list_del(&block->leaf_link); >> mark_split(block); >> >> return 0; >> @@ -256,6 +262,9 @@ static void __drm_buddy_free(struct drm_buddy *mm, >> break; >> >> list_del(&buddy->link); >> + list_add(&parent->leaf_link, &block->leaf_link); >> + list_del(&buddy->leaf_link); >> + list_del(&block->leaf_link); >> >> drm_block_free(mm, block); >> drm_block_free(mm, buddy); >> @@ -386,6 +395,78 @@ alloc_range_bias(struct drm_buddy *mm, >> return ERR_PTR(err); >> } >> >> +static struct drm_buddy_block * >> +find_continuous_blocks(struct drm_buddy *mm, >> + int order, >> + unsigned long flags, >> + struct drm_buddy_block **rblock) >> +{ >> + struct list_head *head = &mm->free_list[order]; >> + struct drm_buddy_block *free_block, *max_block = NULL, *end, *begin; >> + u64 pages = BIT(order + 1); >> + u64 cur_pages; >> + >> + list_for_each_entry(free_block, head, link) { >> + if (max_block) { >> + if (!(flags & DRM_BUDDY_TOPDOWN_ALLOCATION)) >> + break; >> + >> + if (drm_buddy_block_offset(free_block) < >> + drm_buddy_block_offset(max_block)) >> + continue; >> + } >> + >> + cur_pages = BIT(order); >> + begin = end = free_block; >> + while (true) { >> + struct drm_buddy_block *prev, *next; >> + int prev_order, next_order; >> + >> + prev = list_prev_entry(begin, leaf_link); >> + if (!drm_buddy_block_is_free(prev) || >> + drm_buddy_block_offset(prev) > >> + drm_buddy_block_offset(begin)) { >> + prev = NULL; >> + } >> + next = list_next_entry(end, leaf_link); >> + if (!drm_buddy_block_is_free(next) || >> + drm_buddy_block_offset(next) < >> + drm_buddy_block_offset(end)) { >> + next = NULL; >> + } >> + if (!prev && !next) >> + break; >> + >> + prev_order = prev ? drm_buddy_block_order(prev) : -1; >> + next_order = next ? drm_buddy_block_order(next) : -1; >> + if (next_order >= prev_order) { >> + BUG_ON(drm_buddy_block_offset(end) + >> + drm_buddy_block_size(mm, end) != >> + drm_buddy_block_offset(next)); >> + end = next; >> + cur_pages += BIT(drm_buddy_block_order(next)); >> + } >> + if (prev_order >= next_order) { >> + BUG_ON(drm_buddy_block_offset(prev) + >> + drm_buddy_block_size(mm, prev) != >> + drm_buddy_block_offset(begin)); >> + begin = prev; >> + cur_pages += BIT(drm_buddy_block_order(prev)); >> + } >> + if (pages == cur_pages) >> + break; >> + BUG_ON(pages < cur_pages); >> + } >> + >> + if (pages > cur_pages) >> + continue; >> + >> + *rblock = end; >> + max_block = begin; >> + } >> + return max_block; >> +} >> + >> static struct drm_buddy_block * >> get_maxblock(struct list_head *head) >> { >> @@ -637,7 +718,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, >> struct list_head *blocks, >> unsigned long flags) >> { >> - struct drm_buddy_block *block = NULL; >> + struct drm_buddy_block *block = NULL, *rblock = NULL; >> unsigned int min_order, order; >> unsigned long pages; >> LIST_HEAD(allocated); >> @@ -689,17 +770,30 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, >> break; >> >> if (order-- == min_order) { >> + if (!(flags & DRM_BUDDY_RANGE_ALLOCATION) && >> + min_order != 0 && pages == BIT(order + 1)) { >> + block = find_continuous_blocks(mm, >> + order, >> + flags, >> + &rblock); >> + if (block) >> + break; >> + } >> err = -ENOSPC; >> goto err_free; >> } >> } while (1); >> >> - mark_allocated(block); >> - mm->avail -= drm_buddy_block_size(mm, block); >> - kmemleak_update_trace(block); >> - list_add_tail(&block->link, &allocated); >> - >> - pages -= BIT(order); >> + do { >> + mark_allocated(block); >> + mm->avail -= drm_buddy_block_size(mm, block); >> + kmemleak_update_trace(block); >> + list_add_tail(&block->link, &allocated); >> + pages -= BIT(drm_buddy_block_order(block)); >> + if (block == rblock || !rblock) >> + break; >> + block = list_next_entry(block, leaf_link); >> + } while (true); >> >> if (!pages) >> break; >> diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h >> index 572077ff8ae7..c5437bd4f4f3 100644 >> --- a/include/drm/drm_buddy.h >> +++ b/include/drm/drm_buddy.h >> @@ -50,6 +50,7 @@ struct drm_buddy_block { >> */ >> struct list_head link; >> struct list_head tmp_link; >> + struct list_head leaf_link; >> }; >> >> /* Order-zero must be at least PAGE_SIZE */