Skip to content

Commit 572a3d1

Browse files
Hugh Dickinsbrauner
authored andcommitted
tmpfs,xattr: GFP_KERNEL_ACCOUNT for simple xattrs
It is particularly important for the userns mount case (when a sensible nr_inodes maximum may not be enforced) that tmpfs user xattrs be subject to memory cgroup limiting. Leave temporary buffer allocations as is, but change the persistent simple xattr allocations from GFP_KERNEL to GFP_KERNEL_ACCOUNT. This limits kernfs's cgroupfs too, but that's good. (I had intended to send this change earlier, but had been confused by shmem_alloc_inode() using GFP_KERNEL, and thought a discussion would be needed to change that too: no, I was forgetting the SLAB_ACCOUNT on that kmem_cache, which implicitly adds __GFP_ACCOUNT to all its allocations.) Signed-off-by: Hugh Dickins <[email protected]> Reviewed-by: Jan Kara <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent aa5b917 commit 572a3d1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

fs/xattr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
10931093
if (len < sizeof(*new_xattr))
10941094
return NULL;
10951095

1096-
new_xattr = kvmalloc(len, GFP_KERNEL);
1096+
new_xattr = kvmalloc(len, GFP_KERNEL_ACCOUNT);
10971097
if (!new_xattr)
10981098
return NULL;
10991099

@@ -1217,7 +1217,7 @@ struct simple_xattr *simple_xattr_set(struct simple_xattrs *xattrs,
12171217
if (!new_xattr)
12181218
return ERR_PTR(-ENOMEM);
12191219

1220-
new_xattr->name = kstrdup(name, GFP_KERNEL);
1220+
new_xattr->name = kstrdup(name, GFP_KERNEL_ACCOUNT);
12211221
if (!new_xattr->name) {
12221222
simple_xattr_free(new_xattr);
12231223
return ERR_PTR(-ENOMEM);

mm/shmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3616,7 +3616,7 @@ static int shmem_initxattrs(struct inode *inode,
36163616

36173617
len = strlen(xattr->name) + 1;
36183618
new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + len,
3619-
GFP_KERNEL);
3619+
GFP_KERNEL_ACCOUNT);
36203620
if (!new_xattr->name) {
36213621
kvfree(new_xattr);
36223622
break;

0 commit comments

Comments
 (0)