total_RAM global for ramdisk size = 1/2 RAM

Rick Hohensee (humbubba@raptor.cqi.com)
Tue, 19 Jan 1999 01:09:58 -0500 (EST)


I think this one may well be worth doing. I don't think the actual code I
did it with is likely to be acceptable. I changed some stuff so the size
of ramdisks is one half the size of total RAM on the box. The way I do it
here this involved a computation of total ram in init/main.c, a divide by
two of that value in drivers/block/rd.c, and a declaration of a global in
a header file common to those two, for which I used init.h.

I declare total_RAM in linux/init.h, compute it in start_kernel() in
init/main.c, and take 1/2 of it for what was rd_size in drivers/block/rd.c.
As it is I get one cast warning, and it works. I get a 14meg ramdisk on
a 32 meg box. I compiled a 1.0.9 kernel on that 14meg ramdisk. It wasn't
noticably faster than on an old SCSI drive. My primary interest in this
survives though, due to the installation possibilities created by very
large ramdisks that size themselves sensibly to the box. I'll be using
this.

The kernel using this hack is 2.2pre5.

Also, in my haste, I think this breaks the commandline control of
ramdisk_size . I don't use rd_size at all in this example. Note that
rd_size was in effect an upper size limit on ramdisks for
straight-from-floppy kernels. My first post to this list was about that.

Since I doubt my code is remotely suitable, I didn't bother with a
systematic patch, just some plain cut/paste outtakes showing what I did.
Look for total_RAM for what I changed. And a few other lines.

BTW, the rdev manpage needs attention. Unless it's been updated.

Rick Hohensee

<linux/init.h>
########################################################################

<<<<snip>>>>>>
/*
* Disable the __initfunc macros if a file that is a part of a
* module attempts to use them. We do not want to interfere
* with module linking.
*/

unsigned long total_RAM ;

#ifndef MODULE
#include <asm/init.h>
#else
#define __init
#define __initdata
#define __initfunc(__arginit) __arginit
/* For assembly routines */
#define __INIT
<<<<<<snip>>>>>>>
######################################################################

/*
* linux/init/main.c
###############################snipsnipsnip##################

/*
* Activate the first processor.
*/

/* ##################################################################
######### A Linux is Born ###############################################
this is where platform-independant flow begins, an asmlinkage "main()"
apparently #############################################################
*/

asmlinkage void __init start_kernel(void)
{
char * command_line;

#ifdef __SMP__
static int boot_cpu = 1;
/* "current" has been set up, we need to load it now */
if (!boot_cpu)
initialize_secondary();
boot_cpu = 0;
#endif

/*
* Interrupts are still disabled. Do necessary setups, then
* enable them
*/
printk(linux_banner);
setup_arch(&command_line, &memory_start, &memory_end);
memory_start = paging_init(memory_start,memory_end);
trap_init();
init_IRQ();
sched_init();
time_init();
parse_options(command_line);

/*
* HACK ALERT! This is early. We're enabling the console before
* we've done PCI setups etc, and console_init() must be aware of
* this. But we do want output early, in case something goes wrong.
*/
total_RAM = memory_end - memory_start ;
memory_start = console_init(memory_start,memory_end);
#ifdef CONFIG_MODULES
init_modules();
#endif
if (prof_shift) {
###############################snipsnip###########################

/*
* ramdisk.c - Multiple RAM disk driver - gzip-loading version - v. 0.8 beta.
*
* (C) Chad Page, Theodore Ts'o, et. al, 1995.
*
* This RAM disk is designed to have filesystems created on it and mounted
* just like a regular floppy disk.
*
* It also does something suggested by Linus: use the buffer cache as the
* RAM disk data. This makes it possible to dynamically allocate the RAM disk
* buffer - with some consequences I have to deal with as I write this.
*
* This code is based on the original ramdisk.c, written mostly by
* Theodore Ts'o (TYT) in 1991. The code was largely rewritten by
* Chad Page to use the buffer cache to store the RAM disk data in
* 1995; Theodore then took over the driver again, and cleaned it up
* for inclusion in the mainline kernel.
*
* The original CRAMDISK code was written by Richard Lyons, and
* adapted by Chad Page to use the new RAM disk interface. Theodore
* Ts'o rewrote it so that both the compressed RAM disk loader and the
* kernel decompressor uses the same inflate.c codebase. The RAM disk
* loader now also loads into a dynamic (buffer cache based) RAM disk,
* not the old static RAM disk. Support for the old static RAM disk has
* been completely removed.
*
* Loadable module support added by Tom Dyas.
*
* Further cleanups by Chad Page (page0588@sundance.sjsu.edu):
* Cosmetic changes in #ifdef MODULE, code movement, etc.
* When the RAM disk module is removed, free the protected buffers
* Default RAM disk size changed to 2.88 MB
*
* Added initrd: Werner Almesberger & Hans Lermen, Feb '96
*
* 4/25/96 : Made RAM disk size a parameter (default is now 4 MB)
* - Chad Page
*###### this is not a default, it is a MAXIMUM ###########

* Add support for fs images split across >1 disk, Paul Gortmaker, Mar '98
*
*/

#include <linux/config.h>
#include <linux/sched.h>
#include <linux/minix_fs.h>
#include <linux/ext2_fs.h>
#include <linux/romfs_fs.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/malloc.h>
#include <linux/ioctl.h>
#include <linux/fd.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/system.h>
#include <asm/uaccess.h>
#include <asm/byteorder.h>

extern void wait_for_keypress(void);

/*
* 35 has been officially registered as the RAMDISK major number, but
* so is the original MAJOR number of 1. We're using 1 in
* include/linux/major.h for now
*/
#define MAJOR_NR RAMDISK_MAJOR
#include <linux/blk.h>

/* The RAM disk size is now a parameter */
#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */

#ifndef MODULE
/* We don't have to load RAM disks or gunzip them in a module. */
#define RD_LOADER
#define BUILD_CRAMDISK

void rd_load(void);
static int crd_load(struct file *fp, struct file *outfp);

#ifdef CONFIG_BLK_DEV_INITRD
static int initrd_users = 0;
#endif
#endif

/* Various static variables go here. Most are used only in the RAM disk code.
*/

static int rd_length[NUM_RAMDISKS];
static int rd_blocksizes[NUM_RAMDISKS];

/*
* Parameters for the boot-loading of the RAM disk. These are set by
* init/main.c (from arguments to the kernel command line) or from the
* architecture-specific setup routine (from the stored boot sector
* information## which may be set in the top Makefile ?
THIS VALUE is apparently the MAXIMUM size a RAMDISK can grow to.).
###############################################################
*/
int rd_size = 0 ; /* we don't use this name */
/* default size of the RAM disks */

##############internal snip############################
#####################################################################
for (i = 0; i < NUM_RAMDISKS; i++) {

rd_length[i] = (total_RAM / 2 );
rd_blocksizes[i] = 1024 ;
}

blksize_size[MAJOR_NR] = rd_blocksizes;

printk("RAM disk driver initialized: %d RAM disks of %dK size\n",
NUM_RAMDISKS, total_RAM >> 11 );

return 0;
}
#########################snip######################################

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/