Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 752ade68 authored by Michal Hocko's avatar Michal Hocko Committed by Linus Torvalds
Browse files

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: default avatarMichal Hocko <mhocko@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> # Xen bits
Acked-by: default avatarKees Cook <keescook@chromium.org>
Acked-by: default avatarVlastimil 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 81be3dee
Loading
Loading
Loading
Loading
+2 −8
Original line number Original line Diff line number Diff line
@@ -1166,10 +1166,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
		return -EINVAL;
		return -EINVAL;


	keys = kmalloc_array(args->count, sizeof(uint8_t),
	keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL);
			     GFP_KERNEL | __GFP_NOWARN);
	if (!keys)
		keys = vmalloc(sizeof(uint8_t) * args->count);
	if (!keys)
	if (!keys)
		return -ENOMEM;
		return -ENOMEM;


@@ -1211,10 +1208,7 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
	if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
		return -EINVAL;
		return -EINVAL;


	keys = kmalloc_array(args->count, sizeof(uint8_t),
	keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL);
			     GFP_KERNEL | __GFP_NOWARN);
	if (!keys)
		keys = vmalloc(sizeof(uint8_t) * args->count);
	if (!keys)
	if (!keys)
		return -ENOMEM;
		return -ENOMEM;


+1 −3
Original line number Original line Diff line number Diff line
@@ -32,9 +32,7 @@ static void *lzo_alloc_ctx(struct crypto_scomp *tfm)
{
{
	void *ctx;
	void *ctx;


	ctx = kmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL | __GFP_NOWARN);
	ctx = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
	if (!ctx)
		ctx = vmalloc(LZO1X_MEM_COMPRESS);
	if (!ctx)
	if (!ctx)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


+2 −6
Original line number Original line Diff line number Diff line
@@ -513,7 +513,7 @@ static int __erst_record_id_cache_add_one(void)
	if (i < erst_record_id_cache.len)
	if (i < erst_record_id_cache.len)
		goto retry;
		goto retry;
	if (erst_record_id_cache.len >= erst_record_id_cache.size) {
	if (erst_record_id_cache.len >= erst_record_id_cache.size) {
		int new_size, alloc_size;
		int new_size;
		u64 *new_entries;
		u64 *new_entries;


		new_size = erst_record_id_cache.size * 2;
		new_size = erst_record_id_cache.size * 2;
@@ -524,11 +524,7 @@ static int __erst_record_id_cache_add_one(void)
				pr_warn(FW_WARN "too many record IDs!\n");
				pr_warn(FW_WARN "too many record IDs!\n");
			return 0;
			return 0;
		}
		}
		alloc_size = new_size * sizeof(entries[0]);
		new_entries = kvmalloc(new_size * sizeof(entries[0]), GFP_KERNEL);
		if (alloc_size < PAGE_SIZE)
			new_entries = kmalloc(alloc_size, GFP_KERNEL);
		else
			new_entries = vmalloc(alloc_size);
		if (!new_entries)
		if (!new_entries)
			return -ENOMEM;
			return -ENOMEM;
		memcpy(new_entries, entries,
		memcpy(new_entries, entries,
+1 −7
Original line number Original line Diff line number Diff line
@@ -88,13 +88,7 @@ static int agp_get_key(void)


void agp_alloc_page_array(size_t size, struct agp_memory *mem)
void agp_alloc_page_array(size_t size, struct agp_memory *mem)
{
{
	mem->pages = NULL;
	mem->pages = kvmalloc(size, GFP_KERNEL);

	if (size <= 2*PAGE_SIZE)
		mem->pages = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
	if (mem->pages == NULL) {
		mem->pages = vmalloc(size);
	}
}
}
EXPORT_SYMBOL(agp_alloc_page_array);
EXPORT_SYMBOL(agp_alloc_page_array);


+1 −3
Original line number Original line Diff line number Diff line
@@ -568,9 +568,7 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size)


	size *= nmemb;
	size *= nmemb;


	mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
	mem = kvmalloc(size, GFP_KERNEL);
	if (!mem)
		mem = vmalloc(size);
	if (!mem)
	if (!mem)
		return ERR_PTR(-ENOMEM);
		return ERR_PTR(-ENOMEM);


Loading