Commit 21d31f1f authored by Joern Engel's avatar Joern Engel

[PATCH] [MTD] block2mtd: remove readahead code

Over the years there was a slow trickle of complaints against the readahead
code.  Most of them concerned performance, Peter Zijlstra stumbled over it
when working unrelated changes and I believe there was an actual bug report.
Oh, Andrew Morton also complained about duplicating code from mm/readahead.c.

It is just not worth it.  On flash media like usb sticks, readahead will
make things go slow - very slow.  On spinning disks, readahead may be a
win, but this is definitely not the place to add it.
Signed-off-by: default avatarJörn Engel <joern@lazybastard.org>
parent 8870530a
...@@ -40,56 +40,9 @@ struct block2mtd_dev { ...@@ -40,56 +40,9 @@ struct block2mtd_dev {
static LIST_HEAD(blkmtd_device_list); static LIST_HEAD(blkmtd_device_list);
#define PAGE_READAHEAD 64 static struct page* page_read(struct address_space *mapping, int index)
static void cache_readahead(struct address_space *mapping, int index)
{ {
filler_t *filler = (filler_t*)mapping->a_ops->readpage; filler_t *filler = (filler_t*)mapping->a_ops->readpage;
int i, pagei;
unsigned ret = 0;
unsigned long end_index;
struct page *page;
LIST_HEAD(page_pool);
struct inode *inode = mapping->host;
loff_t isize = i_size_read(inode);
if (!isize) {
INFO("iSize=0 in cache_readahead\n");
return;
}
end_index = ((isize - 1) >> PAGE_CACHE_SHIFT);
read_lock_irq(&mapping->tree_lock);
for (i = 0; i < PAGE_READAHEAD; i++) {
pagei = index + i;
if (pagei > end_index) {
INFO("Overrun end of disk in cache readahead\n");
break;
}
page = radix_tree_lookup(&mapping->page_tree, pagei);
if (page && (!i))
break;
if (page)
continue;
read_unlock_irq(&mapping->tree_lock);
page = page_cache_alloc_cold(mapping);
read_lock_irq(&mapping->tree_lock);
if (!page)
break;
page->index = pagei;
list_add(&page->lru, &page_pool);
ret++;
}
read_unlock_irq(&mapping->tree_lock);
if (ret)
read_cache_pages(mapping, &page_pool, filler, NULL);
}
static struct page* page_readahead(struct address_space *mapping, int index)
{
filler_t *filler = (filler_t*)mapping->a_ops->readpage;
cache_readahead(mapping, index);
return read_cache_page(mapping, index, filler, NULL); return read_cache_page(mapping, index, filler, NULL);
} }
...@@ -105,7 +58,7 @@ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len) ...@@ -105,7 +58,7 @@ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
u_long *max; u_long *max;
while (pages) { while (pages) {
page = page_readahead(mapping, index); page = page_read(mapping, index);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
if (IS_ERR(page)) if (IS_ERR(page))
...@@ -174,8 +127,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -174,8 +127,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
cpylen = len; // this page cpylen = len; // this page
len = len - cpylen; len = len - cpylen;
// Get page page = page_read(dev->blkdev->bd_inode->i_mapping, index);
page = page_readahead(dev->blkdev->bd_inode->i_mapping, index);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
if (IS_ERR(page)) if (IS_ERR(page))
...@@ -213,8 +165,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf, ...@@ -213,8 +165,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
cpylen = len; // this page cpylen = len; // this page
len = len - cpylen; len = len - cpylen;
// Get page page = page_read(mapping, index);
page = page_readahead(mapping, index);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
if (IS_ERR(page)) if (IS_ERR(page))
......
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