Skip to contentSkip to conversation

libnvdimm, region_devs: stop NDD_ALIASING bit test if one test pass

PATCH Superseded Ocean He 3 participants 3 messages Aug 19, 2018 – Sep 2, 2018 libnvdimm: non-volatile memory device

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ocean He

author
#0 lore raw

PATCH 1/1 libnvdimm, region_devs: stop NDD_ALIASING bit test if one test pass

From: Ocean He <[email protected]>

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.

Because the check of alias is "if (alias)" but not
"if (alias == nd_region->ndr_mappings)", there is no function change while just save a few cycles.

---
A test to check if all the nd_mapping->nvdimm have the same flags, using Lenovo ThinkSystem SR630 and 4.18-rc6.

# ipmctl show -dimm
DimmID  Capacity        HealthState     ActionRequired  LockState       FWVersion
0x0021  125.7 GiB       Healthy         0               Disabled        01.00.00.4888
0x0121  125.7 GiB       Healthy         0               Disabled        01.00.00.4888
0x1021  125.7 GiB       Healthy         0               Disabled        01.00.00.4888
0x1121  125.7 GiB       Healthy         0               Disabled        01.00.00.4888
# ipmctl create -f -goal -socket 0x0 PersistentMemoryType=AppDirect
# ipmctl create -f -goal -socket 0x1 PersistentMemoryType=AppDirect

# reboot, to make goal configuration take effect.

# ndctl create-namespace -r region0 -s 100m -t pmem -m fsdax
# ndctl create-namespace -r region1 -s 100m -t pmem -m fsdax
# reboot and find all the nd_mapping->nvdimm have the same flags.
 drivers/nvdimm/region_devs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +3 -1
index ec3543b..fc3bc1c 100644
@@ -234,8 +234,10 @@ int nd_region_to_nstype(struct nd_region *nd_region)
 			struct nd_mapping *nd_mapping = &nd_region->mapping[i];
 			struct nvdimm *nvdimm = nd_mapping->nvdimm;
 
-			if (test_bit(NDD_ALIASING, &nvdimm->flags))
+			if (test_bit(NDD_ALIASING, &nvdimm->flags)) {
 				alias++;
+				break;
+			}
 		}
 		if (alias)
 			return ND_DEVICE_NAMESPACE_PMEM;
Signature · 6 lines
1.8.3.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#1 lore raw
Quoted 56 lines · Ocean He

From: Ocean He <[email protected]>

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.

Because the check of alias is "if (alias)" but not
"if (alias == nd_region->ndr_mappings)", there is no function change while
just save a few cycles.

---
A test to check if all the nd_mapping->nvdimm have the same flags, using
Lenovo ThinkSystem SR630 and 4.18-rc6.

# ipmctl show -dimm

DimmID Capacity HealthState ActionRequired LockState
FWVersion
0x0021 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x0121 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x1021 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x1121 125.7
GiB Healthy 0 Disabled 01.00.00.48
88

# ipmctl create -f -goal -socket 0x0 PersistentMemoryType=AppDirect
# ipmctl create -f -goal -socket 0x1 PersistentMemoryType=AppDirect

# reboot, to make goal configuration take effect.

# ndctl create-namespace -r region0 -s 100m -t pmem -m fsdax
# ndctl create-namespace -r region1 -s 100m -t pmem -m fsdax
# reboot and find all the nd_mapping->nvdimm have the same flags.
 drivers/nvdimm/region_devs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +0 -0
index ec3543b..fc3bc1c 100644

drivers/nvdimm/region_devs.c int nd_region_to_nstype(struct nd_region · line 242

Quoted 10 lines
drivers/nvdimm/region_devs.c +2 -1
@@ -234,8 +234,10 @@ int nd_region_to_nstype(struct nd_region
 *nd_region)
 			struct nd_mapping *nd_mapping = &nd_region-
 >mapping[i];
 			struct nvdimm *nvdimm = nd_mapping->nvdimm;
 
-			if (test_bit(NDD_ALIASING, &nvdimm->flags))
+			if (test_bit(NDD_ALIASING, &nvdimm->flags))
 {
 				alias++;
+				break;

I think we can go a step further, and instead of the 'break' followed by a check for the '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. That makes it much cleaner and now we can get rid of 'alias' entirely.

drivers/nvdimm/region_devs.c int nd_region_to_nstype(struct nd_region *nd_region) · line 243

Quoted 4 lines
drivers/nvdimm/region_devs.c +1 -0
+			}
drivers/nvdimm/region_devs.c +0 -0
 		}
 		if (alias)
 			return ND_DEVICE_NAMESPACE_PMEM;

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 75 lines

-----Original Message-----
From: Verma, Vishal L <[email protected]>
Sent: Friday, August 31, 2018 5:51 AM
To: Williams, Dan J <[email protected]>; [email protected]; [email protected]; Jiang, Dave <[email protected]>
Cc: [email protected]; [email protected]; Ocean HY1 He <[email protected]>
Subject: [External] Re: [PATCH] libnvdimm, region_devs: stop NDD_ALIASING bit test if one test pass

Quoted 61 lines · Ocean He

From: Ocean He <[email protected]>

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.

Because the check of alias is "if (alias)" but not
"if (alias == nd_region->ndr_mappings)", there is no function change while
just save a few cycles.

---
A test to check if all the nd_mapping->nvdimm have the same flags, using
Lenovo ThinkSystem SR630 and 4.18-rc6.

# ipmctl show -dimm

DimmID Capacity HealthState ActionRequired LockState
FWVersion
0x0021 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x0121 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x1021 125.7
GiB Healthy 0 Disabled 01.00.00.48
88
0x1121 125.7
GiB Healthy 0 Disabled 01.00.00.48
88

# ipmctl create -f -goal -socket 0x0 PersistentMemoryType=AppDirect
# ipmctl create -f -goal -socket 0x1 PersistentMemoryType=AppDirect

# reboot, to make goal configuration take effect.

# ndctl create-namespace -r region0 -s 100m -t pmem -m fsdax
# ndctl create-namespace -r region1 -s 100m -t pmem -m fsdax
# reboot and find all the nd_mapping->nvdimm have the same flags.
 drivers/nvdimm/region_devs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +0 -0
index ec3543b..fc3bc1c 100644
@@ -234,8 +234,10 @@ int nd_region_to_nstype(struct nd_region
 *nd_region)
 			struct nd_mapping *nd_mapping = &nd_region-
 >mapping[i];
 			struct nvdimm *nvdimm = nd_mapping->nvdimm;
 
Quoted 12 lines

drivers/nvdimm/region_devs.c int nd_region_to_nstype(struct nd_region *nd_region) · line 239

Quoted 5 lines
drivers/nvdimm/region_devs.c +2 -1
-			if (test_bit(NDD_ALIASING, &nvdimm->flags))
+			if (test_bit(NDD_ALIASING, &nvdimm->flags))
 {
 				alias++;
+				break;

I think we can go a step further, and instead of the 'break' followed by a check for the '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. That makes it much cleaner and now we can get rid of 'alias' entirely.

Hi Vishal,

Thanks for comments and I would send version 2 patch later.

Ocean.

Quoted 4 lines

drivers/nvdimm/region_devs.c int nd_region_to_nstype(struct nd_region *nd_region) · line 243

Quoted 4 lines
drivers/nvdimm/region_devs.c +1 -0
+			}
drivers/nvdimm/region_devs.c +0 -0
 		}
 		if (alias)
 			return ND_DEVICE_NAMESPACE_PMEM;

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm