@@ -97,10 +97,9 @@ impl Vmalloc {
97
97
this
98
98
}
99
99
100
- pub ( super ) fn alloc ( & mut self , mut npages : usize ) -> Option < VirtAddr > {
101
- npages += 1 ; // allocate a guard page
102
-
103
- let size_bytes = npages * Size4KiB :: SIZE as usize ;
100
+ pub ( super ) fn alloc ( & mut self , npages : usize ) -> Option < VirtAddr > {
101
+ // +1: area for the guard page.
102
+ let size_bytes = ( npages + 1 ) * Size4KiB :: SIZE as usize ;
104
103
105
104
let area = self
106
105
. free_list
@@ -125,6 +124,10 @@ impl Vmalloc {
125
124
area_cursor. remove ( ) ;
126
125
}
127
126
127
+ // subtract the size of the guard page since we are not required to allocate
128
+ // a frame for that area.
129
+ let size_bytes = size_bytes - Size4KiB :: SIZE as usize ;
130
+
128
131
let mut address_space = AddressSpace :: this ( ) ;
129
132
let mut offset_table = address_space. offset_page_table ( ) ;
130
133
@@ -155,10 +158,9 @@ impl Vmalloc {
155
158
Some ( address)
156
159
}
157
160
158
- pub ( super ) fn dealloc ( & mut self , addr : VirtAddr , mut npages : usize ) {
159
- npages += 1 ; // deallocate the vmalloc guard page
160
-
161
- let size = npages * Size4KiB :: SIZE as usize ;
161
+ pub ( super ) fn dealloc ( & mut self , addr : VirtAddr , npages : usize ) {
162
+ // +1: area for the guard page.
163
+ let size = ( npages + 1 ) * Size4KiB :: SIZE as usize ;
162
164
163
165
// check if this block can be merged into another block.
164
166
let merge = self
@@ -176,6 +178,9 @@ impl Vmalloc {
176
178
self . free_list . insert ( box VmallocArea :: new ( addr, size) ) ;
177
179
}
178
180
181
+ // subtract the size of the guard page since its not mapped.
182
+ let size = size - Size4KiB :: SIZE as usize ;
183
+
179
184
let mut address_space = AddressSpace :: this ( ) ;
180
185
let mut offset_table = address_space. offset_page_table ( ) ;
181
186
0 commit comments