mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
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/[email protected] Signed-off-by: Michal Hocko <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> # Xen bits Acked-by: Kees Cook <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Andreas Dilger <[email protected]> # Lustre Acked-by: Christian Borntraeger <[email protected]> # KVM/s390 Acked-by: Dan Williams <[email protected]> # nvdim Acked-by: David Sterba <[email protected]> # btrfs Acked-by: Ilya Dryomov <[email protected]> # Ceph Acked-by: Tariq Toukan <[email protected]> # mlx4 Acked-by: Leon Romanovsky <[email protected]> # mlx5 Cc: Martin Schwidefsky <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Anton Vorontsov <[email protected]> Cc: Colin Cross <[email protected]> Cc: Tony Luck <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Ben Skeggs <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Santosh Raspatur <[email protected]> Cc: Hariprasad S <[email protected]> Cc: Yishai Hadas <[email protected]> Cc: Oleg Drokin <[email protected]> Cc: "Yan, Zheng" <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: David Miller <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
81be3dee96
commit
752ade68cb
44 changed files with 128 additions and 350 deletions
|
|
@ -376,10 +376,7 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
|
|||
if (mask != q->tab_mask) {
|
||||
struct sk_buff **ntab;
|
||||
|
||||
ntab = kcalloc(mask + 1, sizeof(struct sk_buff *),
|
||||
GFP_KERNEL | __GFP_NOWARN);
|
||||
if (!ntab)
|
||||
ntab = vzalloc((mask + 1) * sizeof(struct sk_buff *));
|
||||
ntab = kvmalloc_array((mask + 1), sizeof(struct sk_buff *), GFP_KERNEL | __GFP_ZERO);
|
||||
if (!ntab)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
|||
|
|
@ -446,27 +446,13 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void *fq_codel_zalloc(size_t sz)
|
||||
{
|
||||
void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
|
||||
|
||||
if (!ptr)
|
||||
ptr = vzalloc(sz);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void fq_codel_free(void *addr)
|
||||
{
|
||||
kvfree(addr);
|
||||
}
|
||||
|
||||
static void fq_codel_destroy(struct Qdisc *sch)
|
||||
{
|
||||
struct fq_codel_sched_data *q = qdisc_priv(sch);
|
||||
|
||||
tcf_destroy_chain(&q->filter_list);
|
||||
fq_codel_free(q->backlogs);
|
||||
fq_codel_free(q->flows);
|
||||
kvfree(q->backlogs);
|
||||
kvfree(q->flows);
|
||||
}
|
||||
|
||||
static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
|
||||
|
|
@ -493,13 +479,13 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
|
|||
}
|
||||
|
||||
if (!q->flows) {
|
||||
q->flows = fq_codel_zalloc(q->flows_cnt *
|
||||
sizeof(struct fq_codel_flow));
|
||||
q->flows = kvzalloc(q->flows_cnt *
|
||||
sizeof(struct fq_codel_flow), GFP_KERNEL);
|
||||
if (!q->flows)
|
||||
return -ENOMEM;
|
||||
q->backlogs = fq_codel_zalloc(q->flows_cnt * sizeof(u32));
|
||||
q->backlogs = kvzalloc(q->flows_cnt * sizeof(u32), GFP_KERNEL);
|
||||
if (!q->backlogs) {
|
||||
fq_codel_free(q->flows);
|
||||
kvfree(q->flows);
|
||||
return -ENOMEM;
|
||||
}
|
||||
for (i = 0; i < q->flows_cnt; i++) {
|
||||
|
|
|
|||
|
|
@ -467,29 +467,14 @@ static void hhf_reset(struct Qdisc *sch)
|
|||
rtnl_kfree_skbs(skb, skb);
|
||||
}
|
||||
|
||||
static void *hhf_zalloc(size_t sz)
|
||||
{
|
||||
void *ptr = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
|
||||
|
||||
if (!ptr)
|
||||
ptr = vzalloc(sz);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void hhf_free(void *addr)
|
||||
{
|
||||
kvfree(addr);
|
||||
}
|
||||
|
||||
static void hhf_destroy(struct Qdisc *sch)
|
||||
{
|
||||
int i;
|
||||
struct hhf_sched_data *q = qdisc_priv(sch);
|
||||
|
||||
for (i = 0; i < HHF_ARRAYS_CNT; i++) {
|
||||
hhf_free(q->hhf_arrays[i]);
|
||||
hhf_free(q->hhf_valid_bits[i]);
|
||||
kvfree(q->hhf_arrays[i]);
|
||||
kvfree(q->hhf_valid_bits[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < HH_FLOWS_CNT; i++) {
|
||||
|
|
@ -503,7 +488,7 @@ static void hhf_destroy(struct Qdisc *sch)
|
|||
kfree(flow);
|
||||
}
|
||||
}
|
||||
hhf_free(q->hh_flows);
|
||||
kvfree(q->hh_flows);
|
||||
}
|
||||
|
||||
static const struct nla_policy hhf_policy[TCA_HHF_MAX + 1] = {
|
||||
|
|
@ -609,8 +594,8 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt)
|
|||
|
||||
if (!q->hh_flows) {
|
||||
/* Initialize heavy-hitter flow table. */
|
||||
q->hh_flows = hhf_zalloc(HH_FLOWS_CNT *
|
||||
sizeof(struct list_head));
|
||||
q->hh_flows = kvzalloc(HH_FLOWS_CNT *
|
||||
sizeof(struct list_head), GFP_KERNEL);
|
||||
if (!q->hh_flows)
|
||||
return -ENOMEM;
|
||||
for (i = 0; i < HH_FLOWS_CNT; i++)
|
||||
|
|
@ -624,8 +609,8 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt)
|
|||
|
||||
/* Initialize heavy-hitter filter arrays. */
|
||||
for (i = 0; i < HHF_ARRAYS_CNT; i++) {
|
||||
q->hhf_arrays[i] = hhf_zalloc(HHF_ARRAYS_LEN *
|
||||
sizeof(u32));
|
||||
q->hhf_arrays[i] = kvzalloc(HHF_ARRAYS_LEN *
|
||||
sizeof(u32), GFP_KERNEL);
|
||||
if (!q->hhf_arrays[i]) {
|
||||
/* Note: hhf_destroy() will be called
|
||||
* by our caller.
|
||||
|
|
@ -637,8 +622,8 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt)
|
|||
|
||||
/* Initialize valid bits of heavy-hitter filter arrays. */
|
||||
for (i = 0; i < HHF_ARRAYS_CNT; i++) {
|
||||
q->hhf_valid_bits[i] = hhf_zalloc(HHF_ARRAYS_LEN /
|
||||
BITS_PER_BYTE);
|
||||
q->hhf_valid_bits[i] = kvzalloc(HHF_ARRAYS_LEN /
|
||||
BITS_PER_BYTE, GFP_KERNEL);
|
||||
if (!q->hhf_valid_bits[i]) {
|
||||
/* Note: hhf_destroy() will be called
|
||||
* by our caller.
|
||||
|
|
|
|||
|
|
@ -702,15 +702,11 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
|
|||
spinlock_t *root_lock;
|
||||
struct disttable *d;
|
||||
int i;
|
||||
size_t s;
|
||||
|
||||
if (n > NETEM_DIST_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
s = sizeof(struct disttable) + n * sizeof(s16);
|
||||
d = kmalloc(s, GFP_KERNEL | __GFP_NOWARN);
|
||||
if (!d)
|
||||
d = vmalloc(s);
|
||||
d = kvmalloc(sizeof(struct disttable) + n * sizeof(s16), GFP_KERNEL);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
|||
|
|
@ -685,11 +685,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
|
|||
|
||||
static void *sfq_alloc(size_t sz)
|
||||
{
|
||||
void *ptr = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN);
|
||||
|
||||
if (!ptr)
|
||||
ptr = vmalloc(sz);
|
||||
return ptr;
|
||||
return kvmalloc(sz, GFP_KERNEL);
|
||||
}
|
||||
|
||||
static void sfq_free(void *addr)
|
||||
|
|
|
|||
Loading…
Reference in a new issue