Commit 688fcbfc authored by Pengfei Li's avatar Pengfei Li Committed by Linus Torvalds

mm/vmalloc: modify struct vmap_area to reduce its size

Objective
---------

The current implementation of struct vmap_area wasted space.

After applying this commit, sizeof(struct vmap_area) has been
reduced from 11 words to 8 words.

Description
-----------

1) Pack "subtree_max_size", "vm" and "purge_list".  This is no problem
   because

A) "subtree_max_size" is only used when vmap_area is in "free" tree

B) "vm" is only used when vmap_area is in "busy" tree

C) "purge_list" is only used when vmap_area is in vmap_purge_list

2) Eliminate "flags".

;Since only one flag VM_VM_AREA is being used, and the same thing can be
done by judging whether "vm" is NULL, then the "flags" can be eliminated.

Link: http://lkml.kernel.org/r/20190716152656.12255-3-lpf.vector@gmail.comSigned-off-by: default avatarPengfei Li <lpf.vector@gmail.com>
Suggested-by: default avatarUladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: default avatarUladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dd3b8353
...@@ -53,15 +53,21 @@ struct vmap_area { ...@@ -53,15 +53,21 @@ struct vmap_area {
unsigned long va_start; unsigned long va_start;
unsigned long va_end; unsigned long va_end;
/*
* Largest available free size in subtree.
*/
unsigned long subtree_max_size;
unsigned long flags;
struct rb_node rb_node; /* address sorted rbtree */ struct rb_node rb_node; /* address sorted rbtree */
struct list_head list; /* address sorted list */ struct list_head list; /* address sorted list */
struct llist_node purge_list; /* "lazy purge" list */
struct vm_struct *vm; /*
* The following three variables can be packed, because
* a vmap_area object is always one of the three states:
* 1) in "free" tree (root is vmap_area_root)
* 2) in "busy" tree (root is free_vmap_area_root)
* 3) in purge list (head is vmap_purge_list)
*/
union {
unsigned long subtree_max_size; /* in "free" tree */
struct vm_struct *vm; /* in "busy" tree */
struct llist_node purge_list; /* in purge list */
};
}; };
/* /*
......
...@@ -329,7 +329,6 @@ EXPORT_SYMBOL(vmalloc_to_pfn); ...@@ -329,7 +329,6 @@ EXPORT_SYMBOL(vmalloc_to_pfn);
#define DEBUG_AUGMENT_PROPAGATE_CHECK 0 #define DEBUG_AUGMENT_PROPAGATE_CHECK 0
#define DEBUG_AUGMENT_LOWEST_MATCH_CHECK 0 #define DEBUG_AUGMENT_LOWEST_MATCH_CHECK 0
#define VM_VM_AREA 0x04
static DEFINE_SPINLOCK(vmap_area_lock); static DEFINE_SPINLOCK(vmap_area_lock);
/* Export for kexec only */ /* Export for kexec only */
...@@ -1115,7 +1114,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, ...@@ -1115,7 +1114,7 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
va->va_start = addr; va->va_start = addr;
va->va_end = addr + size; va->va_end = addr + size;
va->flags = 0; va->vm = NULL;
insert_vmap_area(va, &vmap_area_root, &vmap_area_list); insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
spin_unlock(&vmap_area_lock); spin_unlock(&vmap_area_lock);
...@@ -1928,7 +1927,6 @@ void __init vmalloc_init(void) ...@@ -1928,7 +1927,6 @@ void __init vmalloc_init(void)
if (WARN_ON_ONCE(!va)) if (WARN_ON_ONCE(!va))
continue; continue;
va->flags = VM_VM_AREA;
va->va_start = (unsigned long)tmp->addr; va->va_start = (unsigned long)tmp->addr;
va->va_end = va->va_start + tmp->size; va->va_end = va->va_start + tmp->size;
va->vm = tmp; va->vm = tmp;
...@@ -2026,7 +2024,6 @@ static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va, ...@@ -2026,7 +2024,6 @@ static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
vm->size = va->va_end - va->va_start; vm->size = va->va_end - va->va_start;
vm->caller = caller; vm->caller = caller;
va->vm = vm; va->vm = vm;
va->flags |= VM_VM_AREA;
spin_unlock(&vmap_area_lock); spin_unlock(&vmap_area_lock);
} }
...@@ -2131,10 +2128,10 @@ struct vm_struct *find_vm_area(const void *addr) ...@@ -2131,10 +2128,10 @@ struct vm_struct *find_vm_area(const void *addr)
struct vmap_area *va; struct vmap_area *va;
va = find_vmap_area((unsigned long)addr); va = find_vmap_area((unsigned long)addr);
if (va && va->flags & VM_VM_AREA) if (!va)
return va->vm;
return NULL; return NULL;
return va->vm;
} }
/** /**
...@@ -2155,11 +2152,10 @@ struct vm_struct *remove_vm_area(const void *addr) ...@@ -2155,11 +2152,10 @@ struct vm_struct *remove_vm_area(const void *addr)
spin_lock(&vmap_area_lock); spin_lock(&vmap_area_lock);
va = __find_vmap_area((unsigned long)addr); va = __find_vmap_area((unsigned long)addr);
if (va && va->flags & VM_VM_AREA) { if (va && va->vm) {
struct vm_struct *vm = va->vm; struct vm_struct *vm = va->vm;
va->vm = NULL; va->vm = NULL;
va->flags &= ~VM_VM_AREA;
spin_unlock(&vmap_area_lock); spin_unlock(&vmap_area_lock);
kasan_free_shadow(vm); kasan_free_shadow(vm);
...@@ -2862,7 +2858,7 @@ long vread(char *buf, char *addr, unsigned long count) ...@@ -2862,7 +2858,7 @@ long vread(char *buf, char *addr, unsigned long count)
if (!count) if (!count)
break; break;
if (!(va->flags & VM_VM_AREA)) if (!va->vm)
continue; continue;
vm = va->vm; vm = va->vm;
...@@ -2942,7 +2938,7 @@ long vwrite(char *buf, char *addr, unsigned long count) ...@@ -2942,7 +2938,7 @@ long vwrite(char *buf, char *addr, unsigned long count)
if (!count) if (!count)
break; break;
if (!(va->flags & VM_VM_AREA)) if (!va->vm)
continue; continue;
vm = va->vm; vm = va->vm;
...@@ -3485,10 +3481,10 @@ static int s_show(struct seq_file *m, void *p) ...@@ -3485,10 +3481,10 @@ static int s_show(struct seq_file *m, void *p)
va = list_entry(p, struct vmap_area, list); va = list_entry(p, struct vmap_area, list);
/* /*
* s_show can encounter race with remove_vm_area, !VM_VM_AREA on * s_show can encounter race with remove_vm_area, !vm on behalf
* behalf of vmap area is being tear down or vm_map_ram allocation. * of vmap area is being tear down or vm_map_ram allocation.
*/ */
if (!(va->flags & VM_VM_AREA)) { if (!va->vm) {
seq_printf(m, "0x%pK-0x%pK %7ld vm_map_ram\n", seq_printf(m, "0x%pK-0x%pK %7ld vm_map_ram\n",
(void *)va->va_start, (void *)va->va_end, (void *)va->va_start, (void *)va->va_end,
va->va_end - va->va_start); va->va_end - va->va_start);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment