From patchwork Tue Sep 4 10:47:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10587073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 553D0175A for ; Tue, 4 Sep 2018 10:47:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46B4B28AC4 for ; Tue, 4 Sep 2018 10:47:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37E9228ADC; Tue, 4 Sep 2018 10:47:57 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 CC17328AC4 for ; Tue, 4 Sep 2018 10:47:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8B8EF21A09130; Tue, 4 Sep 2018 03:47:56 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F176521A09130 for ; Tue, 4 Sep 2018 03:47:55 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id f4-v6so1483441pgq.5 for ; Tue, 04 Sep 2018 03:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BNS15GySw45MLcrj6NgFJRkc/1V72+qIGsnSMM50p6c=; b=lR4Ayoa8Egf7LcfLET+hKFEJCPY9ST2ocafcSClgn6l8lKLraDjC3U7ceAi1inQfQ2 bpsGz+i3knINtNig38Y8RW2Gr9KKHKko8IA49BEQbt3uXrmSiUb2b2hzVXrt9vy3UOko Rbu3w361pScDKqN8ifW2M+tYX3Lao6Z1VUMot9hrEmP2M56yTMtlbzRyhqyKHUl9QRzZ 3+PY/laKuAgn2vLp8NRukCnJpLJVOMdoSRu/1G8cjdWzYN63E0Z/mK8615t/DfG/TtRj JOfWQk8VwEg3EPFMPvVGoKpe/iSO9M2MbgHfvTItkwZisKRSTChiFlNY/Oe9+a8l4yc0 Wxbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BNS15GySw45MLcrj6NgFJRkc/1V72+qIGsnSMM50p6c=; b=qsVGCbJBJd9bdwxdUuKcOFRgtV8ia2Ue0fT8P1K3bdZBx0qwSu4dGlF6FcmGBaUPWy ucEHVstX+FmjPFbQzPoLJHYj2l+PNKmkzUWDCgUTJdCJVUjKY45aM6ibqY5vjIi89oMw 2CQsRqu7D2YzeZox/G6ghvyO7Nc1Bl8YAWZwzE+/djk/vV/qeYFrXpNEMQ2Gz0Z75r4g aSviRYFgsGRsQ8bOcJ5RKtaU3DDXNGeQ/u2AGN1pk7TXOic8GWg0LxymUIkCbbhtedxi 9hUduZW5hJzmgqGrggYoBXl0pdimp3E3CSD+JbIwhb/fRJI8PTZk68GCeNmDDMPy+HKm jrFg== X-Gm-Message-State: APzg51Bal7iGB95c5cqWgeUV8CvkxcbRBtU7YzPYI/YQT8zJcKVwCjIT FZNr4+32YOky7jdhGLmDxCw= X-Google-Smtp-Source: ANB0VdYzYQwdTWVWI6EjIXXnKwmyr300PU2WWYYdR3guvGGe0fj2mfgFa74dkAA39tmgBuESYY2vFg== X-Received: by 2002:a63:a51c:: with SMTP id n28-v6mr366243pgf.453.1536058075480; Tue, 04 Sep 2018 03:47:55 -0700 (PDT) Received: from localhost.localdomain ([45.56.155.158]) by smtp.gmail.com with ESMTPSA id d6-v6sm27917315pgt.66.2018.09.04.03.47.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 03:47:54 -0700 (PDT) From: Ocean He To: dan.j.williams@intel.com, ross.zwisler@linux.intel.com, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH v2] libnvdimm, region_devs: stop NDD_ALIASING bit test if one test pass Date: Tue, 4 Sep 2018 06:47:42 -0400 Message-Id: <1536058062-18894-1-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He There is no need to finish entire loop to execute NDD_ALIASING bit test against every nvdimm->flags. In practice, all the nd_mapping->nvdimm have the same flags. So it's safe to return ND_DEVICE_NAMESPACE_PMEM if the NDD_ALIASING bit is found inside the loop, while saving a few cpu cycles. Signed-off-by: Ocean He --- v1: https://lkml.org/lkml/2018/8/19/4 v2: Per Vishal's comments in patch v1, remove 'alias' variable. In the loop, just return ND_DEVICE_NAMESPACE_PMEM if the NDD_ALIASING bit is found for any mapping. Outside the loop, simply return ND_DEVICE_NAMESPACE_IO. The following test pass on Lenovo ThinkSystem SR630 based on 4.19-rc1. # ndctl create-namespace -r region0 -s 1g -t pmem -m fsdax # ndctl create-namespace -r region0 -s 1g -t pmem -m sector # ndctl create-namespace -r region0 -s 1g -t pmem -m devdax # ndctl list [ { "dev":"namespace0.2", "mode":"devdax", "map":"dev", "size":1054867456, "uuid":"fc3a2126-9b8e-4ab4-baa4-a3ec7f62a326", "raw_uuid":"eadc6965-daee-48c5-a0ae-1865ee0c8573", "chardev":"dax0.2", "numa_node":0 }, { "dev":"namespace0.1", "mode":"sector", "size":1071616000, "uuid":"0d81d040-93a1-45c6-9791-3dbb7b5f89d2", "raw_uuid":"2b1b29e6-0510-4dcf-9902-43b77ccb9df5", "sector_size":4096, "blockdev":"pmem0.1s", "numa_node":0 }, { "dev":"namespace0.0", "mode":"fsdax", "map":"dev", "size":1054867456, "uuid":"cbff92ed-cd45-4d24-9353-7a56d42122b1", "raw_uuid":"f6ea1001-5ef0-4942-889a-99005079ab5d", "sector_size":512, "blockdev":"pmem0", "numa_node":0 } ] # reboot and OS could boot up normally # ndctl destroy-namespace namespace0.2 -f # ndctl destroy-namespace namespace0.1 -f # ndctl destroy-namespace namespace0.0 -f drivers/nvdimm/region_devs.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index fa37afc..16ee153 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -228,19 +228,18 @@ void nd_blk_region_set_provider_data(struct nd_blk_region *ndbr, void *data) int nd_region_to_nstype(struct nd_region *nd_region) { if (is_memory(&nd_region->dev)) { - u16 i, alias; + u16 i; - for (i = 0, alias = 0; i < nd_region->ndr_mappings; i++) { + for (i = 0; i < nd_region->ndr_mappings; i++) { struct nd_mapping *nd_mapping = &nd_region->mapping[i]; struct nvdimm *nvdimm = nd_mapping->nvdimm; if (test_bit(NDD_ALIASING, &nvdimm->flags)) - alias++; + return ND_DEVICE_NAMESPACE_PMEM; } - if (alias) - return ND_DEVICE_NAMESPACE_PMEM; - else - return ND_DEVICE_NAMESPACE_IO; + + return ND_DEVICE_NAMESPACE_IO; + } else if (is_nd_blk(&nd_region->dev)) { return ND_DEVICE_NAMESPACE_BLK; }