Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3736472imc; Thu, 14 Mar 2019 04:15:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnZN8A9/g6YIUAoIuT00qrAKxhIzzmLRRxEFN/BQz1Gy/VABtZoiPYzn+mlDULz/MI9psC X-Received: by 2002:a62:1611:: with SMTP id 17mr2640594pfw.139.1552562109000; Thu, 14 Mar 2019 04:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552562108; cv=none; d=google.com; s=arc-20160816; b=D++bhUm6D7UFiCKgP5PhMj2WFnCkxMNp2kbuCr61fN7/lzzZs5P22bs8TOdUBQT4BG VI9k5Sd/epnoYam50C2CSj5CtmM+6vk7IOZD60EcO5dCN1esrDQgSc3XAX+4kFdnRkJR u7ZOZpV/94BSNVwUK09MaIwudAwHl6tohA1rZgPBFNMSEPBQ0FMYFMJCJb/A39kW+MCR sVs6U4GMzbFwrsqx66yTt+iZ/vcPhZsvo13uJDCtIr9sdVilxOdbf/oVQTEDB/OKh8sA BfF1wXe8kU990fOwTveUjMrezZSvUavCS5BiyVUgB/lqE0hBDUQsCyoxsR+79sUbqDNY J8jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature; bh=n4HxxiwAlFlhYdr+5LtCpPNTbZpyj8J+lBCYFMhyfbY=; b=uXfVvH0xPx2uLawIL57HDn20F5lIgGoNbUo0kyXNn2sdMgCeQQ1XnM5qR4lTlap6o6 EkghvAEY+48A4Lnj2bcBzVmk32tq11bo3IVaKXvXfScP1lR8r30ovgtFI9OayS1cb8qk DtnDGtS0WGKH6ZH+CLQ4s+ihmlzo/2LmWos+Kii/Ee04NFvS88R/h9SDUkqEov/oIqpS jM1cClR95z/CHtBLneH70b5S4Nd+Fx/aCKFMcb1j/6MdGMTzXdBG5tuZ1Xt/GmpkdaPq 7brpfTjyPgTtxBRjZk2NbSN3SYlHfypAQzOSJp1/W1G1np3bdUWf3ynY37f1sHdhTrJ0 gsew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=roF3VzBj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn18si13089625plb.185.2019.03.14.04.14.54; Thu, 14 Mar 2019 04:15:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=roF3VzBj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727302AbfCNLMU (ORCPT + 99 others); Thu, 14 Mar 2019 07:12:20 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35173 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726292AbfCNLMT (ORCPT ); Thu, 14 Mar 2019 07:12:19 -0400 Received: by mail-pg1-f195.google.com with SMTP id e17so3751385pgd.2 for ; Thu, 14 Mar 2019 04:12:19 -0700 (PDT) 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-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=V4WkntqCWYD2ySLdJE0Pa05kcViJnqQGRwEVED3ffo4K4zh/Yez8Yi8k7HRth3yTsN cT9QB41h9/jpjBvMWHOS0G7J+60w3JkiZwg4U+biSBaKEWCInWeaTADA1o/wQv8dlXbG 1OT0U7EXTWpyN8JNxcjdPRxvl0CeUfhWA60ppUI7+628Lr/9u+r/tWNuRxbhOjYqGEcd clSWtTPZOTtAqMsbJLfQkcgz85VUOk9qr4Om4GVJD43rPNg+wwGBThnJHP1jox/Jq+tx NHrKRU6uKWMAJ5Qex4F3LN7JyR9vMMZ5m/LUP0SXcnbQsKAOMZNDRbiqnrO+A4UqCNd+ 22lA== X-Gm-Message-State: APjAAAUv5i0+bUPXXkk7ao25x3Op1R/Km/ePfhlYTjht9ao7ZAU2Ug5T HTX+I/EWCo0MubpzKsrXQv0= 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) { -- 1.9.1