Re: Raid0 needs more memory.

Tall cool one (ice@mama.indstate.edu)
Wed, 2 Jul 1997 14:01:48 -0500


Taking people's advice I patched raid0 to use vmalloc instead of kmalloc,
and it should now fail gracefully if it doesn't get the memory it wants and
also it prints out how much hash memory it's attempting to malloc, just in
case you should want to know (make it easier to tune your memory usage).

Here is the patch:

-------- cut --------
--- linux-orig/drivers/block/raid0.c Sun May 19 23:50:46 1996
+++ linux/drivers/block/raid0.c Wed Jul 2 13:48:29 1997
@@ -26,7 +26,7 @@
#define MD_DRIVER
#define MD_PERSONALITY

-static void create_strip_zones (int minor, struct md_dev *mddev)
+static int create_strip_zones (int minor, struct md_dev *mddev)
{
int i, j, c=0;
int current_offset=0;
@@ -50,8 +50,8 @@
c=0;
}

- data->strip_zone=kmalloc (sizeof(struct strip_zone)*data->nr_strip_zones,
- GFP_KERNEL);
+ if ((data->strip_zone=vmalloc(sizeof(struct strip_zone)*data->nr_strip_zones)) == NULL)
+ return 1;

data->smallest=NULL;

@@ -81,6 +81,7 @@
data->strip_zone[i-1].size) : 0;
current_offset=smallest_by_zone->size;
}
+ return 0;
}

static int raid0_run (int minor, struct md_dev *mddev)
@@ -90,16 +91,18 @@

MOD_INC_USE_COUNT;

- mddev->private=kmalloc (sizeof (struct raid0_data), GFP_KERNEL);
+ if ((mddev->private=vmalloc (sizeof (struct raid0_data))) == NULL) return 1;
data=(struct raid0_data *) mddev->private;

- create_strip_zones (minor, mddev);
+ if (create_strip_zones (minor, mddev)) return 1;

nb_zone=data->nr_zones=
md_size[minor]/data->smallest->size +
(md_size[minor]%data->smallest->size ? 1 : 0);
-
- data->hash_table=kmalloc (sizeof (struct raid0_hash)*nb_zone, GFP_KERNEL);
+
+ printk ("raid0 : Allocating %d bytes for hash.\n",sizeof(struct raid0_hash)*nb_zone);
+ if ((data->hash_table=vmalloc (sizeof (struct raid0_hash)*nb_zone)) == NULL)
+ return 1;

size=data->strip_zone[cur].size;

@@ -142,9 +145,9 @@
{
struct raid0_data *data=(struct raid0_data *) mddev->private;

- kfree (data->hash_table);
- kfree (data->strip_zone);
- kfree (data);
+ vfree (data->hash_table);
+ vfree (data->strip_zone);
+ vfree (data);

MOD_DEC_USE_COUNT;
return 0;
-------- cut --------

Not heavily tested, I don't have my 12GB of drive space to test it with
handy anymore =(, but it worked with a smaller raid array, and I'm going to
assume it'll work with any size. Also I didn't really test the "didn't get
the memory it wants" condition, I'm assuming MD will do the right thing with
the returned failure status from raid0_run().

Enjoy...

- Steve

.------------------------------------------------. # * # # # # # #
| Steve Baker | Barely Working | # ## # # # # #
| ice@mama.indstate.edu | System Administrator | # # # # # # # #
| Red-Hat Rulz! | Will work for hardware | # # # ## # # # #
`--- SYS-ADMIN FOR HIRE, HAVE UNIX, WILL TRAVEL -' #### # # # ## # #