History

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.

Pengfei Li committed 7 years ago

Commit 688fcbf1 parent dd3b8352 files · +23 −21Browse files

Unified · Split

2 files
  1. include/linux/vmalloc.h +13 −7
  2. mm/vmalloc.c +10 −14
include/linux/vmalloc.h+13−7
@@ -53,15 +53,21 @@ struct vmap_area { · 52 unmodified lines
5353 unsigned long va_start;
5454 unsigned long va_end;
5555
56− /*
57− * Largest available free size in subtree.
58− */
59− unsigned long subtree_max_size;
60− unsigned long flags;
6156 struct rb_node rb_node; /* address sorted rbtree */
6257 struct list_head list; /* address sorted list */
63− struct llist_node purge_list; /* "lazy purge" list */
64− struct vm_struct *vm;
58+
59+ /*
60+ * The following three variables can be packed, because
61+ * a vmap_area object is always one of the three states:
62+ * 1) in "free" tree (root is vmap_area_root)
63+ * 2) in "busy" tree (root is free_vmap_area_root)
64+ * 3) in purge list (head is vmap_purge_list)
65+ */
66+ union {
67+ unsigned long subtree_max_size; /* in "free" tree */
68+ struct vm_struct *vm; /* in "busy" tree */
69+ struct llist_node purge_list; /* in purge list */
70+ };
6571 };
6672
6773 /*
mm/vmalloc.c+10−14
@@ -329,7 +329,6 @@ EXPORT_SYMBOL(vmalloc_to_pfn); · 328 unmodified lines
329329 #define DEBUG_AUGMENT_PROPAGATE_CHECK 0
330330 #define DEBUG_AUGMENT_LOWEST_MATCH_CHECK 0
331331
332−#define VM_VM_AREA 0x04
333332
334333 static DEFINE_SPINLOCK(vmap_area_lock);
335334 /* Export for kexec only */
@@ -1115,7 +1114,7 @@ retry: · 779 unmodified lines
11151114
11161115 va->va_start = addr;
11171116 va->va_end = addr + size;
1118− va->flags = 0;
1117+ va->vm = NULL;
11191118 insert_vmap_area(va, &vmap_area_root, &vmap_area_list);
11201119
11211120 spin_unlock(&vmap_area_lock);
@@ -1928,7 +1927,6 @@ void __init vmalloc_init(void) · 806 unmodified lines
19281927 if (WARN_ON_ONCE(!va))
19291928 continue;
19301929
1931− va->flags = VM_VM_AREA;
19321930 va->va_start = (unsigned long)tmp->addr;
19331931 va->va_end = va->va_start + tmp->size;
19341932 va->vm = tmp;
@@ -2026,7 +2024,6 @@ static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va, · 91 unmodified lines
20262024 vm->size = va->va_end - va->va_start;
20272025 vm->caller = caller;
20282026 va->vm = vm;
2029− va->flags |= VM_VM_AREA;
20302027 spin_unlock(&vmap_area_lock);
20312028 }
20322029
@@ -2131,10 +2128,10 @@ struct vm_struct *find_vm_area(const void *addr) · 98 unmodified lines
21312128 struct vmap_area *va;
21322129
21332130 va = find_vmap_area((unsigned long)addr);
2134− if (va && va->flags & VM_VM_AREA)
2135− return va->vm;
2131+ if (!va)
2132+ return NULL;
21362133
2137− return NULL;
2134+ return va->vm;
21382135 }
21392136
21402137 /**
@@ -2155,11 +2152,10 @@ struct vm_struct *remove_vm_area(const void *addr) · 14 unmodified lines
21552152
21562153 spin_lock(&vmap_area_lock);
21572154 va = __find_vmap_area((unsigned long)addr);
2158− if (va && va->flags & VM_VM_AREA) {
2155+ if (va && va->vm) {
21592156 struct vm_struct *vm = va->vm;
21602157
21612158 va->vm = NULL;
2162− va->flags &= ~VM_VM_AREA;
21632159 spin_unlock(&vmap_area_lock);
21642160
21652161 kasan_free_shadow(vm);
@@ -2862,7 +2858,7 @@ long vread(char *buf, char *addr, unsigned long count) · 696 unmodified lines
28622858 if (!count)
28632859 break;
28642860
2865− if (!(va->flags & VM_VM_AREA))
2861+ if (!va->vm)
28662862 continue;
28672863
28682864 vm = va->vm;
@@ -2942,7 +2938,7 @@ long vwrite(char *buf, char *addr, unsigned long count) · 73 unmodified lines
29422938 if (!count)
29432939 break;
29442940
2945− if (!(va->flags & VM_VM_AREA))
2941+ if (!va->vm)
29462942 continue;
29472943
29482944 vm = va->vm;
@@ -3485,10 +3481,10 @@ static int s_show(struct seq_file *m, void *p) · 536 unmodified lines
34853481 va = list_entry(p, struct vmap_area, list);
34863482
34873483 /*
3488− * s_show can encounter race with remove_vm_area, !VM_VM_AREA on
3489− * behalf of vmap area is being tear down or vm_map_ram allocation.
3484+ * s_show can encounter race with remove_vm_area, !vm on behalf
3485+ * of vmap area is being tear down or vm_map_ram allocation.
34903486 */
3491− if (!(va->flags & VM_VM_AREA)) {
3487+ if (!va->vm) {
34923488 seq_printf(m, "0x%pK-0x%pK %7ld vm_map_ram\n",
34933489 (void *)va->va_start, (void *)va->va_end,
34943490 va->va_end - va->va_start);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t