diff mbox series

[v3,1/4] kernfs: kvmalloc xattr value instead of kmalloc

Message ID 20200312200317.31736-2-dxu@dxuuu.xyz (mailing list archive)
State New, archived
Headers show
Series Support user xattrs in cgroupfs | expand

Commit Message

Daniel Xu March 12, 2020, 8:03 p.m. UTC
xattr values have a 64k maximum size. This can result in an order 4
kmalloc request which can be difficult to fulfill. Since xattrs do not
need physically contiguous memory, we can switch to kvmalloc and not
have to worry about higher order allocations failing.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 fs/xattr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Shakeel Butt March 12, 2020, 9:03 p.m. UTC | #1
On Thu, Mar 12, 2020 at 1:03 PM Daniel Xu <dxu@dxuuu.xyz> wrote:
>
> xattr values have a 64k maximum size. This can result in an order 4
> kmalloc request which can be difficult to fulfill. Since xattrs do not
> need physically contiguous memory, we can switch to kvmalloc and not
> have to worry about higher order allocations failing.
>
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>

Reviewed-by: Shakeel Butt <shakeelb@google.com>
Andreas Dilger March 12, 2020, 9:09 p.m. UTC | #2
On Mar 12, 2020, at 2:03 PM, Daniel Xu <dxu@dxuuu.xyz> wrote:
> 
> xattr values have a 64k maximum size. This can result in an order 4
> kmalloc request which can be difficult to fulfill. Since xattrs do not
> need physically contiguous memory, we can switch to kvmalloc and not
> have to worry about higher order allocations failing.
> 
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> fs/xattr.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/xattr.c b/fs/xattr.c
> index 90dd78f0eb27..0d3c9b4d1914 100644
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -817,7 +817,7 @@ struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
> 	if (len < sizeof(*new_xattr))
> 		return NULL;
> 
> -	new_xattr = kmalloc(len, GFP_KERNEL);
> +	new_xattr = kvmalloc(len, GFP_KERNEL);
> 	if (!new_xattr)
> 		return NULL;
> 
> @@ -882,7 +882,7 @@ int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
> 
> 		new_xattr->name = kstrdup(name, GFP_KERNEL);
> 		if (!new_xattr->name) {
> -			kfree(new_xattr);
> +			kvfree(new_xattr);
> 			return -ENOMEM;
> 		}
> 	}
> @@ -912,7 +912,7 @@ int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
> 	spin_unlock(&xattrs->lock);
> 	if (xattr) {
> 		kfree(xattr->name);
> -		kfree(xattr);
> +		kvfree(xattr);
> 	}
> 	return err;
> 
> --
> 2.21.1
> 


Cheers, Andreas
diff mbox series

Patch

diff --git a/fs/xattr.c b/fs/xattr.c
index 90dd78f0eb27..0d3c9b4d1914 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -817,7 +817,7 @@  struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
 	if (len < sizeof(*new_xattr))
 		return NULL;
 
-	new_xattr = kmalloc(len, GFP_KERNEL);
+	new_xattr = kvmalloc(len, GFP_KERNEL);
 	if (!new_xattr)
 		return NULL;
 
@@ -882,7 +882,7 @@  int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
 
 		new_xattr->name = kstrdup(name, GFP_KERNEL);
 		if (!new_xattr->name) {
-			kfree(new_xattr);
+			kvfree(new_xattr);
 			return -ENOMEM;
 		}
 	}
@@ -912,7 +912,7 @@  int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
 	spin_unlock(&xattrs->lock);
 	if (xattr) {
 		kfree(xattr->name);
-		kfree(xattr);
+		kvfree(xattr);
 	}
 	return err;