History

lib: Uplevel the pmem "region" ida to a global allocator

In preparation for handling platform differentiated memory types beyond persistent memory, uplevel the "region" identifier to a global number space. This enables a device-dax instance to be registered to any memory type with guaranteed unique names.

Dan Williams committed 7 years ago

Commit 33dd7071 parent 199c8478 files · +46 −11Browse files

Unified · Split

8 files
  1. drivers/nvdimm/Kconfig +1 −0
  2. drivers/nvdimm/core.c +0 −1
  3. drivers/nvdimm/nd-core.h +0 −1
  4. drivers/nvdimm/region_devs.c +4 −9
  5. include/linux/memregion.h +19 −0
  6. lib/Kconfig +3 −0
  7. lib/Makefile +1 −0
  8. lib/memregion.c +18 −0
drivers/nvdimm/Kconfig+1−0
@@ -4,6 +4,7 @@ menuconfig LIBNVDIMM · 3 unmodified lines
44 depends on PHYS_ADDR_T_64BIT
55 depends on HAS_IOMEM
66 depends on BLK_DEV
7+ select MEMREGION
78 help
89 Generic support for non-volatile memory devices including
910 ACPI-6-NFIT defined resources. On platforms that define an
drivers/nvdimm/core.c+0−1
@@ -455,7 +455,6 @@ static __exit void libnvdimm_exit(void) · 454 unmodified lines
455455 nd_region_exit();
456456 nvdimm_exit();
457457 nvdimm_bus_exit();
458− nd_region_devs_exit();
459458 nvdimm_devs_exit();
460459 }
461460
drivers/nvdimm/nd-core.h+0−1
@@ -114,7 +114,6 @@ struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev); · 113 unmodified lines
114114 int __init nvdimm_bus_init(void);
115115 void nvdimm_bus_exit(void);
116116 void nvdimm_devs_exit(void);
117−void nd_region_devs_exit(void);
118117 struct nd_region;
119118 void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
120119 void nd_region_create_ns_seed(struct nd_region *nd_region);
drivers/nvdimm/region_devs.c+4−9
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
44 */
55 #include <linux/scatterlist.h>
6+#include <linux/memregion.h>
67 #include <linux/highmem.h>
78 #include <linux/sched.h>
89 #include <linux/slab.h>
@@ -19,7 +20,6 @@ · 10 unmodified lines
1920 */
2021 #include <linux/io-64-nonatomic-hi-lo.h>
2122
22−static DEFINE_IDA(region_ida);
2323 static DEFINE_PER_CPU(int, flush_idx);
2424
2525 static int nvdimm_map_flush(struct device *dev, struct nvdimm *nvdimm, int dimm,
@@ -133,7 +133,7 @@ static void nd_region_release(struct device *dev) · 107 unmodified lines
133133 put_device(&nvdimm->dev);
134134 }
135135 free_percpu(nd_region->lane);
136− ida_simple_remove(&region_ida, nd_region->id);
136+ memregion_free(nd_region->id);
137137 if (is_nd_blk(dev))
138138 kfree(to_nd_blk_region(dev));
139139 else
@@ -985,7 +985,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, · 845 unmodified lines
985985
986986 if (!region_buf)
987987 return NULL;
988− nd_region->id = ida_simple_get(&region_ida, 0, 0, GFP_KERNEL);
988+ nd_region->id = memregion_alloc(GFP_KERNEL);
989989 if (nd_region->id < 0)
990990 goto err_id;
991991
@@ -1044,7 +1044,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, · 52 unmodified lines
10441044 return nd_region;
10451045
10461046 err_percpu:
1047− ida_simple_remove(&region_ida, nd_region->id);
1047+ memregion_free(nd_region->id);
10481048 err_id:
10491049 kfree(region_buf);
10501050 return NULL;
@@ -1216,8 +1216,3 @@ int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, · 165 unmodified lines
12161216
12171217 return device_for_each_child(&nvdimm_bus->dev, &ctx, region_conflict);
12181218 }
1219−
1220−void __exit nd_region_devs_exit(void)
1221−{
1222− ida_destroy(&region_ida);
1223−}
include/linux/memregion.h+19−0
@@ -0,0 +1,19 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef _MEMREGION_H_
3+#define _MEMREGION_H_
4+#include <linux/types.h>
5+#include <linux/errno.h>
6+
7+#ifdef CONFIG_MEMREGION
8+int memregion_alloc(gfp_t gfp);
9+void memregion_free(int id);
10+#else
11+static inline int memregion_alloc(gfp_t gfp)
12+{
13+ return -ENOMEM;
14+}
15+void memregion_free(int id)
16+{
17+}
18+#endif
19+#endif /* _MEMREGION_H_ */
lib/Kconfig+3−0
@@ -606,6 +606,9 @@ config ARCH_NO_SG_CHAIN · 605 unmodified lines
606606 config ARCH_HAS_PMEM_API
607607 bool
608608
609+config MEMREGION
610+ bool
611+
609612 # use memcpy to implement user copies for nommu architectures
610613 config UACCESS_MEMCPY
611614 bool
lib/Makefile+1−0
@@ -212,6 +212,7 @@ obj-$(CONFIG_GENERIC_NET_UTILS) += net_utils.o · 211 unmodified lines
212212
213213 obj-$(CONFIG_SG_SPLIT) += sg_split.o
214214 obj-$(CONFIG_SG_POOL) += sg_pool.o
215+obj-$(CONFIG_MEMREGION) += memregion.o
215216 obj-$(CONFIG_STMP_DEVICE) += stmp_device.o
216217 obj-$(CONFIG_IRQ_POLL) += irq_poll.o
217218
lib/memregion.c+18−0
@@ -0,0 +1,18 @@
1+// SPDX-License-Identifier: GPL-2.0-only
2+/* identifiers for device / performance-differentiated memory regions */
3+#include <linux/idr.h>
4+#include <linux/types.h>
5+
6+static DEFINE_IDA(memregion_ids);
7+
8+int memregion_alloc(gfp_t gfp)
9+{
10+ return ida_alloc(&memregion_ids, gfp);
11+}
12+EXPORT_SYMBOL(memregion_alloc);
13+
14+void memregion_free(int id)
15+{
16+ ida_free(&memregion_ids, id);
17+}
18+EXPORT_SYMBOL(memregion_free);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t