diff options
author | NeilBrown <neilb@suse.com> | 2018-01-08 20:19:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-01-09 09:41:56 -0500 |
commit | 12e46c461cb901a4034b08e99b448a2b3e48333d (patch) | |
tree | 6264558832d09bb803c4e34c1495902fcd7d91ea | |
parent | 2aa8b1b728da158d8c55f0bd589468183e7865c1 (diff) |
staging: lustre: change some LIBCFS_ALLOC calls to k?alloc(GFP_KERNEL)
When an allocation happens from process context rather than
filesystem context, it is best to use GFP_KERNEL rather than
LIBCFS_ALLOC() which always uses GFP_NOFS.
This include initialization during, or prior to, mount,
and code run from separate worker threads.
So for some of these cases, switch to kmalloc, kvmalloc, or
kvmalloc_array() as appropriate.
In some cases we preserve __GFP_ZERO (via kzalloc/kvzalloc), but in
others it is clear that allocated memory is immediately initialized.
In each case, the matching LIBCFS_FREE() is converted to
kfree() or kvfree()
This is just a subset of locations that need changing.
As there are quite a lot, I've broken them up into several
ad-hoc sets to avoid review-fatigue.
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/lustre/include/linux/libcfs/libcfs_string.h | 4 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 11 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c | 22 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/libcfs/hash.c | 18 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | 9 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/libcfs/libcfs_string.c | 2 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/lnet/config.c | 2 |
7 files changed, 29 insertions, 39 deletions
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h index bb95eaf9f3d5..66463477074a 100644 --- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h | |||
@@ -85,11 +85,11 @@ static inline void | |||
85 | cfs_expr_list_values_free(u32 *values, int num) | 85 | cfs_expr_list_values_free(u32 *values, int num) |
86 | { | 86 | { |
87 | /* | 87 | /* |
88 | * This array is allocated by LIBCFS_ALLOC(), so it shouldn't be freed | 88 | * This array is allocated by kvalloc(), so it shouldn't be freed |
89 | * by OBD_FREE() if it's called by module other than libcfs & LNet, | 89 | * by OBD_FREE() if it's called by module other than libcfs & LNet, |
90 | * otherwise we will see fake memory leak | 90 | * otherwise we will see fake memory leak |
91 | */ | 91 | */ |
92 | LIBCFS_FREE(values, num * sizeof(values[0])); | 92 | kvfree(values); |
93 | } | 93 | } |
94 | 94 | ||
95 | void cfs_expr_list_free(struct cfs_expr_list *expr_list); | 95 | void cfs_expr_list_free(struct cfs_expr_list *expr_list); |
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 9fbf8a044962..bb7b19473e3a 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | |||
@@ -2576,11 +2576,7 @@ static void kiblnd_base_shutdown(void) | |||
2576 | break; | 2576 | break; |
2577 | } | 2577 | } |
2578 | 2578 | ||
2579 | if (kiblnd_data.kib_peers) { | 2579 | kvfree(kiblnd_data.kib_peers); |
2580 | LIBCFS_FREE(kiblnd_data.kib_peers, | ||
2581 | sizeof(struct list_head) * | ||
2582 | kiblnd_data.kib_peer_hash_size); | ||
2583 | } | ||
2584 | 2580 | ||
2585 | if (kiblnd_data.kib_scheds) | 2581 | if (kiblnd_data.kib_scheds) |
2586 | cfs_percpt_free(kiblnd_data.kib_scheds); | 2582 | cfs_percpt_free(kiblnd_data.kib_scheds); |
@@ -2672,8 +2668,9 @@ static int kiblnd_base_startup(void) | |||
2672 | INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs); | 2668 | INIT_LIST_HEAD(&kiblnd_data.kib_failed_devs); |
2673 | 2669 | ||
2674 | kiblnd_data.kib_peer_hash_size = IBLND_PEER_HASH_SIZE; | 2670 | kiblnd_data.kib_peer_hash_size = IBLND_PEER_HASH_SIZE; |
2675 | LIBCFS_ALLOC(kiblnd_data.kib_peers, | 2671 | kiblnd_data.kib_peers = kvmalloc_array(kiblnd_data.kib_peer_hash_size, |
2676 | sizeof(struct list_head) * kiblnd_data.kib_peer_hash_size); | 2672 | sizeof(struct list_head), |
2673 | GFP_KERNEL); | ||
2677 | if (!kiblnd_data.kib_peers) | 2674 | if (!kiblnd_data.kib_peers) |
2678 | goto failed; | 2675 | goto failed; |
2679 | for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) | 2676 | for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) |
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c index 51157ae14a9e..dc63ed2ceb97 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c | |||
@@ -1070,8 +1070,9 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, | |||
1070 | conn->ksnc_tx_carrier = NULL; | 1070 | conn->ksnc_tx_carrier = NULL; |
1071 | atomic_set(&conn->ksnc_tx_nob, 0); | 1071 | atomic_set(&conn->ksnc_tx_nob, 0); |
1072 | 1072 | ||
1073 | LIBCFS_ALLOC(hello, offsetof(struct ksock_hello_msg, | 1073 | hello = kvzalloc(offsetof(struct ksock_hello_msg, |
1074 | kshm_ips[LNET_MAX_INTERFACES])); | 1074 | kshm_ips[LNET_MAX_INTERFACES]), |
1075 | GFP_KERNEL); | ||
1075 | if (!hello) { | 1076 | if (!hello) { |
1076 | rc = -ENOMEM; | 1077 | rc = -ENOMEM; |
1077 | goto failed_1; | 1078 | goto failed_1; |
@@ -1334,8 +1335,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, | |||
1334 | rc = ksocknal_send_hello(ni, conn, peerid.nid, hello); | 1335 | rc = ksocknal_send_hello(ni, conn, peerid.nid, hello); |
1335 | } | 1336 | } |
1336 | 1337 | ||
1337 | LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, | 1338 | kvfree(hello); |
1338 | kshm_ips[LNET_MAX_INTERFACES])); | ||
1339 | 1339 | ||
1340 | /* | 1340 | /* |
1341 | * setup the socket AFTER I've received hello (it disables | 1341 | * setup the socket AFTER I've received hello (it disables |
@@ -1415,9 +1415,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route, | |||
1415 | ksocknal_peer_decref(peer); | 1415 | ksocknal_peer_decref(peer); |
1416 | 1416 | ||
1417 | failed_1: | 1417 | failed_1: |
1418 | if (hello) | 1418 | kvfree(hello); |
1419 | LIBCFS_FREE(hello, offsetof(struct ksock_hello_msg, | ||
1420 | kshm_ips[LNET_MAX_INTERFACES])); | ||
1421 | 1419 | ||
1422 | kfree(conn); | 1420 | kfree(conn); |
1423 | 1421 | ||
@@ -2269,9 +2267,7 @@ ksocknal_free_buffers(void) | |||
2269 | cfs_percpt_free(ksocknal_data.ksnd_sched_info); | 2267 | cfs_percpt_free(ksocknal_data.ksnd_sched_info); |
2270 | } | 2268 | } |
2271 | 2269 | ||
2272 | LIBCFS_FREE(ksocknal_data.ksnd_peers, | 2270 | kvfree(ksocknal_data.ksnd_peers); |
2273 | sizeof(struct list_head) * | ||
2274 | ksocknal_data.ksnd_peer_hash_size); | ||
2275 | 2271 | ||
2276 | spin_lock(&ksocknal_data.ksnd_tx_lock); | 2272 | spin_lock(&ksocknal_data.ksnd_tx_lock); |
2277 | 2273 | ||
@@ -2401,9 +2397,9 @@ ksocknal_base_startup(void) | |||
2401 | memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */ | 2397 | memset(&ksocknal_data, 0, sizeof(ksocknal_data)); /* zero pointers */ |
2402 | 2398 | ||
2403 | ksocknal_data.ksnd_peer_hash_size = SOCKNAL_PEER_HASH_SIZE; | 2399 | ksocknal_data.ksnd_peer_hash_size = SOCKNAL_PEER_HASH_SIZE; |
2404 | LIBCFS_ALLOC(ksocknal_data.ksnd_peers, | 2400 | ksocknal_data.ksnd_peers = kvmalloc_array(ksocknal_data.ksnd_peer_hash_size, |
2405 | sizeof(struct list_head) * | 2401 | sizeof(struct list_head), |
2406 | ksocknal_data.ksnd_peer_hash_size); | 2402 | GFP_KERNEL); |
2407 | if (!ksocknal_data.ksnd_peers) | 2403 | if (!ksocknal_data.ksnd_peers) |
2408 | return -ENOMEM; | 2404 | return -ENOMEM; |
2409 | 2405 | ||
diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c index 4d16147602a6..f7b3c9306456 100644 --- a/drivers/staging/lustre/lnet/libcfs/hash.c +++ b/drivers/staging/lustre/lnet/libcfs/hash.c | |||
@@ -864,12 +864,10 @@ cfs_hash_buckets_free(struct cfs_hash_bucket **buckets, | |||
864 | { | 864 | { |
865 | int i; | 865 | int i; |
866 | 866 | ||
867 | for (i = prev_size; i < size; i++) { | 867 | for (i = prev_size; i < size; i++) |
868 | if (buckets[i]) | 868 | kfree(buckets[i]); |
869 | LIBCFS_FREE(buckets[i], bkt_size); | ||
870 | } | ||
871 | 869 | ||
872 | LIBCFS_FREE(buckets, sizeof(buckets[0]) * size); | 870 | kvfree(buckets); |
873 | } | 871 | } |
874 | 872 | ||
875 | /* | 873 | /* |
@@ -889,7 +887,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, | |||
889 | if (old_bkts && old_size == new_size) | 887 | if (old_bkts && old_size == new_size) |
890 | return old_bkts; | 888 | return old_bkts; |
891 | 889 | ||
892 | LIBCFS_ALLOC(new_bkts, sizeof(new_bkts[0]) * new_size); | 890 | new_bkts = kvmalloc_array(new_size, sizeof(new_bkts[0]), GFP_KERNEL); |
893 | if (!new_bkts) | 891 | if (!new_bkts) |
894 | return NULL; | 892 | return NULL; |
895 | 893 | ||
@@ -902,7 +900,7 @@ cfs_hash_buckets_realloc(struct cfs_hash *hs, struct cfs_hash_bucket **old_bkts, | |||
902 | struct hlist_head *hhead; | 900 | struct hlist_head *hhead; |
903 | struct cfs_hash_bd bd; | 901 | struct cfs_hash_bd bd; |
904 | 902 | ||
905 | LIBCFS_ALLOC(new_bkts[i], cfs_hash_bkt_size(hs)); | 903 | new_bkts[i] = kzalloc(cfs_hash_bkt_size(hs), GFP_KERNEL); |
906 | if (!new_bkts[i]) { | 904 | if (!new_bkts[i]) { |
907 | cfs_hash_buckets_free(new_bkts, cfs_hash_bkt_size(hs), | 905 | cfs_hash_buckets_free(new_bkts, cfs_hash_bkt_size(hs), |
908 | old_size, new_size); | 906 | old_size, new_size); |
@@ -1014,7 +1012,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits, | |||
1014 | 1012 | ||
1015 | len = !(flags & CFS_HASH_BIGNAME) ? | 1013 | len = !(flags & CFS_HASH_BIGNAME) ? |
1016 | CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN; | 1014 | CFS_HASH_NAME_LEN : CFS_HASH_BIGNAME_LEN; |
1017 | LIBCFS_ALLOC(hs, offsetof(struct cfs_hash, hs_name[len])); | 1015 | hs = kzalloc(offsetof(struct cfs_hash, hs_name[len]), GFP_KERNEL); |
1018 | if (!hs) | 1016 | if (!hs) |
1019 | return NULL; | 1017 | return NULL; |
1020 | 1018 | ||
@@ -1046,7 +1044,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits, | |||
1046 | if (hs->hs_buckets) | 1044 | if (hs->hs_buckets) |
1047 | return hs; | 1045 | return hs; |
1048 | 1046 | ||
1049 | LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[len])); | 1047 | kfree(hs); |
1050 | return NULL; | 1048 | return NULL; |
1051 | } | 1049 | } |
1052 | EXPORT_SYMBOL(cfs_hash_create); | 1050 | EXPORT_SYMBOL(cfs_hash_create); |
@@ -1109,7 +1107,7 @@ cfs_hash_destroy(struct cfs_hash *hs) | |||
1109 | 0, CFS_HASH_NBKT(hs)); | 1107 | 0, CFS_HASH_NBKT(hs)); |
1110 | i = cfs_hash_with_bigname(hs) ? | 1108 | i = cfs_hash_with_bigname(hs) ? |
1111 | CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN; | 1109 | CFS_HASH_BIGNAME_LEN : CFS_HASH_NAME_LEN; |
1112 | LIBCFS_FREE(hs, offsetof(struct cfs_hash, hs_name[i])); | 1110 | kfree(hs); |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs) | 1113 | struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs) |
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c index df93d8f77ea2..23734cfb5d44 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_mem.c | |||
@@ -130,10 +130,9 @@ cfs_array_free(void *vars) | |||
130 | if (!arr->va_ptrs[i]) | 130 | if (!arr->va_ptrs[i]) |
131 | continue; | 131 | continue; |
132 | 132 | ||
133 | LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); | 133 | kvfree(arr->va_ptrs[i]); |
134 | } | 134 | } |
135 | LIBCFS_FREE(arr, offsetof(struct cfs_var_array, | 135 | kvfree(arr); |
136 | va_ptrs[arr->va_count])); | ||
137 | } | 136 | } |
138 | EXPORT_SYMBOL(cfs_array_free); | 137 | EXPORT_SYMBOL(cfs_array_free); |
139 | 138 | ||
@@ -148,7 +147,7 @@ cfs_array_alloc(int count, unsigned int size) | |||
148 | struct cfs_var_array *arr; | 147 | struct cfs_var_array *arr; |
149 | int i; | 148 | int i; |
150 | 149 | ||
151 | LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); | 150 | arr = kvmalloc(offsetof(struct cfs_var_array, va_ptrs[count]), GFP_KERNEL); |
152 | if (!arr) | 151 | if (!arr) |
153 | return NULL; | 152 | return NULL; |
154 | 153 | ||
@@ -156,7 +155,7 @@ cfs_array_alloc(int count, unsigned int size) | |||
156 | arr->va_size = size; | 155 | arr->va_size = size; |
157 | 156 | ||
158 | for (i = 0; i < count; i++) { | 157 | for (i = 0; i < count; i++) { |
159 | LIBCFS_ALLOC(arr->va_ptrs[i], size); | 158 | arr->va_ptrs[i] = kvzalloc(size, GFP_KERNEL); |
160 | 159 | ||
161 | if (!arr->va_ptrs[i]) { | 160 | if (!arr->va_ptrs[i]) { |
162 | cfs_array_free((void *)&arr->va_ptrs[0]); | 161 | cfs_array_free((void *)&arr->va_ptrs[0]); |
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c index b8d1ce831ff1..442889a3d729 100644 --- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c +++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c | |||
@@ -437,7 +437,7 @@ cfs_expr_list_values(struct cfs_expr_list *expr_list, int max, u32 **valpp) | |||
437 | return -EINVAL; | 437 | return -EINVAL; |
438 | } | 438 | } |
439 | 439 | ||
440 | LIBCFS_ALLOC(val, sizeof(val[0]) * count); | 440 | val = kvmalloc_array(count, sizeof(val[0]), GFP_KERNEL | __GFP_ZERO); |
441 | if (!val) | 441 | if (!val) |
442 | return -ENOMEM; | 442 | return -ENOMEM; |
443 | 443 | ||
diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c index a1a3c35ea4dc..4b24842e9b16 100644 --- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c | |||
@@ -169,7 +169,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist) | |||
169 | 169 | ||
170 | LASSERT(rc <= LNET_CPT_NUMBER); | 170 | LASSERT(rc <= LNET_CPT_NUMBER); |
171 | if (rc == LNET_CPT_NUMBER) { | 171 | if (rc == LNET_CPT_NUMBER) { |
172 | LIBCFS_FREE(ni->ni_cpts, rc * sizeof(ni->ni_cpts[0])); | 172 | cfs_expr_list_values_free(ni->ni_cpts, LNET_CPT_NUMBER); |
173 | ni->ni_cpts = NULL; | 173 | ni->ni_cpts = NULL; |
174 | } | 174 | } |
175 | 175 | ||