treewide: use kv[mz]alloc* rather than opencoded variants
There are many code paths opencoding kvmalloc. Let's use the helper instead. The main difference to kvmalloc is that those users are usually not considering all the aspects of the memory allocator. E.g. allocation requests <= 32kB (with 4kB pages) are basically never failing and invoke OOM killer to satisfy the allocation. This sounds too disruptive for something that has a reasonable fallback - the vmalloc. On the other hand those requests might fallback to vmalloc even when the memory allocator would succeed after several more reclaim/compaction attempts previously. There is no guarantee something like that happens though. This patch converts many of those places to kv[mz]alloc* helpers because they are more conservative. Link: http://lkml.kernel.org/r/20170306103327.2766-2-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> # Xen bits Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Andreas Dilger <andreas.dilger@intel.com> # Lustre Acked-by: Christian Borntraeger <borntraeger@de.ibm.com> # KVM/s390 Acked-by: Dan Williams <dan.j.williams@intel.com> # nvdim Acked-by: David Sterba <dsterba@suse.com> # btrfs Acked-by: Ilya Dryomov <idryomov@gmail.com> # Ceph Acked-by: Tariq Toukan <tariqt@mellanox.com> # mlx4 Acked-by: Leon Romanovsky <leonro@mellanox.com> # mlx5 Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Anton Vorontsov <anton@enomsg.org> Cc: Colin Cross <ccross@android.com> Cc: Tony Luck <tony.luck@intel.com> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: Ben Skeggs <bskeggs@redhat.com> Cc: Kent Overstreet <kent.overstreet@gmail.com> Cc: Santosh Raspatur <santosh@chelsio.com> Cc: Hariprasad S <hariprasad@chelsio.com> Cc: Yishai Hadas <yishaih@mellanox.com> Cc: Oleg Drokin <oleg.drokin@intel.com> Cc: "Yan, Zheng" <zyan@redhat.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Eric Dumazet <eric.dumazet@gmail.com> Cc: David Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
81be3dee96
commit
752ade68cb
@@ -41,9 +41,6 @@
|
||||
|
||||
#define VALIDATE_TID 1
|
||||
|
||||
void *cxgb_alloc_mem(unsigned long size);
|
||||
void cxgb_free_mem(void *addr);
|
||||
|
||||
/*
|
||||
* Map an ATID or STID to their entries in the corresponding TID tables.
|
||||
*/
|
||||
|
@@ -1151,27 +1151,6 @@ static void cxgb_redirect(struct dst_entry *old, struct dst_entry *new,
|
||||
l2t_release(tdev, e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
|
||||
* The allocated memory is cleared.
|
||||
*/
|
||||
void *cxgb_alloc_mem(unsigned long size)
|
||||
{
|
||||
void *p = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
|
||||
|
||||
if (!p)
|
||||
p = vzalloc(size);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free memory allocated through t3_alloc_mem().
|
||||
*/
|
||||
void cxgb_free_mem(void *addr)
|
||||
{
|
||||
kvfree(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate and initialize the TID tables. Returns 0 on success.
|
||||
*/
|
||||
@@ -1182,7 +1161,7 @@ static int init_tid_tabs(struct tid_info *t, unsigned int ntids,
|
||||
unsigned long size = ntids * sizeof(*t->tid_tab) +
|
||||
natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab);
|
||||
|
||||
t->tid_tab = cxgb_alloc_mem(size);
|
||||
t->tid_tab = kvzalloc(size, GFP_KERNEL);
|
||||
if (!t->tid_tab)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1218,7 +1197,7 @@ static int init_tid_tabs(struct tid_info *t, unsigned int ntids,
|
||||
|
||||
static void free_tid_maps(struct tid_info *t)
|
||||
{
|
||||
cxgb_free_mem(t->tid_tab);
|
||||
kvfree(t->tid_tab);
|
||||
}
|
||||
|
||||
static inline void add_adapter(struct adapter *adap)
|
||||
@@ -1293,7 +1272,7 @@ int cxgb3_offload_activate(struct adapter *adapter)
|
||||
return 0;
|
||||
|
||||
out_free_l2t:
|
||||
t3_free_l2t(l2td);
|
||||
kvfree(l2td);
|
||||
out_free:
|
||||
kfree(t);
|
||||
return err;
|
||||
@@ -1302,7 +1281,7 @@ out_free:
|
||||
static void clean_l2_data(struct rcu_head *head)
|
||||
{
|
||||
struct l2t_data *d = container_of(head, struct l2t_data, rcu_head);
|
||||
t3_free_l2t(d);
|
||||
kvfree(d);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -444,7 +444,7 @@ struct l2t_data *t3_init_l2t(unsigned int l2t_capacity)
|
||||
struct l2t_data *d;
|
||||
int i, size = sizeof(*d) + l2t_capacity * sizeof(struct l2t_entry);
|
||||
|
||||
d = cxgb_alloc_mem(size);
|
||||
d = kvzalloc(size, GFP_KERNEL);
|
||||
if (!d)
|
||||
return NULL;
|
||||
|
||||
@@ -462,9 +462,3 @@ struct l2t_data *t3_init_l2t(unsigned int l2t_capacity)
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
void t3_free_l2t(struct l2t_data *d)
|
||||
{
|
||||
cxgb_free_mem(d);
|
||||
}
|
||||
|
||||
|
@@ -115,7 +115,6 @@ int t3_l2t_send_slow(struct t3cdev *dev, struct sk_buff *skb,
|
||||
struct l2t_entry *e);
|
||||
void t3_l2t_send_event(struct t3cdev *dev, struct l2t_entry *e);
|
||||
struct l2t_data *t3_init_l2t(unsigned int l2t_capacity);
|
||||
void t3_free_l2t(struct l2t_data *d);
|
||||
|
||||
int cxgb3_ofld_send(struct t3cdev *dev, struct sk_buff *skb);
|
||||
|
||||
|
Reference in New Issue
Block a user