From patchwork Fri Dec 13 22:24:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22404 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE17623FBA for ; Fri, 13 Dec 2013 22:27:09 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id b10sf4602548qen.2 for ; Fri, 13 Dec 2013 14:27:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=WYNvt20WbVDgHYGPeJOEWtcjKCoHGOFmJ5mbCWt5p0c=; b=ldH7tRmyf7JmdV0i9oe9jMIKe1xNRy4JhNPPrMll/Z2miWNwIa0TKPEJ5gLrGNqNKI pHKjQZrYQFhSDPQnCFfJhVVhEjCQC8/2TWHeIVTxmRdDrspk7cebnQYo3lDvhvdRGO3q Q+/slnqY/FjrmzvLHe7m3P3LC66fnhh1eGA6Ih/2TTc9uXVRMRV7dpf3a1ZDB/xNo21G SulaESXWzLkJKV3HCEI+JA/PLGocer7cf+AijS0WR8YaCy9anc7EPJ6+IXkuIlvFHi2O oGbgLfSgwJ4OZOyvZWjMgF81XO4dQwHCqOFMANnW5dOFEpQ9pgI4+u2gOXwhAQHrNR35 hSkg== X-Gm-Message-State: ALoCoQn9HxgCpSLHr6A3pFLJzH7JNDIHZEBbr5YVdUYLKxA7W3vZ2e5mEUTTMzmSZk673PAOehiR X-Received: by 10.58.171.135 with SMTP id au7mr1928321vec.22.1386973629836; Fri, 13 Dec 2013 14:27:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.3.165 with SMTP id d5ls1239515qed.77.gmail; Fri, 13 Dec 2013 14:27:09 -0800 (PST) X-Received: by 10.52.187.66 with SMTP id fq2mr27528vdc.93.1386973629672; Fri, 13 Dec 2013 14:27:09 -0800 (PST) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id im16si1203889vec.16.2013.12.13.14.27.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:09 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id o19so1696306vbm.40 for ; Fri, 13 Dec 2013 14:27:09 -0800 (PST) X-Received: by 10.53.13.44 with SMTP id ev12mr1859699vdd.17.1386973629597; Fri, 13 Dec 2013 14:27:09 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp73518vcz; Fri, 13 Dec 2013 14:27:09 -0800 (PST) X-Received: by 10.69.18.234 with SMTP id gp10mr5870870pbd.105.1386973628771; Fri, 13 Dec 2013 14:27:08 -0800 (PST) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id gn4si2497815pbc.196.2013.12.13.14.27.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.169 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id v10so2096497pde.0 for ; Fri, 13 Dec 2013 14:27:08 -0800 (PST) X-Received: by 10.66.65.134 with SMTP id x6mr6100398pas.142.1386973628391; Fri, 13 Dec 2013 14:27:08 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id qz9sm7457908pbc.3.2013.12.13.14.27.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:07 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 039/115] gpu: ion: Fix several issues with page pool Date: Fri, 13 Dec 2013 14:24:13 -0800 Message-Id: <1386973529-4884-40-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Rebecca Schultz Zavin Split out low and high mem pages so they are correctly reported when the shrinker is called. Fix potential deadlock caused by holding the page pool lock while allocationg and also needing that lock from the shrink function Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_page_pool.c | 77 ++++++++++++++++++--------- drivers/staging/android/ion/ion_priv.h | 12 +++-- drivers/staging/android/ion/ion_system_heap.c | 9 ++-- 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index 78f39f7..ea45380 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -54,24 +54,36 @@ static int ion_page_pool_add(struct ion_page_pool *pool, struct page *page) if (!item) return -ENOMEM; item->page = page; - list_add_tail(&item->list, &pool->items); - pool->count++; + if (PageHighMem(page)) { + list_add_tail(&item->list, &pool->high_items); + pool->high_count++; + } else { + list_add_tail(&item->list, &pool->low_items); + pool->low_count++; + } return 0; } -static struct page *ion_page_pool_remove(struct ion_page_pool *pool) +static struct page *ion_page_pool_remove(struct ion_page_pool *pool, bool high) { struct ion_page_pool_item *item; struct page *page; - BUG_ON(!pool->count); - BUG_ON(list_empty(&pool->items)); + if (high) { + BUG_ON(!pool->high_count); + item = list_first_entry(&pool->high_items, + struct ion_page_pool_item, list); + pool->high_count--; + } else { + BUG_ON(!pool->low_count); + item = list_first_entry(&pool->low_items, + struct ion_page_pool_item, list); + pool->low_count--; + } - item = list_first_entry(&pool->items, struct ion_page_pool_item, list); list_del(&item->list); page = item->page; kfree(item); - pool->count--; return page; } @@ -82,12 +94,15 @@ void *ion_page_pool_alloc(struct ion_page_pool *pool) BUG_ON(!pool); mutex_lock(&pool->mutex); - if (pool->count) - page = ion_page_pool_remove(pool); - else - page = ion_page_pool_alloc_pages(pool); + if (pool->high_count) + page = ion_page_pool_remove(pool, true); + else if (pool->low_count) + page = ion_page_pool_remove(pool, false); mutex_unlock(&pool->mutex); + if (!page) + page = ion_page_pool_alloc_pages(pool); + return page; } @@ -97,9 +112,9 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct page* page) mutex_lock(&pool->mutex); ret = ion_page_pool_add(pool, page); + mutex_unlock(&pool->mutex); if (ret) ion_page_pool_free_pages(pool, page); - mutex_unlock(&pool->mutex); } static int ion_page_pool_shrink(struct shrinker *shrinker, @@ -110,30 +125,38 @@ static int ion_page_pool_shrink(struct shrinker *shrinker, shrinker); int nr_freed = 0; int i; + bool high; + + if (sc->gfp_mask & __GFP_HIGHMEM) + high = true; if (sc->nr_to_scan == 0) - return pool->count * (1 << pool->order); + return high ? (pool->high_count + pool->low_count) * + (1 << pool->order) : + pool->low_count * (1 << pool->order); - mutex_lock(&pool->mutex); - for (i = 0; i < sc->nr_to_scan && pool->count; i++) { - struct ion_page_pool_item *item; + for (i = 0; i < sc->nr_to_scan; i++) { struct page *page; - item = list_first_entry(&pool->items, struct ion_page_pool_item, list); - page = item->page; - if (PageHighMem(page) && !(sc->gfp_mask & __GFP_HIGHMEM)) { - list_move_tail(&item->list, &pool->items); - continue; + mutex_lock(&pool->mutex); + if (high && pool->high_count) { + page = ion_page_pool_remove(pool, true); + } else if (pool->low_count) { + page = ion_page_pool_remove(pool, false); + } else { + mutex_unlock(&pool->mutex); + break; } - BUG_ON(page != ion_page_pool_remove(pool)); + mutex_unlock(&pool->mutex); ion_page_pool_free_pages(pool, page); nr_freed += (1 << pool->order); } pr_info("%s: shrunk page_pool of order %d by %d pages\n", __func__, pool->order, nr_freed); - mutex_unlock(&pool->mutex); - return pool->count * (1 << pool->order); + return high ? (pool->high_count + pool->low_count) * + (1 << pool->order) : + pool->low_count * (1 << pool->order); } struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) @@ -142,8 +165,10 @@ struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order) GFP_KERNEL); if (!pool) return NULL; - pool->count = 0; - INIT_LIST_HEAD(&pool->items); + pool->high_count = 0; + pool->low_count = 0; + INIT_LIST_HEAD(&pool->low_items); + INIT_LIST_HEAD(&pool->high_items); pool->shrinker.shrink = ion_page_pool_shrink; pool->shrinker.seeks = DEFAULT_SEEKS * 16; pool->shrinker.batch = 0; diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 9f32634..beb1595 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -217,8 +217,10 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, /** * struct ion_page_pool - pagepool struct - * @count: number of items in the pool - * @items: list of items + * @high_count: number of highmem items in the pool + * @low_count: number of lowmem items in the pool + * @high_items: list of highmem items + * @low_items: list of lowmem items * @shrinker: a shrinker for the items * @mutex: lock protecting this struct and especially the count * item list @@ -235,8 +237,10 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr, * on many systems */ struct ion_page_pool { - int count; - struct list_head items; + int high_count; + int low_count; + struct list_head high_items; + struct list_head low_items; struct shrinker shrinker; struct mutex mutex; void *(*alloc)(struct ion_page_pool *pool); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index b99fa0e..2204206 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -328,9 +328,12 @@ static int ion_system_heap_debug_show(struct ion_heap *heap, struct seq_file *s, int i; for (i = 0; i < num_orders; i++) { struct ion_page_pool *pool = sys_heap->pools[i]; - seq_printf(s, "%d order %u pages in pool = %lu total\n", - pool->count, pool->order, - (1 << pool->order) * PAGE_SIZE * pool->count); + seq_printf(s, "%d order %u highmem pages in pool = %lu total\n", + pool->high_count, pool->order, + (1 << pool->order) * PAGE_SIZE * pool->high_count); + seq_printf(s, "%d order %u lowmem pages in pool = %lu total\n", + pool->low_count, pool->order, + (1 << pool->order) * PAGE_SIZE * pool->low_count); } return 0; }