aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/swap.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2007-05-06 17:50:47 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-07 15:12:59 -0400
commitd1d241cc2c5feec057c370aa71637380b1b945d5 (patch)
tree69c07d4c7a8b52b9ee6efba1511f3b4f8f79e6bb /kernel/power/swap.c
parent726162b5dad154a90dad51c0185b891312de5757 (diff)
swsusp: use rbtree for tracking allocated swap
Make swsusp use extents instead of a bitmap to trace swap pages allocated for saving the image (the tracking is only needed in case there's an error, so that the allocated swap pages can be released). This should allow us to reduce the memory usage, practically always, and improve performance. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Cc: Nigel Cunningham <nigel@nigel.suspend2.net> Cc: Pavel Machek <pavel@ucw.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/power/swap.c')
-rw-r--r--kernel/power/swap.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index b18c155cbb60..e83ed9945a80 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -243,7 +243,6 @@ struct swap_map_page {
243struct swap_map_handle { 243struct swap_map_handle {
244 struct swap_map_page *cur; 244 struct swap_map_page *cur;
245 sector_t cur_swap; 245 sector_t cur_swap;
246 struct bitmap_page *bitmap;
247 unsigned int k; 246 unsigned int k;
248}; 247};
249 248
@@ -252,9 +251,6 @@ static void release_swap_writer(struct swap_map_handle *handle)
252 if (handle->cur) 251 if (handle->cur)
253 free_page((unsigned long)handle->cur); 252 free_page((unsigned long)handle->cur);
254 handle->cur = NULL; 253 handle->cur = NULL;
255 if (handle->bitmap)
256 free_bitmap(handle->bitmap);
257 handle->bitmap = NULL;
258} 254}
259 255
260static int get_swap_writer(struct swap_map_handle *handle) 256static int get_swap_writer(struct swap_map_handle *handle)
@@ -262,12 +258,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
262 handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL); 258 handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
263 if (!handle->cur) 259 if (!handle->cur)
264 return -ENOMEM; 260 return -ENOMEM;
265 handle->bitmap = alloc_bitmap(count_swap_pages(root_swap, 0)); 261 handle->cur_swap = alloc_swapdev_block(root_swap);
266 if (!handle->bitmap) {
267 release_swap_writer(handle);
268 return -ENOMEM;
269 }
270 handle->cur_swap = alloc_swapdev_block(root_swap, handle->bitmap);
271 if (!handle->cur_swap) { 262 if (!handle->cur_swap) {
272 release_swap_writer(handle); 263 release_swap_writer(handle);
273 return -ENOSPC; 264 return -ENOSPC;
@@ -284,7 +275,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
284 275
285 if (!handle->cur) 276 if (!handle->cur)
286 return -EINVAL; 277 return -EINVAL;
287 offset = alloc_swapdev_block(root_swap, handle->bitmap); 278 offset = alloc_swapdev_block(root_swap);
288 error = write_page(buf, offset, bio_chain); 279 error = write_page(buf, offset, bio_chain);
289 if (error) 280 if (error)
290 return error; 281 return error;
@@ -293,7 +284,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
293 error = wait_on_bio_chain(bio_chain); 284 error = wait_on_bio_chain(bio_chain);
294 if (error) 285 if (error)
295 goto out; 286 goto out;
296 offset = alloc_swapdev_block(root_swap, handle->bitmap); 287 offset = alloc_swapdev_block(root_swap);
297 if (!offset) 288 if (!offset)
298 return -ENOSPC; 289 return -ENOSPC;
299 handle->cur->next_swap = offset; 290 handle->cur->next_swap = offset;
@@ -430,7 +421,8 @@ int swsusp_write(void)
430 } 421 }
431 } 422 }
432 if (error) 423 if (error)
433 free_all_swap_pages(root_swap, handle.bitmap); 424 free_all_swap_pages(root_swap);
425
434 release_swap_writer(&handle); 426 release_swap_writer(&handle);
435 out: 427 out:
436 swsusp_close(); 428 swsusp_close();