Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp18187ima; Thu, 14 Mar 2019 18:20:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQKDHU1F9lP1AFNRf9m9jZjnSHLoAND+B2TSfW6roAYv7VbltEo55Ok530bwNJzj+MUaG7 X-Received: by 2002:a17:902:8b83:: with SMTP id ay3mr1303650plb.1.1552612824959; Thu, 14 Mar 2019 18:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552612824; cv=none; d=google.com; s=arc-20160816; b=0JkepguKhfDWBd+1BtjadNpH1qXreQw09W2wS29mR6k8zaISQhkwcmhOTXNQVOBcaM 8zhk7fRFhINc/VeTpGtOO6FQk5nYtR6S/sNTn7W9zQ2FIZ24sViT/ZFU1a30y8t6TGKH YzpaE/FaaPbZn98x0opa6JliDbTSHk46i5cfHmtoxzZsXfGnjMyaRkjNPR9QK6iD+o6q cGKlvse1zVoFLTW9e6C6EJD6V1+XC0w7Hgl1WgZxVBfjoONqfEb1ZBFDbog0fSabePH9 T+Q+9LcvgkIaH73dH5RMNIyd7Q4IWHeiP1qlRR09DwFnElrlKwkJaJrx64B6S2N4sDWe QY3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=57nb8+i4njYf0Sx7vK0uz/Fy+Wk35vcKfI9GvYHLB2g=; b=0NzQ8NHbK5tu/tjQyi/8E7ByagDOTEIiqtuvzxRBtYhXSNL+O+HYsw8vX5w3w8fGQ/ 8GCicl9J1Ip0xX++qut6u07I/ZLS6YB1kjPWNgyioq6O0MujHvjKAkCRgrUswFIiJEA9 R73owS/4vY5KkGT8uswc+ZsXpXjnZu6xshiqqHhVD8J2Owrvb2s8ZRqhCfdZwhFyfjG9 VoZLG9bFDGFm5gVrF5ed3pfFoBxK4A2Y8x24RxTlX6ayS7/ShV32/ULiJHLHzCKsNbFc aJlYFphOncfNFVyAwM96QqmFPxV/dCEujBa8msDwET0UcoMoAg4kiosMuo5dav67Tpqz Ug7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JbXK+ZRj; 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 u18si610130pfm.84.2019.03.14.18.19.57; Thu, 14 Mar 2019 18:20:24 -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=JbXK+ZRj; 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 S1727652AbfCOBS7 (ORCPT + 99 others); Thu, 14 Mar 2019 21:18:59 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:36420 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727254AbfCOBS7 (ORCPT ); Thu, 14 Mar 2019 21:18:59 -0400 Received: by mail-ed1-f68.google.com with SMTP id e4so6270175edi.3 for ; Thu, 14 Mar 2019 18:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=57nb8+i4njYf0Sx7vK0uz/Fy+Wk35vcKfI9GvYHLB2g=; b=JbXK+ZRjGhJk5BgVQdbUDEY/bLWxoWGXnCsqK8tlWR02Wm84qrfAZoWQ3eVrM9eYBC meYNhXoP9OMHPFElx0lyW2R4r4o5NnqL+RLQbhZQir++2KxEsNiHoI1ltttcNw05ToNl akU1K7vWbmDYV/NiiTS9VWhmxq3Q/2NQhsN9JtP+iT+psUuLDOp/6AnE/s0kT8C93SRb NCJ1IMjOR3N0vp0KJqhczBw/nKGRE5qQlW+2yeITcnFLyi60qbnD4tND+jt5kB15W057 PRvzYzuhGap9BcOBPF6cJXAdtZ44/Aeoonuq9WWQHOuPX2szsAdNMZG/ydJGU+wOvREV 8HvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=57nb8+i4njYf0Sx7vK0uz/Fy+Wk35vcKfI9GvYHLB2g=; b=oZ72XH0vgdclQZTX++eF4v0Rt67UtPmAUjDyHbz3tZsd/CJLRXzg99zpLCDhNdxjSF vRAQwv4sgrgtFqJl2DwX8dbfPUIWWrcJd2YG0fDSJEacku1iAkDAUdU9dFTUHOyaew0m Y5bLO7X/1U1e0d70ujZWaQbjXYXeA0Im9L6+RKxE1ei/3nxqtRU6Csi5J3rQOm9T0Zi3 4WB3jsRLGiQH9KavYUcjh02Q0tyvhBv6vAUXPp2OVMWc+za3917ggR45cHDsjDV3wPZC RkP8h4k69aJoeZOh9n52mFpAyc+CITS6Z86068qrHtZnKVS/dlaUuorK+MBGR0d0jJq4 e0YA== X-Gm-Message-State: APjAAAU60sGO8NU7sQ89eaDrPq0D0ApxjCDuw9rlDfYE9VkPYHQEBkoU 0IDRJAaqhq6h1/BnOD8s42bUOdZ/kRQ77TVxvSDlEQ== X-Received: by 2002:a05:6402:1596:: with SMTP id c22mr876354edv.122.1552612737406; Thu, 14 Mar 2019 18:18:57 -0700 (PDT) MIME-Version: 1.0 References: <1552561932-23776-1-git-send-email-huangzhaoyang@gmail.com> In-Reply-To: <1552561932-23776-1-git-send-email-huangzhaoyang@gmail.com> From: Zhaoyang Huang Date: Fri, 15 Mar 2019 09:18:46 +0800 Message-ID: Subject: Re: [PATCH] driver : staging : ion: optimization for decreasing memory fragmentaion To: "open list:ANDROID ION DRIVER" , "open list:ANDROID ION DRIVER" , "moderated list:ANDROID ION DRIVER" , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi All, I would like to explain more for the purpose of this patch. During our daily test on android system, we found that there is always showing the memory fragmentation after some test cases(etc camera snapshot), which lead to huge amount of order0 pages which other page blocks remain none(200M order0 page blocks in a 1G RAM system). By analysing the DDR dump file, we can find that it is the ION SYSTEM HEAP which cut the whole memory into pieces. That is to say, Burst huge order0 allocation is alike a knife that cut higher order blocks into small one and can not back to original buddy somehow. On Thu, Mar 14, 2019 at 7:12 PM Zhaoyang Huang wrote: > > 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 >