Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965960AbcCPIHq (ORCPT ); Wed, 16 Mar 2016 04:07:46 -0400 Received: from mail.kernel.org ([198.145.29.136]:59089 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965867AbcCPIHc (ORCPT ); Wed, 16 Mar 2016 04:07:32 -0400 From: lizf@kernel.org To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Joe Thornber , Mike Snitzer , Zefan Li Subject: [PATCH 3.4 012/107] dm thin: allocate the cell_sort_array dynamically Date: Wed, 16 Mar 2016 16:05:06 +0800 Message-Id: <1458115601-5762-12-git-send-email-lizf@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458115541-5712-1-git-send-email-lizf@kernel.org> References: <1458115541-5712-1-git-send-email-lizf@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2151 Lines: 73 From: Joe Thornber 3.4.111-rc1 review patch. If anyone has any objections, please let me know. ------------------ commit a822c83e47d97cdef38c4352e1ef62d9f46cfe98 upstream. Given the pool's cell_sort_array holds 8192 pointers it triggers an order 5 allocation via kmalloc. This order 5 allocation is prone to failure as system memory gets more fragmented over time. Fix this by allocating the cell_sort_array using vmalloc. Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer [lizf: Backported 3.4: it's prinson_{create,destroy}() that need fixing] Signed-off-by: Zefan Li --- drivers/md/dm-thin.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index e811e44..862612e 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -13,6 +13,7 @@ #include #include #include +#include #define DM_MSG_PREFIX "thin" @@ -149,9 +150,7 @@ static struct bio_prison *prison_create(unsigned nr_cells) { unsigned i; uint32_t nr_buckets = calc_nr_buckets(nr_cells); - size_t len = sizeof(struct bio_prison) + - (sizeof(struct hlist_head) * nr_buckets); - struct bio_prison *prison = kmalloc(len, GFP_KERNEL); + struct bio_prison *prison = kmalloc(sizeof(*prison), GFP_KERNEL); if (!prison) return NULL; @@ -164,9 +163,15 @@ static struct bio_prison *prison_create(unsigned nr_cells) return NULL; } + prison->cells = vmalloc(sizeof(*prison->cells) * nr_buckets); + if (!prison->cells) { + mempool_destroy(prison->cell_pool); + kfree(prison); + return NULL; + } + prison->nr_buckets = nr_buckets; prison->hash_mask = nr_buckets - 1; - prison->cells = (struct hlist_head *) (prison + 1); for (i = 0; i < nr_buckets; i++) INIT_HLIST_HEAD(prison->cells + i); @@ -175,6 +180,7 @@ static struct bio_prison *prison_create(unsigned nr_cells) static void prison_destroy(struct bio_prison *prison) { + vfree(prison->cells); mempool_destroy(prison->cell_pool); kfree(prison); } -- 1.9.1