From patchwork Wed Mar 20 06:38:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 10861013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 248CF14DE for ; Wed, 20 Mar 2019 08:32:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08FBF299BB for ; Wed, 20 Mar 2019 08:32:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F143729A9D; Wed, 20 Mar 2019 08:32:33 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 9BE50299BB for ; Wed, 20 Mar 2019 08:32:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8959689B62; Wed, 20 Mar 2019 08:32:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1CA2589BF8 for ; Wed, 20 Mar 2019 06:38:31 +0000 (UTC) Received: by mail-pf1-x442.google.com with SMTP id c207so1177015pfc.7 for ; Tue, 19 Mar 2019 23:38:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=AF5hfBuiGsRcBiZ0vVXmEUTffuz50KgXcl2b8eIbr7w=; b=XEINfc2ZO6uK2aSnrhvrRAd2yBf7K5fMPkCkyrCVVyNguirWo458eI8g2g4HH4eSV8 6y62eO3vh6UjgF4TAUbuUodFGHtU1CUTbf7+HAuttxKcDy2JB8Sc2+eCtwVjpodJCVgK 13Y02DkaGNmARCjjpGp9MNsUBlglXnOCFkYXzNL+evAY/IFC1i9bFFl+G3oT6oeQ/C7b 2Eug4+8Z1CVmEt7TcdAN/GhB23Hd+wlhJzLjZV/0Boa4u4RxG/75Y67L1Z/7aWJPpShJ Lq+Jj29IGLtiiX/MVpl3aMTefBwvmChF2rRwCsoqQWn/pvJQQBCwFeaJaQ2CELk4QqlW X2SQ== X-Gm-Message-State: APjAAAUTlCyD7zNdhlQHUX4XIP6SDpeT/h+124OlsUOr2UhDkIdoTN4B qIVDpCaRzNbsk5wzhhWv2zU7JDt8 X-Google-Smtp-Source: APXvYqzUQNa49xRlgEPPoe1oyIw2XEH6d4Tqm2tgL/srpdSqXkWrPwVznfQ4b/i5YVdHmqBtuQoeAQ== X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr6149664plr.97.1553063910721; Tue, 19 Mar 2019 23:38:30 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id n15sm2787376pgc.92.2019.03.19.23.38.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Mar 2019 23:38:29 -0700 (PDT) From: Zhaoyang Huang To: devel@driverdev.osuosl.org (open list:ANDROID ION DRIVER), dri-devel@lists.freedesktop.org (open list:ANDROID ION DRIVER), linaro-mm-sig@lists.linaro.org (moderated list:ANDROID ION DRIVER), linux-kernel@vger.kernel.org Subject: [PATCH v2] driver : staging : ion: optimization for decreasing memory fragmentaion Date: Wed, 20 Mar 2019 14:38:23 +0800 Message-Id: <1553063903-26768-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Mailman-Approved-At: Wed, 20 Mar 2019 08:32:28 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=AF5hfBuiGsRcBiZ0vVXmEUTffuz50KgXcl2b8eIbr7w=; b=FCUsHJx1eBZpUUT6STWDj+JbjRhgpATZl1w+NGMKoeSRiw4geadmiD+W8x8zr1jHO7 xTBfegsc5gVAdA56p0pIcwbuWosfu1eioltjS8l4eMNgdOt9X/m71piu+vrW5rMwjg6s TiNKI72P1O0tQjdtqhHQ8pDFF6pqZCyYMpVC/Dgpi7ufmy9C/Y+UTnp/AFfekuuGN6xi 33gRQ89wEdMjzSwPKynQEowr2zxelyoqbLX1fcHLxTt4lfEwEMNwa9YyOdgGUfXWPg0e cYhkCfdKWcEM+cJg35PFetGf/QS6sJbu0c1iGfcDNIYEsV2km/v0xrh1hYKHDVGOyyIp t9UQ== 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Zhaoyang Huang Two action for this patch: 1. set a batch size for system heap's shrinker, which can have it buffer reasonable page blocks in pool for future allocation. 2. reverse the order sequence when free page blocks, the purpose is also to have system heap keep as more big blocks as it can. By testing on an android system with 2G RAM, the changes with setting batch = 48MB can help reduce the fragmentation obviously and improve big block allocation speed for 15%. Signed-off-by: Zhaoyang Huang --- drivers/staging/android/ion/ion_heap.c | 16 +++++++++++++++- drivers/staging/android/ion/ion_system_heap.c | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 31db510..0c8d696 100644 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -16,6 +16,8 @@ #include #include "ion.h" +static unsigned long ion_heap_batch; + void *ion_heap_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer) { @@ -303,7 +305,19 @@ int ion_heap_init_shrinker(struct ion_heap *heap) heap->shrinker.count_objects = ion_heap_shrink_count; heap->shrinker.scan_objects = ion_heap_shrink_scan; heap->shrinker.seeks = DEFAULT_SEEKS; - heap->shrinker.batch = 0; + heap->shrinker.batch = ion_heap_batch; return register_shrinker(&heap->shrinker); } + +/* + * configuring ion_heap_batch as 3 times of the pool's peak value can help + * improving allocation speed + */ +static int __init ion_system_heap_batch_init(char *arg) +{ + ion_heap_batch = memparse(arg, NULL); + + return 0; +} +early_param("ion_batch", ion_system_heap_batch_init); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 701eb9f..d249f8d 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -182,7 +182,7 @@ static int ion_system_heap_shrink(struct ion_heap *heap, gfp_t gfp_mask, if (!nr_to_scan) only_scan = 1; - for (i = 0; i < NUM_ORDERS; i++) { + for (i = NUM_ORDERS - 1; i >= 0; i--) { pool = sys_heap->pools[i]; if (only_scan) {