From patchwork Fri Jul 8 10:23:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 9220441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7A6460572 for ; Fri, 8 Jul 2016 10:29:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A862928684 for ; Fri, 8 Jul 2016 10:29:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CB3328688; Fri, 8 Jul 2016 10:29:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FED228687 for ; Fri, 8 Jul 2016 10:29:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754482AbcGHK3J (ORCPT ); Fri, 8 Jul 2016 06:29:09 -0400 Received: from mga03.intel.com ([134.134.136.65]:45373 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754112AbcGHK3I (ORCPT ); Fri, 8 Jul 2016 06:29:08 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 08 Jul 2016 03:29:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,329,1464678000"; d="scan'208";a="1003105299" Received: from ahunter-desktop.fi.intel.com ([10.237.72.168]) by fmsmga001.fm.intel.com with ESMTP; 08 Jul 2016 03:29:04 -0700 From: Adrian Hunter To: Ulf Hansson Cc: linux-mmc , Alex Lemberg , Mateusz Nowak , Yuliy Izrailov , Jaehoon Chung , Dong Aisheng , Das Asutosh , Zhangfei Gao , Dorfman Konstantin , David Griego , Sahitya Tummala , Harjani Ritesh , Venu Byravarasu Subject: [PATCH V3 25/30] mmc: queue: Share mmc request array between partitions Date: Fri, 8 Jul 2016 13:23:06 +0300 Message-Id: <1467973391-29221-26-git-send-email-adrian.hunter@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467973391-29221-1-git-send-email-adrian.hunter@intel.com> References: <1467973391-29221-1-git-send-email-adrian.hunter@intel.com> Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP eMMC can have multiple internal partitions that are represented as separate disks / queues. However the card has only 1 command queue which must be empty when switching partitions. Consequently the array of mmc requests that are queued can be shared between partitions saving memory. Keep a pointer to the mmc request queue on the card, and use that instead of allocating a new one for each partition. Use a reference count to keep track of when to free it. Signed-off-by: Adrian Hunter --- drivers/mmc/card/queue.c | 43 +++++++++++++++++++++++++++++++++++++------ include/linux/mmc/card.h | 4 ++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 5a016ce19e89..1602aea0c4f7 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -197,10 +197,17 @@ static struct mmc_queue_req *mmc_queue_alloc_mqrqs(struct mmc_queue *mq, struct mmc_queue_req *mqrq; int i; + if (mq->card->mqrq) { + mq->card->mqrq_ref_cnt += 1; + return mq->card->mqrq; + } + mqrq = kcalloc(qdepth, sizeof(*mqrq), GFP_KERNEL); if (mqrq) { for (i = 0; i < mq->qdepth; i++) mqrq[i].task_id = i; + mq->card->mqrq = mqrq; + mq->card->mqrq_ref_cnt = 1; } return mqrq; @@ -211,6 +218,9 @@ static bool mmc_queue_alloc_bounce_bufs(struct mmc_queue *mq, { int i; + if (mq->card->mqrq_ref_cnt > 1) + return !!mq->mqrq[0].bounce_buf; + for (i = 0; i < mq->qdepth; i++) { mq->mqrq[i].bounce_buf = kmalloc(bouncesz, GFP_KERNEL); if (!mq->mqrq[i].bounce_buf) @@ -234,6 +244,9 @@ static int mmc_queue_alloc_bounce_sgs(struct mmc_queue *mq, { int i, ret; + if (mq->card->mqrq_ref_cnt > 1) + return 0; + for (i = 0; i < mq->qdepth; i++) { mq->mqrq[i].sg = mmc_alloc_sg(1, &ret); if (ret) @@ -251,6 +264,9 @@ static int mmc_queue_alloc_sgs(struct mmc_queue *mq, int max_segs) { int i, ret; + if (mq->card->mqrq_ref_cnt > 1) + return 0; + for (i = 0; i < mq->qdepth; i++) { mq->mqrq[i].sg = mmc_alloc_sg(max_segs, &ret); if (ret) @@ -280,6 +296,19 @@ static void mmc_queue_reqs_free_bufs(struct mmc_queue *mq) mmc_queue_req_free_bufs(&mq->mqrq[i]); } +static void mmc_queue_free_mqrqs(struct mmc_queue *mq) +{ + if (!mq->mqrq) + return; + + if (!--mq->card->mqrq_ref_cnt) { + mmc_queue_reqs_free_bufs(mq); + kfree(mq->card->mqrq); + mq->card->mqrq = NULL; + } + mq->mqrq = NULL; +} + /** * mmc_init_queue - initialise a queue structure. * @mq: mmc queue @@ -370,9 +399,7 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, return 0; cleanup_queue: - mmc_queue_reqs_free_bufs(mq); - kfree(mq->mqrq); - mq->mqrq = NULL; + mmc_queue_free_mqrqs(mq); blk_cleanup: blk_cleanup_queue(mq->queue); return ret; @@ -395,9 +422,7 @@ void mmc_cleanup_queue(struct mmc_queue *mq) blk_start_queue(q); spin_unlock_irqrestore(q->queue_lock, flags); - mmc_queue_reqs_free_bufs(mq); - kfree(mq->mqrq); - mq->mqrq = NULL; + mmc_queue_free_mqrqs(mq); mq->card = NULL; } @@ -413,6 +438,9 @@ int mmc_packed_init(struct mmc_queue *mq, struct mmc_card *card) if (mq->qdepth != 2) return -EINVAL; + if (mqrq_cur->packed) + goto out; + mqrq_cur->packed = kzalloc(sizeof(struct mmc_packed), GFP_KERNEL); if (!mqrq_cur->packed) { pr_warn("%s: unable to allocate packed cmd for mqrq_cur\n", @@ -443,6 +471,9 @@ void mmc_packed_clean(struct mmc_queue *mq) struct mmc_queue_req *mqrq_cur = &mq->mqrq[0]; struct mmc_queue_req *mqrq_prev = &mq->mqrq[1]; + if (mq->card->mqrq_ref_cnt > 1) + return; + kfree(mqrq_cur->packed); mqrq_cur->packed = NULL; kfree(mqrq_prev->packed); diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 3d7434e48566..0acf6e0a8e83 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -207,6 +207,7 @@ struct mmc_host; struct mmc_ios; struct sdio_func; struct sdio_func_tuple; +struct mmc_queue_req; #define SDIO_MAX_FUNCS 7 @@ -319,6 +320,9 @@ struct mmc_card { struct dentry *debugfs_root; struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */ unsigned int nr_parts; + + struct mmc_queue_req *mqrq; /* Shared queue structure */ + int mqrq_ref_cnt; /* Shared queue ref. count */ }; /*