Commit a647e4bc authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] md/bitmap: remove unnecessary page reference manipulations from md/bitmap code

md/bitmap gets a collection of pages representing the bitmap when it
initialises the bitmap, and puts all the references when discarding the
bitmap.

It also occasionally takes extra references without any good reason, and
sometimes drops them ...  though it doesn't always drop them, which can result
in a memory leak.

This patch removes the unnecessary 'get_page' calls, and the corresponding
'put_page' calls.
Signed-off-by: default avatarNeil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e16b68b6
...@@ -332,7 +332,6 @@ static int write_page(struct bitmap *bitmap, struct page *page, int wait) ...@@ -332,7 +332,6 @@ static int write_page(struct bitmap *bitmap, struct page *page, int wait)
/* add to list to be waited for */ /* add to list to be waited for */
struct page_list *item = mempool_alloc(bitmap->write_pool, GFP_NOIO); struct page_list *item = mempool_alloc(bitmap->write_pool, GFP_NOIO);
item->page = page; item->page = page;
get_page(page);
spin_lock(&bitmap->write_lock); spin_lock(&bitmap->write_lock);
list_add(&item->list, &bitmap->complete_pages); list_add(&item->list, &bitmap->complete_pages);
spin_unlock(&bitmap->write_lock); spin_unlock(&bitmap->write_lock);
...@@ -548,7 +547,6 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, ...@@ -548,7 +547,6 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
return; return;
} }
get_page(bitmap->sb_page);
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0); sb = (bitmap_super_t *)kmap_atomic(bitmap->sb_page, KM_USER0);
switch (op) { switch (op) {
...@@ -559,7 +557,6 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits, ...@@ -559,7 +557,6 @@ static void bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
default: BUG(); default: BUG();
} }
kunmap_atomic(sb, KM_USER0); kunmap_atomic(sb, KM_USER0);
put_page(bitmap->sb_page);
} }
/* /*
...@@ -641,7 +638,6 @@ static void drain_write_queues(struct bitmap *bitmap) ...@@ -641,7 +638,6 @@ static void drain_write_queues(struct bitmap *bitmap)
while ((item = dequeue_page(bitmap))) { while ((item = dequeue_page(bitmap))) {
/* don't bother to wait */ /* don't bother to wait */
put_page(item->page);
mempool_free(item, bitmap->write_pool); mempool_free(item, bitmap->write_pool);
} }
} }
...@@ -744,11 +740,6 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) ...@@ -744,11 +740,6 @@ static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
page = filemap_get_page(bitmap, chunk); page = filemap_get_page(bitmap, chunk);
bit = file_page_offset(chunk); bit = file_page_offset(chunk);
/* make sure the page stays cached until it gets written out */
if (! test_page_attr(bitmap, page, BITMAP_PAGE_DIRTY))
get_page(page);
/* set the bit */ /* set the bit */
kaddr = kmap_atomic(page, KM_USER0); kaddr = kmap_atomic(page, KM_USER0);
if (bitmap->flags & BITMAP_HOSTENDIAN) if (bitmap->flags & BITMAP_HOSTENDIAN)
...@@ -1028,10 +1019,9 @@ int bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1028,10 +1019,9 @@ int bitmap_daemon_work(struct bitmap *bitmap)
if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) { if (!test_page_attr(bitmap, page, BITMAP_PAGE_CLEAN)) {
int need_write = test_page_attr(bitmap, page, int need_write = test_page_attr(bitmap, page,
BITMAP_PAGE_NEEDWRITE); BITMAP_PAGE_NEEDWRITE);
if (need_write) { if (need_write)
get_page(page);
clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE); clear_page_attr(bitmap, page, BITMAP_PAGE_NEEDWRITE);
}
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
if (need_write) { if (need_write) {
switch (write_page(bitmap, page, 0)) { switch (write_page(bitmap, page, 0)) {
...@@ -1043,13 +1033,11 @@ int bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1043,13 +1033,11 @@ int bitmap_daemon_work(struct bitmap *bitmap)
default: default:
bitmap_file_kick(bitmap); bitmap_file_kick(bitmap);
} }
put_page(page);
} }
continue; continue;
} }
/* grab the new page, sync and release the old */ /* grab the new page, sync and release the old */
get_page(page);
if (lastpage != NULL) { if (lastpage != NULL) {
if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
...@@ -1063,7 +1051,6 @@ int bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1063,7 +1051,6 @@ int bitmap_daemon_work(struct bitmap *bitmap)
set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
} }
put_page(lastpage);
if (err) if (err)
bitmap_file_kick(bitmap); bitmap_file_kick(bitmap);
} else } else
...@@ -1117,8 +1104,6 @@ int bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1117,8 +1104,6 @@ int bitmap_daemon_work(struct bitmap *bitmap)
set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
} }
put_page(lastpage);
} }
return err; return err;
...@@ -1140,7 +1125,6 @@ static void bitmap_writeback(struct bitmap *bitmap) ...@@ -1140,7 +1125,6 @@ static void bitmap_writeback(struct bitmap *bitmap)
PRINTK("finished page writeback: %p\n", page); PRINTK("finished page writeback: %p\n", page);
err = PageError(page); err = PageError(page);
put_page(page);
if (err) { if (err) {
printk(KERN_WARNING "%s: bitmap file writeback " printk(KERN_WARNING "%s: bitmap file writeback "
"failed (page %lu): %d\n", "failed (page %lu): %d\n",
......
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