提交 8311c29d 编写于 作者: N NeilBrown 提交者: Linus Torvalds

md: reduce CPU wastage on idle md array with a write-intent bitmap

On an md array with a write-intent bitmap, a thread wakes up every few seconds
and scans the bitmap looking for work to do.  If the array is idle, there will
be no work to do, but a lot of scanning is done to discover this.

So cache the fact that the bitmap is completely clean, and avoid scanning the
whole bitmap when the cache is known to be clean.
Signed-off-by: NNeil Brown <neilb@suse.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 a35e63ef
...@@ -1047,6 +1047,11 @@ void bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1047,6 +1047,11 @@ void bitmap_daemon_work(struct bitmap *bitmap)
if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ)) if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ))
return; return;
bitmap->daemon_lastrun = jiffies; bitmap->daemon_lastrun = jiffies;
if (bitmap->allclean) {
bitmap->mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
return;
}
bitmap->allclean = 1;
for (j = 0; j < bitmap->chunks; j++) { for (j = 0; j < bitmap->chunks; j++) {
bitmap_counter_t *bmc; bitmap_counter_t *bmc;
...@@ -1068,8 +1073,10 @@ void bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1068,8 +1073,10 @@ void bitmap_daemon_work(struct bitmap *bitmap)
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) {
write_page(bitmap, page, 0); write_page(bitmap, page, 0);
bitmap->allclean = 0;
}
continue; continue;
} }
...@@ -1098,6 +1105,9 @@ void bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1098,6 +1105,9 @@ void bitmap_daemon_work(struct bitmap *bitmap)
/* /*
if (j < 100) printk("bitmap: j=%lu, *bmc = 0x%x\n", j, *bmc); if (j < 100) printk("bitmap: j=%lu, *bmc = 0x%x\n", j, *bmc);
*/ */
if (*bmc)
bitmap->allclean = 0;
if (*bmc == 2) { if (*bmc == 2) {
*bmc=1; /* maybe clear the bit next time */ *bmc=1; /* maybe clear the bit next time */
set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
...@@ -1132,6 +1142,8 @@ void bitmap_daemon_work(struct bitmap *bitmap) ...@@ -1132,6 +1142,8 @@ void bitmap_daemon_work(struct bitmap *bitmap)
} }
} }
if (bitmap->allclean == 0)
bitmap->mddev->thread->timeout = bitmap->daemon_sleep * HZ;
} }
static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
...@@ -1226,6 +1238,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect ...@@ -1226,6 +1238,7 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
sectors -= blocks; sectors -= blocks;
else sectors = 0; else sectors = 0;
} }
bitmap->allclean = 0;
return 0; return 0;
} }
...@@ -1296,6 +1309,7 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, ...@@ -1296,6 +1309,7 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
} }
} }
spin_unlock_irq(&bitmap->lock); spin_unlock_irq(&bitmap->lock);
bitmap->allclean = 0;
return rv; return rv;
} }
...@@ -1332,6 +1346,7 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int ab ...@@ -1332,6 +1346,7 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int ab
} }
unlock: unlock:
spin_unlock_irqrestore(&bitmap->lock, flags); spin_unlock_irqrestore(&bitmap->lock, flags);
bitmap->allclean = 0;
} }
void bitmap_close_sync(struct bitmap *bitmap) void bitmap_close_sync(struct bitmap *bitmap)
...@@ -1399,7 +1414,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n ...@@ -1399,7 +1414,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n
set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
} }
spin_unlock_irq(&bitmap->lock); spin_unlock_irq(&bitmap->lock);
bitmap->allclean = 0;
} }
/* dirty the memory and file bits for bitmap chunks "s" to "e" */ /* dirty the memory and file bits for bitmap chunks "s" to "e" */
......
...@@ -235,6 +235,8 @@ struct bitmap { ...@@ -235,6 +235,8 @@ struct bitmap {
unsigned long flags; unsigned long flags;
int allclean;
unsigned long max_write_behind; /* write-behind mode */ unsigned long max_write_behind; /* write-behind mode */
atomic_t behind_writes; atomic_t behind_writes;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册