aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid6main.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-01-06 03:20:33 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-06 11:34:06 -0500
commitfccddba060f2b4916a30aa27acc3d03b01bb981e (patch)
tree92fbb81ab3b1fdbbe8de9ba2ebb91ac68c57b2a0 /drivers/md/raid6main.c
parent9ffae0cf3ea02f75d163922accfd3e592d87adde (diff)
[PATCH] md: tidy up raid5/6 hash table code
- replace open-coded hash chain with hlist macros - Fix hash-table size at one page - it is already quite generous, so there will never be a need to use multiple pages, so no need for __get_free_pages No functional change. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/md/raid6main.c')
-rw-r--r--drivers/md/raid6main.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index 4062fc16ac2b..79b5244f44f4 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -40,12 +40,10 @@
40#define STRIPE_SHIFT (PAGE_SHIFT - 9) 40#define STRIPE_SHIFT (PAGE_SHIFT - 9)
41#define STRIPE_SECTORS (STRIPE_SIZE>>9) 41#define STRIPE_SECTORS (STRIPE_SIZE>>9)
42#define IO_THRESHOLD 1 42#define IO_THRESHOLD 1
43#define HASH_PAGES 1 43#define NR_HASH (PAGE_SIZE / sizeof(struct hlist_head))
44#define HASH_PAGES_ORDER 0
45#define NR_HASH (HASH_PAGES * PAGE_SIZE / sizeof(struct stripe_head *))
46#define HASH_MASK (NR_HASH - 1) 44#define HASH_MASK (NR_HASH - 1)
47 45
48#define stripe_hash(conf, sect) ((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK]) 46#define stripe_hash(conf, sect) (&((conf)->stripe_hashtbl[((sect) >> STRIPE_SHIFT) & HASH_MASK]))
49 47
50/* bio's attached to a stripe+device for I/O are linked together in bi_sector 48/* bio's attached to a stripe+device for I/O are linked together in bi_sector
51 * order without overlap. There may be several bio's per stripe+device, and 49 * order without overlap. There may be several bio's per stripe+device, and
@@ -132,29 +130,21 @@ static void release_stripe(struct stripe_head *sh)
132 spin_unlock_irqrestore(&conf->device_lock, flags); 130 spin_unlock_irqrestore(&conf->device_lock, flags);
133} 131}
134 132
135static void remove_hash(struct stripe_head *sh) 133static inline void remove_hash(struct stripe_head *sh)
136{ 134{
137 PRINTK("remove_hash(), stripe %llu\n", (unsigned long long)sh->sector); 135 PRINTK("remove_hash(), stripe %llu\n", (unsigned long long)sh->sector);
138 136
139 if (sh->hash_pprev) { 137 hlist_del_init(&sh->hash);
140 if (sh->hash_next)
141 sh->hash_next->hash_pprev = sh->hash_pprev;
142 *sh->hash_pprev = sh->hash_next;
143 sh->hash_pprev = NULL;
144 }
145} 138}
146 139
147static __inline__ void insert_hash(raid6_conf_t *conf, struct stripe_head *sh) 140static inline void insert_hash(raid6_conf_t *conf, struct stripe_head *sh)
148{ 141{
149 struct stripe_head **shp = &stripe_hash(conf, sh->sector); 142 struct hlist_head *hp = stripe_hash(conf, sh->sector);
150 143
151 PRINTK("insert_hash(), stripe %llu\n", (unsigned long long)sh->sector); 144 PRINTK("insert_hash(), stripe %llu\n", (unsigned long long)sh->sector);
152 145
153 CHECK_DEVLOCK(); 146 CHECK_DEVLOCK();
154 if ((sh->hash_next = *shp) != NULL) 147 hlist_add_head(&sh->hash, hp);
155 (*shp)->hash_pprev = &sh->hash_next;
156 *shp = sh;
157 sh->hash_pprev = shp;
158} 148}
159 149
160 150
@@ -247,10 +237,11 @@ static inline void init_stripe(struct stripe_head *sh, sector_t sector, int pd_i
247static struct stripe_head *__find_stripe(raid6_conf_t *conf, sector_t sector) 237static struct stripe_head *__find_stripe(raid6_conf_t *conf, sector_t sector)
248{ 238{
249 struct stripe_head *sh; 239 struct stripe_head *sh;
240 struct hlist_node *hn;
250 241
251 CHECK_DEVLOCK(); 242 CHECK_DEVLOCK();
252 PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector); 243 PRINTK("__find_stripe, sector %llu\n", (unsigned long long)sector);
253 for (sh = stripe_hash(conf, sector); sh; sh = sh->hash_next) 244 hlist_for_each_entry (sh, hn, stripe_hash(conf, sector), hash)
254 if (sh->sector == sector) 245 if (sh->sector == sector)
255 return sh; 246 return sh;
256 PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector); 247 PRINTK("__stripe %llu not in cache\n", (unsigned long long)sector);
@@ -1931,17 +1922,15 @@ static int run(mddev_t *mddev)
1931 return -EIO; 1922 return -EIO;
1932 } 1923 }
1933 1924
1934 mddev->private = kmalloc (sizeof (raid6_conf_t) 1925 mddev->private = kzalloc(sizeof (raid6_conf_t)
1935 + mddev->raid_disks * sizeof(struct disk_info), 1926 + mddev->raid_disks * sizeof(struct disk_info),
1936 GFP_KERNEL); 1927 GFP_KERNEL);
1937 if ((conf = mddev->private) == NULL) 1928 if ((conf = mddev->private) == NULL)
1938 goto abort; 1929 goto abort;
1939 memset (conf, 0, sizeof (*conf) + mddev->raid_disks * sizeof(struct disk_info) );
1940 conf->mddev = mddev; 1930 conf->mddev = mddev;
1941 1931
1942 if ((conf->stripe_hashtbl = (struct stripe_head **) __get_free_pages(GFP_ATOMIC, HASH_PAGES_ORDER)) == NULL) 1932 if ((conf->stripe_hashtbl = kzalloc(PAGE_SIZE, GFP_KERNEL)) == NULL)
1943 goto abort; 1933 goto abort;
1944 memset(conf->stripe_hashtbl, 0, HASH_PAGES * PAGE_SIZE);
1945 1934
1946 conf->spare_page = alloc_page(GFP_KERNEL); 1935 conf->spare_page = alloc_page(GFP_KERNEL);
1947 if (!conf->spare_page) 1936 if (!conf->spare_page)
@@ -2085,9 +2074,7 @@ abort:
2085 print_raid6_conf(conf); 2074 print_raid6_conf(conf);
2086 if (conf->spare_page) 2075 if (conf->spare_page)
2087 put_page(conf->spare_page); 2076 put_page(conf->spare_page);
2088 if (conf->stripe_hashtbl) 2077 kfree(conf->stripe_hashtbl);
2089 free_pages((unsigned long) conf->stripe_hashtbl,
2090 HASH_PAGES_ORDER);
2091 kfree(conf); 2078 kfree(conf);
2092 } 2079 }
2093 mddev->private = NULL; 2080 mddev->private = NULL;
@@ -2104,7 +2091,7 @@ static int stop (mddev_t *mddev)
2104 md_unregister_thread(mddev->thread); 2091 md_unregister_thread(mddev->thread);
2105 mddev->thread = NULL; 2092 mddev->thread = NULL;
2106 shrink_stripes(conf); 2093 shrink_stripes(conf);
2107 free_pages((unsigned long) conf->stripe_hashtbl, HASH_PAGES_ORDER); 2094 kfree(conf->stripe_hashtbl);
2108 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 2095 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
2109 kfree(conf); 2096 kfree(conf);
2110 mddev->private = NULL; 2097 mddev->private = NULL;
@@ -2131,12 +2118,13 @@ static void print_sh (struct seq_file *seq, struct stripe_head *sh)
2131static void printall (struct seq_file *seq, raid6_conf_t *conf) 2118static void printall (struct seq_file *seq, raid6_conf_t *conf)
2132{ 2119{
2133 struct stripe_head *sh; 2120 struct stripe_head *sh;
2121 struct hlist_node *hn;
2134 int i; 2122 int i;
2135 2123
2136 spin_lock_irq(&conf->device_lock); 2124 spin_lock_irq(&conf->device_lock);
2137 for (i = 0; i < NR_HASH; i++) { 2125 for (i = 0; i < NR_HASH; i++) {
2138 sh = conf->stripe_hashtbl[i]; 2126 sh = conf->stripe_hashtbl[i];
2139 for (; sh; sh = sh->hash_next) { 2127 hlist_for_each_entry(sh, hn, &conf->stripe_hashtbl[i], hash) {
2140 if (sh->raid_conf != conf) 2128 if (sh->raid_conf != conf)
2141 continue; 2129 continue;
2142 print_sh(seq, sh); 2130 print_sh(seq, sh);