dm log: use standard kernel module refcounts
PATCH 1/2 dm log: use standard kernel module refcounts
Avoid private module usage accounting by removing 'use' from dm_dirty_log_internal. The standard module reference counting is sufficient.
--- drivers/md/dm-log.c | 19 +++---------------- 1 files changed, 3 insertions(+), 16 deletions(-)
drivers/md/dm-log.c +3 -16
@@ -20,7 +20,6 @@ struct dm_dirty_log_internal {struct dm_dirty_log_type *type;struct list_head list; -long use; };static LIST_HEAD (_log_types);
@@ -44,12 +43,8 @@ static struct dm_dirty_log_internal *_get_dirty_log_type(const char *name)spin_lock (&_lock); log_type =__find_dirty_log_type (name); -if (log_type) { -if (!log_type->use && !try_module_get (log_type->type->module)) - log_type =NULL ; -else - log_type->use++; - } +if (log_type && !try_module_get (log_type->type->module)) + log_type =NULL ;spin_unlock (&_lock);
@@ -120,10 +115,7 @@ static void put_type(struct dm_dirty_log_type *type)if (!log_type) goto out; -if (!--log_type->use) -module_put (type->module); - -BUG_ON (log_type->use <0 ); +module_put (type->module); out:spin_unlock (&_lock);
@@ -173,11 +165,6 @@ int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)return -EINVAL ; } -if (log_type->use) { -spin_unlock (&_lock); -return -ETXTBSY ; - } -list_del (&log_type->list);spin_unlock (&_lock);
Signature · 1 line
1.6.0.6
PATCH 2/2 dm log: remove struct dm_dirty_log_internal
Remove the 'dm_dirty_log_internal' structure. The resulting cleanup eliminates extra memory allocations. Therefore exposing the internal list_head to the external 'dm_dirty_log_type' structure is a worthwhile compromise.
--- drivers/md/dm-log.c | 60 ++++++++++------------------------------- include/linux/dm-dirty-log.h | 3 ++ 2 files changed, 18 insertions(+), 45 deletions(-)
drivers/md/dm-log.c +15 -45
@@ -16,34 +16,28 @@#define DM_MSG_PREFIX "dirty region log" -struct dm_dirty_log_internal { -struct dm_dirty_log_type *type; - -struct list_head list; -}; -static LIST_HEAD (_log_types);static DEFINE_SPINLOCK (_lock); -static struct dm_dirty_log_internal *__find_dirty_log_type (const char *name) +static struct dm_dirty_log_type *__find_dirty_log_type (const char *name) { -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;list_for_each_entry (log_type, &_log_types, list) -if (!strcmp (name, log_type->type->name)) +if (!strcmp (name, log_type->name))return log_type;return NULL ; } -static struct dm_dirty_log_internal *_get_dirty_log_type (const char *name) +static struct dm_dirty_log_type *_get_dirty_log_type (const char *name) { -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;spin_lock (&_lock); log_type =__find_dirty_log_type (name); -if (log_type && !try_module_get (log_type->type->module)) +if (log_type && !try_module_get (log_type->module)) log_type =NULL ;spin_unlock (&_lock);
@@ -71,14 +65,14 @@ static struct dm_dirty_log_internal *_get_dirty_log_type(const char *name)static struct dm_dirty_log_type *get_type (const char *type_name) {char *p, *type_name_dup; -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;if (!type_name)return NULL ; log_type =_get_dirty_log_type (type_name);if (log_type) -return log_type->type; +return log_type; type_name_dup =kstrdup (type_name,GFP_KERNEL );if (!type_name_dup) {
@@ -100,19 +94,16 @@ static struct dm_dirty_log_type *get_type(const char *type_name)kfree (type_name_dup); -return log_type ? log_type->type :NULL ; +return log_type; }static void put_type (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type; -if (!type)return ; -spin_lock (&_lock); - log_type =__find_dirty_log_type (type->name); -if (!log_type) +spin_lock (&_lock); +if (!__find_dirty_log_type (type->name)) goto out;module_put (type->module);
@@ -121,32 +112,15 @@ out:spin_unlock (&_lock); } -static struct dm_dirty_log_internal *_alloc_dirty_log_type (struct dm_dirty_log_type *type) -{ -struct dm_dirty_log_internal *log_type =kzalloc (sizeof (*log_type), -GFP_KERNEL ); - -if (log_type) - log_type->type = type; - -return log_type; -} -int dm_dirty_log_type_register (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type =_alloc_dirty_log_type (type);int r =0 ; -if (!log_type) -return -ENOMEM ; -spin_lock (&_lock);if (!__find_dirty_log_type (type->name)) -list_add (&log_type->list, &_log_types); -else { -kfree (log_type); +list_add (&type->list, &_log_types); +else r = -EEXIST ; - }spin_unlock (&_lock);return r;
@@ -155,20 +129,16 @@ EXPORT_SYMBOL(dm_dirty_log_type_register);int dm_dirty_log_type_unregister (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type; -spin_lock (&_lock); - log_type =__find_dirty_log_type (type->name); -if (!log_type) { +if (!__find_dirty_log_type (type->name)) {spin_unlock (&_lock);return -EINVAL ; } -list_del (&log_type->list); +list_del (&type->list);spin_unlock (&_lock); -kfree (log_type);return 0 ; }
include/linux/dm-dirty-log.h +3 -0
@@ -28,6 +28,9 @@ struct dm_dirty_log_type {const char *name;struct module *module; +/* For internal device-mapper use */ +struct list_head list; +int (*ctr)(struct dm_dirty_log *log,struct dm_target *ti,unsigned argc,char **argv);void (*dtr)(struct dm_dirty_log *log);
Signature · 1 line
1.6.0.6
Re: [PATCH 2/2] dm log: remove struct dm_dirty_log_internal
Code looks good. I haven't tested.
brassow
Quoted 184 lines · Mike Snitzer
Remove the '
dm_dirty_log_internal' structure. The resulting cleanup eliminates extra memory allocations. Therefore exposing the internallist_headto the external 'dm_dirty_log_type' structure is a worthwhile compromise.Signed-off-by Mike Snitzer <[email protected]>---
drivers/md/dm-log.c| 60 ++++++++++------------------------------- include/linux/dm-dirty-log.h | 3 ++ 2 files changed, 18 insertions(+), 45 deletions(-)drivers/md/dm-log.c +6
-12@@ -16,34 +16,28 @@#define DM_MSG_PREFIX "dirty region log" -struct dm_dirty_log_internal { -struct dm_dirty_log_type *type; - -struct list_head list; -}; -static LIST_HEAD (_log_types);static DEFINE_SPINLOCK (_lock); -static struct dm_dirty_log_internal *__find_dirty_log_type (const char *name) +static struct dm_dirty_log_type *__find_dirty_log_type (const char *name) { -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;list_for_each_entry (log_type, &_log_types, list) -if (!strcmp (name, log_type->type->name)) +if (!strcmp (name, log_type->name))return log_type;return NULL ; } -static struct dm_dirty_log_internal *_get_dirty_log_type (const char *name) +static struct dm_dirty_log_type *_get_dirty_log_type (const char *name) { -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;spin_lock (&_lock); log_type =__find_dirty_log_type (name); -if (log_type && !try_module_get (log_type->type->module)) +if (log_type && !try_module_get (log_type->module))log_type = NULL; spin_unlock(&_lock);drivers/md/dm-log.c +2
-2@@ -71,14 +65,14 @@ static struct dm_dirty_log_internal *_get_dirty_log_type(const char *name)static struct dm_dirty_log_type *get_type (const char *type_name) {char *p, *type_name_dup; -struct dm_dirty_log_internal *log_type; +struct dm_dirty_log_type *log_type;if (!type_name)return NULL ; log_type =_get_dirty_log_type (type_name);if (log_type) -return log_type->type; +return log_type; type_name_dup =kstrdup (type_name,GFP_KERNEL );if (!type_name_dup) {drivers/md/dm-log.c +3
-6@@ -100,19 +94,16 @@ static struct dm_dirty_log_type *get_type(const char *type_name)kfree (type_name_dup ); -return log_type ? log_type->type :NULL ; +return log_type; }static void put_type (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type; -if (!type)return ; -spin_lock (&_lock); - log_type =__find_dirty_log_type (type->name); -if (!log_type) +spin_lock (&_lock); +if (!__find_dirty_log_type (type->name)) goto out;module_put(type->module);drivers/md/dm-log.c +2
-19@@ -121,32 +112,15 @@ out:spin_unlock (&_lock); } -static struct dm_dirty_log_internal *_alloc_dirty_log_type (struct dm_dirty_log_type *type) -{ -struct dm_dirty_log_internal *log_type =kzalloc (sizeof (*log_type), -GFP_KERNEL ); - -if (log_type) - log_type->type = type; - -return log_type; -} -int dm_dirty_log_type_register (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type =_alloc_dirty_log_type (type);int r =0 ; -if (!log_type) -return -ENOMEM ; -spin_lock (&_lock);if (!__find_dirty_log_type (type->name)) -list_add (&log_type->list, &_log_types); -else { -kfree (log_type); +list_add (&type->list, &_log_types); +else r = -EEXIST ; - }spin_unlock (&_lock);return r;drivers/md/dm-log.c +2
-6@@ -155,20 +129,16 @@ EXPORT_SYMBOL(dm_dirty_log_type_register);int dm_dirty_log_type_unregister (struct dm_dirty_log_type *type) { -struct dm_dirty_log_internal *log_type; -spin_lock (&_lock); - log_type =__find_dirty_log_type (type->name); -if (!log_type) { +if (!__find_dirty_log_type (type->name)) {spin_unlock (&_lock);return -EINVAL ; } -list_del (&log_type->list); +list_del (&type->list);spin_unlock (&_lock); -kfree (log_type);return 0 ; }include/linux/dm-dirty-log.h +3
-0@@ -28,6 +28,9 @@ struct dm_dirty_log_type {const char *name;struct module *module; +/* For internal device-mapper use */ +struct list_head list; +int (*ctr)(struct dm_dirty_log *log,struct dm_target *ti,unsigned argc,char **argv);void (*dtr)(struct dm_dirty_log *log);Signature · 6 lines
1.6.0.6 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
ACK.
brassow
Quoted 70 lines · Mike Snitzer
Avoid private module usage accounting by removing 'use' from
dm_dirty_log_internal. The standard module reference counting is sufficient.Signed-off-by Mike Snitzer <[email protected]>---
drivers/md/dm-log.c| 19 +++----------------1 files changed, 3 insertions(+), 16 deletions(-)drivers/md/dm-log.c +3
-11@@ -20,7 +20,6 @@ struct dm_dirty_log_internal {struct dm_dirty_log_type *type;struct list_head list; -long use; };static LIST_HEAD (_log_types);@@ -44,12 +43,8 @@ static struct dm_dirty_log_internal *_get_dirty_log_type(const char *name)spin_lock (&_lock); log_type =__find_dirty_log_type (name); -if (log_type) { -if (!log_type->use && !try_module_get (log_type->type->module)) - log_type =NULL ; -else - log_type->use++; - } +if (log_type && !try_module_get (log_type->type->module)) + log_type =NULL ;spin_unlock (&_lock);@@ -120,10 +115,7 @@ static void put_type(struct dm_dirty_log_type *type)if (!log_type) goto out; -if (!--log_type->use) -module_put (type->module); - -BUG_ON (log_type->use <0 ); +module_put (type->module);out:
spin_unlock(&_lock);drivers/md/dm-log.c +0
-5@@ -173,11 +165,6 @@ int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)return -EINVAL ; } -if (log_type->use) { -spin_unlock (&_lock); -return -ETXTBSY ; - } -list_del (&log_type->list);spin_unlock(&_lock);Signature · 6 lines
1.6.0.6 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel