Re: memory management and device drivers

Linus Torvalds (
Mon, 14 Aug 1995 07:29:03 +0300

Jeff Newbern: "memory management and device drivers" (Aug 13, 18:09):
> I am currently writing a PCI character device driver. This PCI card
> places its registers and other memory regions in PCI memory space, so I
> need to use the vremap() call to map their physical addresses (above
> high_memory) into kernel virtual space.
> Here's the problem: vremap() calls get_vm_area() which calls kmalloc().
> Since vremap() is called at driver init time (out of chr_dev_init() in
> drivers/char/mem.c) there are some bad interactions with the memory
> management. My driver init routine calls vremap(), which calls
> get_vm_area() which calls kmalloc() to obtain a (16 byte) vm_area struct
> for the new memory area. This produces a "warning -- bdflush not running"
> message and kmalloc() returns NULL. Thus get_vm_area() returns NULL and
> vremap() returns NULL, and my driver disables itself.

Indeed. The vremap() (like other vxxxx memory management functions)
assumes that the memory management is already up and running. As such
it's not usable at early system initialization. I'd suggest using it
either in a module (vremap() is exported in the latest kernels), or
doing your initialization as late as possible.

One good place is in "device_setup()", which currently handles only disk
drivers, but is really meant to be rather general. It is called when
the system is more-or-less up and running, and you can sleep and
allocate memory without problems.