Skip to content

Commit da67db4

Browse files
committed
Merge branch 'hpfs' from Mikulas Patocka
Merge hpfs patches from Mikulas Patocka. * emailed patches from Mikulas Patocka <[email protected]>: hpfs: implement prefetch to improve performance hpfs: use mpage hpfs: better test for errors
2 parents 65b97fb + 275f495 commit da67db4

File tree

5 files changed

+106
-13
lines changed

5 files changed

+106
-13
lines changed

fs/hpfs/buffer.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,37 @@
77
*/
88
#include <linux/sched.h>
99
#include <linux/slab.h>
10+
#include <linux/blkdev.h>
1011
#include "hpfs_fn.h"
1112

13+
void hpfs_prefetch_sectors(struct super_block *s, unsigned secno, int n)
14+
{
15+
struct buffer_head *bh;
16+
struct blk_plug plug;
17+
18+
if (n <= 0 || unlikely(secno >= hpfs_sb(s)->sb_fs_size))
19+
return;
20+
21+
bh = sb_find_get_block(s, secno);
22+
if (bh) {
23+
if (buffer_uptodate(bh)) {
24+
brelse(bh);
25+
return;
26+
}
27+
brelse(bh);
28+
};
29+
30+
blk_start_plug(&plug);
31+
while (n > 0) {
32+
if (unlikely(secno >= hpfs_sb(s)->sb_fs_size))
33+
break;
34+
sb_breadahead(s, secno);
35+
secno++;
36+
n--;
37+
}
38+
blk_finish_plug(&plug);
39+
}
40+
1241
/* Map a sector into a buffer and return pointers to it and to the buffer. */
1342

1443
void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
@@ -18,6 +47,8 @@ void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head
1847

1948
hpfs_lock_assert(s);
2049

50+
hpfs_prefetch_sectors(s, secno, ahead);
51+
2152
cond_resched();
2253

2354
*bhp = bh = sb_bread(s, secno);
@@ -67,6 +98,8 @@ void *hpfs_map_4sectors(struct super_block *s, unsigned secno, struct quad_buffe
6798
return NULL;
6899
}
69100

101+
hpfs_prefetch_sectors(s, secno, 4 + ahead);
102+
70103
qbh->data = data = kmalloc(2048, GFP_NOFS);
71104
if (!data) {
72105
printk("HPFS: hpfs_map_4sectors: out of memory\n");

fs/hpfs/file.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "hpfs_fn.h"
10+
#include <linux/mpage.h>
1011

1112
#define BLOCKS(size) (((size) + 511) >> 9)
1213

@@ -34,19 +35,28 @@ int hpfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
3435
* so we must ignore such errors.
3536
*/
3637

37-
static secno hpfs_bmap(struct inode *inode, unsigned file_secno)
38+
static secno hpfs_bmap(struct inode *inode, unsigned file_secno, unsigned *n_secs)
3839
{
3940
struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
4041
unsigned n, disk_secno;
4142
struct fnode *fnode;
4243
struct buffer_head *bh;
4344
if (BLOCKS(hpfs_i(inode)->mmu_private) <= file_secno) return 0;
4445
n = file_secno - hpfs_inode->i_file_sec;
45-
if (n < hpfs_inode->i_n_secs) return hpfs_inode->i_disk_sec + n;
46+
if (n < hpfs_inode->i_n_secs) {
47+
*n_secs = hpfs_inode->i_n_secs - n;
48+
return hpfs_inode->i_disk_sec + n;
49+
}
4650
if (!(fnode = hpfs_map_fnode(inode->i_sb, inode->i_ino, &bh))) return 0;
4751
disk_secno = hpfs_bplus_lookup(inode->i_sb, inode, &fnode->btree, file_secno, bh);
4852
if (disk_secno == -1) return 0;
4953
if (hpfs_chk_sectors(inode->i_sb, disk_secno, 1, "bmap")) return 0;
54+
n = file_secno - hpfs_inode->i_file_sec;
55+
if (n < hpfs_inode->i_n_secs) {
56+
*n_secs = hpfs_inode->i_n_secs - n;
57+
return hpfs_inode->i_disk_sec + n;
58+
}
59+
*n_secs = 1;
5060
return disk_secno;
5161
}
5262

@@ -67,10 +77,14 @@ static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_he
6777
{
6878
int r;
6979
secno s;
80+
unsigned n_secs;
7081
hpfs_lock(inode->i_sb);
71-
s = hpfs_bmap(inode, iblock);
82+
s = hpfs_bmap(inode, iblock, &n_secs);
7283
if (s) {
84+
if (bh_result->b_size >> 9 < n_secs)
85+
n_secs = bh_result->b_size >> 9;
7386
map_bh(bh_result, inode->i_sb, s);
87+
bh_result->b_size = n_secs << 9;
7488
goto ret_0;
7589
}
7690
if (!create) goto ret_0;
@@ -95,14 +109,26 @@ static int hpfs_get_block(struct inode *inode, sector_t iblock, struct buffer_he
95109
return r;
96110
}
97111

112+
static int hpfs_readpage(struct file *file, struct page *page)
113+
{
114+
return mpage_readpage(page, hpfs_get_block);
115+
}
116+
98117
static int hpfs_writepage(struct page *page, struct writeback_control *wbc)
99118
{
100-
return block_write_full_page(page,hpfs_get_block, wbc);
119+
return block_write_full_page(page, hpfs_get_block, wbc);
101120
}
102121

103-
static int hpfs_readpage(struct file *file, struct page *page)
122+
static int hpfs_readpages(struct file *file, struct address_space *mapping,
123+
struct list_head *pages, unsigned nr_pages)
124+
{
125+
return mpage_readpages(mapping, pages, nr_pages, hpfs_get_block);
126+
}
127+
128+
static int hpfs_writepages(struct address_space *mapping,
129+
struct writeback_control *wbc)
104130
{
105-
return block_read_full_page(page,hpfs_get_block);
131+
return mpage_writepages(mapping, wbc, hpfs_get_block);
106132
}
107133

108134
static void hpfs_write_failed(struct address_space *mapping, loff_t to)
@@ -161,6 +187,8 @@ static sector_t _hpfs_bmap(struct address_space *mapping, sector_t block)
161187
const struct address_space_operations hpfs_aops = {
162188
.readpage = hpfs_readpage,
163189
.writepage = hpfs_writepage,
190+
.readpages = hpfs_readpages,
191+
.writepages = hpfs_writepages,
164192
.write_begin = hpfs_write_begin,
165193
.write_end = hpfs_write_end,
166194
.bmap = _hpfs_bmap

fs/hpfs/hpfs_fn.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
#define ALLOC_FWD_MAX 128
2828
#define ALLOC_M 1
2929
#define FNODE_RD_AHEAD 16
30-
#define ANODE_RD_AHEAD 16
31-
#define DNODE_RD_AHEAD 4
30+
#define ANODE_RD_AHEAD 0
31+
#define DNODE_RD_AHEAD 72
32+
#define COUNT_RD_AHEAD 62
3233

3334
#define FREE_DNODES_ADD 58
3435
#define FREE_DNODES_DEL 29
@@ -207,6 +208,7 @@ void hpfs_remove_fnode(struct super_block *, fnode_secno fno);
207208

208209
/* buffer.c */
209210

211+
void hpfs_prefetch_sectors(struct super_block *, unsigned, int);
210212
void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
211213
void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
212214
void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
@@ -271,6 +273,7 @@ void hpfs_evict_inode(struct inode *);
271273

272274
__le32 *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
273275
__le32 *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
276+
void hpfs_prefetch_bitmap(struct super_block *, unsigned);
274277
unsigned char *hpfs_load_code_page(struct super_block *, secno);
275278
__le32 *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
276279
struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);

fs/hpfs/map.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ __le32 *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
1717
struct quad_buffer_head *qbh, char *id)
1818
{
1919
secno sec;
20-
if (hpfs_sb(s)->sb_chk) if (bmp_block * 16384 > hpfs_sb(s)->sb_fs_size) {
20+
__le32 *ret;
21+
unsigned n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
22+
if (hpfs_sb(s)->sb_chk) if (bmp_block >= n_bands) {
2123
hpfs_error(s, "hpfs_map_bitmap called with bad parameter: %08x at %s", bmp_block, id);
2224
return NULL;
2325
}
@@ -26,7 +28,23 @@ __le32 *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
2628
hpfs_error(s, "invalid bitmap block pointer %08x -> %08x at %s", bmp_block, sec, id);
2729
return NULL;
2830
}
29-
return hpfs_map_4sectors(s, sec, qbh, 4);
31+
ret = hpfs_map_4sectors(s, sec, qbh, 4);
32+
if (ret) hpfs_prefetch_bitmap(s, bmp_block + 1);
33+
return ret;
34+
}
35+
36+
void hpfs_prefetch_bitmap(struct super_block *s, unsigned bmp_block)
37+
{
38+
unsigned to_prefetch, next_prefetch;
39+
unsigned n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
40+
if (unlikely(bmp_block >= n_bands))
41+
return;
42+
to_prefetch = le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[bmp_block]);
43+
if (unlikely(bmp_block + 1 >= n_bands))
44+
next_prefetch = 0;
45+
else
46+
next_prefetch = le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[bmp_block + 1]);
47+
hpfs_prefetch_sectors(s, to_prefetch, 4 + 4 * (to_prefetch + 4 == next_prefetch));
3048
}
3149

3250
/*

fs/hpfs/super.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
121121
unsigned long *bits;
122122
unsigned count;
123123

124-
bits = hpfs_map_4sectors(s, secno, &qbh, 4);
124+
bits = hpfs_map_4sectors(s, secno, &qbh, 0);
125125
if (!bits)
126126
return 0;
127127
count = bitmap_weight(bits, 2048 * BITS_PER_BYTE);
@@ -134,8 +134,13 @@ static unsigned count_bitmaps(struct super_block *s)
134134
unsigned n, count, n_bands;
135135
n_bands = (hpfs_sb(s)->sb_fs_size + 0x3fff) >> 14;
136136
count = 0;
137-
for (n = 0; n < n_bands; n++)
137+
for (n = 0; n < COUNT_RD_AHEAD; n++) {
138+
hpfs_prefetch_bitmap(s, n);
139+
}
140+
for (n = 0; n < n_bands; n++) {
141+
hpfs_prefetch_bitmap(s, n + COUNT_RD_AHEAD);
138142
count += hpfs_count_one_bitmap(s, le32_to_cpu(hpfs_sb(s)->sb_bmp_dir[n]));
143+
}
139144
return count;
140145
}
141146

@@ -558,7 +563,13 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
558563
sbi->sb_cp_table = NULL;
559564
sbi->sb_c_bitmap = -1;
560565
sbi->sb_max_fwd_alloc = 0xffffff;
561-
566+
567+
if (sbi->sb_fs_size >= 0x80000000) {
568+
hpfs_error(s, "invalid size in superblock: %08x",
569+
(unsigned)sbi->sb_fs_size);
570+
goto bail4;
571+
}
572+
562573
/* Load bitmap directory */
563574
if (!(sbi->sb_bmp_dir = hpfs_load_bitmap_directory(s, le32_to_cpu(superblock->bitmaps))))
564575
goto bail4;

0 commit comments

Comments
 (0)