From patchwork Fri Dec 29 12:34:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuchaowei110@gmail.com X-Patchwork-Id: 10137895 X-Patchwork-Delegate: snitzer@redhat.com 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 D11D160375 for ; Sat, 30 Dec 2017 19:29:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0336286D2 for ; Sat, 30 Dec 2017 19:29:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B412328753; Sat, 30 Dec 2017 19:29:34 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 54F64286D2 for ; Sat, 30 Dec 2017 19:29:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93F0D61B8F; Sat, 30 Dec 2017 19:29:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74A1360C95; Sat, 30 Dec 2017 19:29:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4F6AE41284; Sat, 30 Dec 2017 19:29:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vBTCb3rL029833 for ; Fri, 29 Dec 2017 07:37:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4596060600; Fri, 29 Dec 2017 12:37:03 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6926C18C50; Fri, 29 Dec 2017 12:37:00 +0000 (UTC) Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3927C5D68C; Fri, 29 Dec 2017 12:36:59 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id r2so5569724pgq.13; Fri, 29 Dec 2017 04:36:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date:in-reply-to:references; bh=WVn3T6TpMu/B8Pi+CXqXcDhtHbwnL302BBq5LF8Fij0=; b=MBtOiWZV2ru5D5K5rFba6gqdDkw4fSyByMB9OlsXRqyizaxMxpRNIDr/kKdDdyBAU/ Gb2/TpCfIYjuuRLJWOE2CXSTpisu+dIxVUGBJN8Ro8+GJ7wvv+yn3wt9n3d34ApaMzWu 76ksN4Aa1gHp2EOq4P1kU9XXAlNAN5ybNB1N/Mt0XLvQwweqt1UaJw1QpyNrbhZ/ZiDY +lmBm0csk9y7fBBRHC0OIRELYsRBFALdqIIkXuTkLKjlAhST8DZMf/e8psWmq6QPzGgE RuUFLdbZduFgv7Gzp3VsltULQGvUfOeSb8NQghrzbaRcPCFyCiTrs9jLWvwtUsru8maU hjbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date:in-reply-to :references; bh=WVn3T6TpMu/B8Pi+CXqXcDhtHbwnL302BBq5LF8Fij0=; b=pWCiHrlLVMO2xEg9SGZ28gDhJ139RNphieLl5Pa6Y7iynxafE5Uev5v+IFTXyYGzMP MVnWYYls1w81nY4czfK+R7Be8Kx9ndhgOPZSm1Cu7x2AxelK7o2uhltQMZiDuWM7nVBX 1mJTvGwxZT2jO6tWT92gDFrjYgaAi++Ml4vsmcVNvXNDVTWQUvzIqL116U7sPjSOsdpS NDJhs9BC09Ucjcj51LKQtMk/R/oWrzCTAWkkO4hmgZ7UnLgVm7I3Zvy4BbDybaCO/tQx bis5W9yqmZYrHqx9Dma8OAaKDZF7Mlijb1wy8ryC7J0/ypimblNgVx1UpsmzYhps6wRo Nb0A== X-Gm-Message-State: AKGB3mKceZQuOheRVypb8VSf+nuoDDbdXgalhTkUOdLUdv1iINMEwIJT dErk0Tr55/h82MiGmanVUj0MPc3K79c= X-Google-Smtp-Source: ACJfBos5kMMppVScDBpYOaa/DCVhSdmsrBB03JuYxqDC5QRNt1BiAx8i0baJ1IGgSAm5AVfYT2YAsQ== X-Received: by 10.99.172.10 with SMTP id v10mr31540001pge.35.1514551018590; Fri, 29 Dec 2017 04:36:58 -0800 (PST) Received: from localhost.localdomain ([104.194.95.68]) by smtp.gmail.com with ESMTPSA id a20sm17777300pgw.27.2017.12.29.04.36.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Dec 2017 04:36:58 -0800 (PST) Message-ID: <5a4636ea.5465650a.6d7db.95fe@mx.google.com> X-Google-Original-Message-ID: <20171229123400.20127-3-liuchaowei> From: liuchaowei110@gmail.com X-Google-Original-From: liuchaowei To: agk@redhat.com Date: Fri, 29 Dec 2017 20:34:00 +0800 In-Reply-To: <20171229123400.20127-1-liuchaowei> References: <20171229123400.20127-1-liuchaowei> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Dec 2017 12:36:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 29 Dec 2017 12:36:59 +0000 (UTC) for IP:'74.125.83.65' DOMAIN:'mail-pg0-f65.google.com' HELO:'mail-pg0-f65.google.com' FROM:'liuchaowei110@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.83.65 mail-pg0-f65.google.com 74.125.83.65 mail-pg0-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Sat, 30 Dec 2017 14:28:54 -0500 Cc: snitzer@redhat.com, linux-doc@vger.kernel.org, corbet@lwn.net, neilb@suse.com, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, dm-devel@redhat.com, liuchaowei Subject: [dm-devel] [PATCH 2/2] dm: optimze stripe index search algorithm X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 30 Dec 2017 19:29:33 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP From: liuchaowei The previous stripe index search algorithm use sequential search and it's very slow if there are many and many physical storage devices. The new alrogithm save the stripe index into stripe node structure, and this driver will fetch stripe index from stripe node pointer directly, faster than sequential search from an array Change-Id: Ia1b3e01d54484fd40b82c52c0777ff36aac721b3 Signed-off-by: liuchaowei --- drivers/md/dm-asymmetric-stripe.c | 40 ++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-asymmetric-stripe.c b/drivers/md/dm-asymmetric-stripe.c index ead77ff25c6b..4902fd6c4674 100644 --- a/drivers/md/dm-asymmetric-stripe.c +++ b/drivers/md/dm-asymmetric-stripe.c @@ -34,6 +34,11 @@ typedef struct asymmetric_stripe asm_stripe; typedef struct asymmetric_stripe_c asm_stripe_c; +typedef struct asymmetric_stripe_node asm_stripe_node; + +struct asymmetric_stripe_node { + uint32_t stripe_id; +}; struct asymmetric_stripe { struct dm_dev *dev; @@ -42,6 +47,7 @@ struct asymmetric_stripe { sector_t physical_start; sector_t stripe_width; sector_t opt_io_size; + sector_t internal_offs; uint32_t ratio; atomic_t error_count; @@ -63,6 +69,7 @@ struct asymmetric_stripe_c { /* Work struct used for triggering events*/ struct work_struct trigger_event; + asm_stripe_node *node; asm_stripe stripe[0]; }; @@ -99,10 +106,13 @@ static int get_stripe(struct dm_target *ti, unsigned int stripe, char **argv) { + static uint32_t chunk_id; unsigned long long start; char dummy; int ret; unsigned int id = stripe; + sector_t offs_prev, size; + uint32_t i; if (sscanf(argv[1], "%llu%c", &start, &dummy) != 1) return -EINVAL; @@ -116,6 +126,17 @@ static int get_stripe(struct dm_target *ti, sc->stripe[id].stripe_width = sc->avg_width * sc->stripe[id].ratio; sc->stripe[id].opt_io_size = sc->chunk_size * sc->stripe[id].ratio; + if (id > 0) { + offs_prev = sc->stripe[id-1].internal_offs; + size = offs_prev + sc->stripe[id-1].opt_io_size; + } else + size = 0; + + sc->stripe[id].internal_offs = size; + + for (i = 0; i < sc->stripe[id].ratio; i++, chunk_id++) + sc->node[chunk_id].stripe_id = id; + return 0; } @@ -127,6 +148,7 @@ static int set_stripe_ratio(struct dm_target *ti, unsigned int i; uint32_t r = 0, ratio; char *tmp_ratio = ratio_str; + size_t len; if (sizeof(sc->ratio_str) < strlen(ratio_str)) { ti->error = "Too big stripe ratio string"; @@ -146,6 +168,13 @@ static int set_stripe_ratio(struct dm_target *ti, r += ratio; } + len = sizeof(asm_stripe_node) * r; + sc->node = kmalloc(len, GFP_KERNEL); + if (sc->node == NULL) { + ti->error = "Memory allocation for striped node failed"; + return -ENOMEM; + } + sc->total_ratio = r; sc->avg_width = ti->len / r; sc->stripe_size = r * sc->chunk_size; @@ -245,6 +274,7 @@ static int asymmetric_stripe_ctr(struct dm_target *ti, parse_error: while (i--) dm_put_device(ti, sc->stripe[i].dev); + kfree(sc->node); kfree(sc); return -EINVAL; } @@ -254,6 +284,7 @@ static inline sector_t stripe_index_fetch(asm_stripe_c *sc, uint32_t *stripe) { sector_t width_offset; + uint32_t chunk_id; if (sc->stripe_size_shift < 0) width_offset = sector_div(*sector, sc->stripe_size); @@ -262,11 +293,9 @@ static inline sector_t stripe_index_fetch(asm_stripe_c *sc, *sector >>= sc->stripe_size_shift; } - for (*stripe = 0; *stripe < sc->stripes; (*stripe)++) { - if (width_offset < sc->stripe[*stripe].opt_io_size) - break; - width_offset -= sc->stripe[*stripe].opt_io_size; - } + chunk_id = width_offset / sc->chunk_size; + *stripe = sc->node[chunk_id].stripe_id; + width_offset -= sc->stripe[*stripe].internal_offs; return width_offset; } @@ -280,6 +309,7 @@ static void asymmetric_stripe_dtr(struct dm_target *ti) dm_put_device(ti, sc->stripe[i].dev); flush_work(&sc->trigger_event); + kfree(sc->node); kfree(sc); }