From patchwork Thu Mar 14 11:12:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 10854247 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 7A4561669 for ; Fri, 15 Mar 2019 08:24:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 641AB2A8AE for ; Fri, 15 Mar 2019 08:24:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 586FA2A8B2; Fri, 15 Mar 2019 08:24:00 +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 03FEC2A8AE for ; Fri, 15 Mar 2019 08:24:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5A9786E332; Fri, 15 Mar 2019 08:23:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B9E86E185 for ; Thu, 14 Mar 2019 11:12:19 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id 8so175984pfr.4 for ; Thu, 14 Mar 2019 04:12:19 -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=n4HxxiwAlFlhYdr+5LtCpPNTbZpyj8J+lBCYFMhyfbY=; b=AxY/s/eesl8bVlXADCveLhNddTujfOhEsulu11K7acVLRNlbeg0rIkdW9nMsB9KyBI Wrh22cnQimhTnhbuw91WsNx5a9nE6ien0WCWKq1xbU5xcj0MNEYx5EqedzBvLuVUhNm4 YTpweUNXUk8ayxuqxSkamWaumJwNpyzBpccG6kEZQVY0NVa7XKB2PHB6O5uv48Q7NYo/ hbeayBa+0NHXtsApiHzA+0k2LjQARVrRaUozS+b91uzU92mrqx+E9cJodvqGkg2IRtMI A16Rc62juICn/p5DNjKCGdifyVDmgI3mN1OF/Z+Jf8lG1y5M3zGwAXNiySoevIESjXNm Ea+A== X-Gm-Message-State: APjAAAXaRYdYNGir4dzh4oFU3+9Z20xM9Cp7dXJr/NohDhpqWzUKwSeI rnpwLhk8Y+IsWK5zj29Qsa0= X-Google-Smtp-Source: APXvYqxgGoNRfjnUZsQWx4drOGx00xoiXr7fHElYupWHFek9O3YWWuv8jqhL/GfJUxtX1Kd84mQCrw== X-Received: by 2002:a65:63c8:: with SMTP id n8mr44137753pgv.158.1552561938862; Thu, 14 Mar 2019 04:12:18 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 20sm34946592pfs.182.2019.03.14.04.12.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Mar 2019 04:12:18 -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] driver : staging : ion: optimization for decreasing memory fragmentaion Date: Thu, 14 Mar 2019 19:12:12 +0800 Message-Id: <1552561932-23776-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Mailman-Approved-At: Fri, 15 Mar 2019 08:22:56 +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=n4HxxiwAlFlhYdr+5LtCpPNTbZpyj8J+lBCYFMhyfbY=; b=roF3VzBjrTyogMB4us1/EsA/Dq4OBYl+TaF+eOCuBLQVH8XeGPaXxaAD1Td7hqPfoK LBDL2hte6Ck6pioefoqCurbnoloOrxvPVRA5SFL0tIs+aCiCNuGE1FM74gozRGQZMRul 53AvQ8XLfcuPCr60Vo+C2OCmxRmbUEIRk/F9cUVM6efhLHPhawZ2GQ5rU+mYOX3QTVI0 xDKA6swaB6/uIDaVzvOup2HuROIX0TnUs/0n1ZKNpwwDsVzhI2mo6LjLaeeGcTzTZ+Zk 8+AonY4iohLVAzLN3EvugsBccsD6tN3LwmggZQTuqkqqSf8K/z46Xufj9g6/Ee2pPmvp 9oxw== 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 | 12 +++++++++++- drivers/staging/android/ion/ion_system_heap.c | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 31db510..68aa970 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" +unsigned long ion_heap_batch; + void *ion_heap_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer) { @@ -303,7 +305,15 @@ 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); } + +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) {