Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp262614img; Tue, 19 Mar 2019 23:39:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyfmBj79mjTZ/nIc+f7z3Z/R/dOooDq+MgFoJsRIz2BjRRihRBbqnYav2LcRGXMcp2RYsYm X-Received: by 2002:a17:902:87:: with SMTP id a7mr6413993pla.295.1553063976478; Tue, 19 Mar 2019 23:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553063976; cv=none; d=google.com; s=arc-20160816; b=zE79CKAzdAa4vP732G6fPmaWujvXIHUjZx4b0Kgl5itzgmGe30ysu1Xtjfu7a6NN+Q i5EXk0lVtL9liBGTAVeOIPYay65Huo5s5lkp/tl7U+oYtDmPUngshOLwcNrrOgdGJldq GFKyxzM3R13gxx2SDb4trKTGjH1IBam7NEdEPD2NOy4hKEOHIatMP0lzv6zuAZJy8C0z nzNErMEI5FC1PHPASMQ1htRI+oJDcIMsy881pz1LVA4QRgQ3iQiPW0EEkkofZAchHaQE WFGDZvmURMO1YbjUYyZzJMG3PZ0/aj7hjjFaw8NObd+LU2JGcOOQwq9dEGeKjlPB9K2w XXEA== 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=AF5hfBuiGsRcBiZ0vVXmEUTffuz50KgXcl2b8eIbr7w=; b=qvtNiDolRb+X/I52DpHSAwT9YXw9r4R9wioYjH0zcsqvL+OfKLxzEl7pb3mo+qSmz7 eK7oEylIo9pcWPHrIkLYNviIJPy2U7NyQEc3W+FaW1bM9599jl/CakZuuP/stxwiQcgf eqXfRrLQRjZNek+GumlWpOMWV9Q1m4pc8Z4rTh8ZpcygOaumnyQw60QDhTMW5rWi6ZUH eEkfCABiqD3asa7Lahajiu1gpyrkkPPLUPiurP+JmSqbNI0L+xQeVNXI7oPxvr8OjDNv tF/V1Er09jH5nIOBRvLWx2nbnWNium2ldZoZr4m1JKLgZkHUYKiWmJFfGKHFu0cYGMMx ruEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FCUsHJx1; 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 i10si914580pgs.572.2019.03.19.23.39.20; Tue, 19 Mar 2019 23:39:36 -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=FCUsHJx1; 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 S1727439AbfCTGib (ORCPT + 99 others); Wed, 20 Mar 2019 02:38:31 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42486 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfCTGib (ORCPT ); Wed, 20 Mar 2019 02:38:31 -0400 Received: by mail-pg1-f196.google.com with SMTP id p6so1019206pgh.9 for ; Tue, 19 Mar 2019 23:38:31 -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=AF5hfBuiGsRcBiZ0vVXmEUTffuz50KgXcl2b8eIbr7w=; b=FCUsHJx1eBZpUUT6STWDj+JbjRhgpATZl1w+NGMKoeSRiw4geadmiD+W8x8zr1jHO7 xTBfegsc5gVAdA56p0pIcwbuWosfu1eioltjS8l4eMNgdOt9X/m71piu+vrW5rMwjg6s TiNKI72P1O0tQjdtqhHQ8pDFF6pqZCyYMpVC/Dgpi7ufmy9C/Y+UTnp/AFfekuuGN6xi 33gRQ89wEdMjzSwPKynQEowr2zxelyoqbLX1fcHLxTt4lfEwEMNwa9YyOdgGUfXWPg0e cYhkCfdKWcEM+cJg35PFetGf/QS6sJbu0c1iGfcDNIYEsV2km/v0xrh1hYKHDVGOyyIp t9UQ== 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=No+pgRBxl5Ce2lXTDI1eJI0Ry0jcFjDZCXjQYW0R2zhBxjPhkG+YzftFTyE7XDb2SC FqTT4ayRCrt08HYJH9timuCSKM+XolzF2gC0kK3j58E3f9264g20fBcKLab0dcNs+eY2 afS8AGc7GHQFGstsRnetyi1AlJ8s4WmofCMHp40yI0MwnVS+oPg5VxIbWvjhV4y3XkFq jJhC6ocO9rVGLd4cnBe3sIKjZxZqMvVAf7046VC5Ibp2MNx8BlyyqtWU87ODvQzw2qjb YDwLCshyFVc0KTnFIvF7lpvH4nRf4H3ZtF0pDj8Z2bNvFKmTc/iTPa1ght5gGukzsE+X 2YYw== X-Gm-Message-State: APjAAAXtYm8JsxzalMYKX0pJES9fDv39mo27MNvAsFUvL3OiOSLWYokK fKSJhCAIEXQB7JvqUcwWD5w= 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 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 | 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) { -- 1.9.1