Commit 40a063f6691ce937a3d00c9700b6964b5ec4e022

Authored by Eric Sandeen
Committed by Jan Kara
1 parent 156e74312f

ext2: speed up file creates by optimizing rec_len functions

The addition of 64k block capability in the rec_len_from_disk
and rec_len_to_disk functions added a bit of math overhead which
slows down file create workloads needlessly when the architecture
cannot even support 64k blocks, thanks to page size limits.

The directory entry checking can also be optimized a bit
by sprinkling in some unlikely() conditions to move the
error handling out of line.

bonnie++ sequential file creates on a 512MB ramdisk speeds up
from about 2200/s to about 2500/s, about a 14% improvement.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>

Showing 1 changed file with 14 additions and 5 deletions Side-by-side Diff

... ... @@ -28,21 +28,30 @@
28 28  
29 29 typedef struct ext2_dir_entry_2 ext2_dirent;
30 30  
  31 +/*
  32 + * Tests against MAX_REC_LEN etc were put in place for 64k block
  33 + * sizes; if that is not possible on this arch, we can skip
  34 + * those tests and speed things up.
  35 + */
31 36 static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
32 37 {
33 38 unsigned len = le16_to_cpu(dlen);
34 39  
  40 +#if (PAGE_CACHE_SIZE >= 65536)
35 41 if (len == EXT2_MAX_REC_LEN)
36 42 return 1 << 16;
  43 +#endif
37 44 return len;
38 45 }
39 46  
40 47 static inline __le16 ext2_rec_len_to_disk(unsigned len)
41 48 {
  49 +#if (PAGE_CACHE_SIZE >= 65536)
42 50 if (len == (1 << 16))
43 51 return cpu_to_le16(EXT2_MAX_REC_LEN);
44 52 else
45 53 BUG_ON(len > (1 << 16));
  54 +#endif
46 55 return cpu_to_le16(len);
47 56 }
48 57  
49 58  
50 59  
51 60  
52 61  
... ... @@ -129,15 +138,15 @@
129 138 p = (ext2_dirent *)(kaddr + offs);
130 139 rec_len = ext2_rec_len_from_disk(p->rec_len);
131 140  
132   - if (rec_len < EXT2_DIR_REC_LEN(1))
  141 + if (unlikely(rec_len < EXT2_DIR_REC_LEN(1)))
133 142 goto Eshort;
134   - if (rec_len & 3)
  143 + if (unlikely(rec_len & 3))
135 144 goto Ealign;
136   - if (rec_len < EXT2_DIR_REC_LEN(p->name_len))
  145 + if (unlikely(rec_len < EXT2_DIR_REC_LEN(p->name_len)))
137 146 goto Enamelen;
138   - if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
  147 + if (unlikely(((offs + rec_len - 1) ^ offs) & ~(chunk_size-1)))
139 148 goto Espan;
140   - if (le32_to_cpu(p->inode) > max_inumber)
  149 + if (unlikely(le32_to_cpu(p->inode) > max_inumber))
141 150 goto Einumber;
142 151 }
143 152 if (offs != limit)