On Thu, Apr 04, 2019 at 12:08:38PM -0700, Dan Williams wrote:
+++ b/lib/Kconfig
@@ -318,6 +318,12 @@ config DECOMPRESS_LZ4
config GENERIC_ALLOCATOR
bool
+#
+# Generic IDA for memory regions
+#
Leaky abstraction -- nobody needs know that it's implemented as an IDA.
Suggest:
# Memory region ID allocation
...
+++ b/lib/memregion.c
@@ -0,0 +1,22 @@
+#include <linux/idr.h>
+#include <linux/module.h>
+
+static DEFINE_IDA(region_ida);
+
+int memregion_alloc(void)
+{
+ return ida_simple_get(®ion_ida, 0, 0, GFP_KERNEL);
+}
+EXPORT_SYMBOL(memregion_alloc);
+
+void memregion_free(int id)
+{
+ ida_simple_remove(®ion_ida, id);
+}
+EXPORT_SYMBOL(memregion_free);
+
+static void __exit memregion_exit(void)
+{
+ ida_destroy(®ion_ida);
+}
+module_exit(memregion_exit);
- Should these be EXPORT_SYMBOL_GPL?
- Can we use the new interface, ida_alloc() and ida_free()?
- Do we really want memregion_exit() to happen while there are still IDs
allocated in the IDA? I think this might well be better as:
BUG_ON(!ida_empty(®ion_ida));
Also, do we really want to call the structure the region_ida? Why not
region_ids?