[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ogfs-dev]vmalloc/vfree bugs in osi_malloc/osi_free

I just found a paper "How NOT to write kernel drivers".  In
section 2.2, some ogfs code is used as a bad example:

  Most tutorials warn about using kmalloc for al-locating big areas of
  memory, and it seems a lot of people also notice these limits in

    static __inline void *
    osi_malloc(unsigned int size)
        if (size > 2*PAGE_SIZE)
            return __vmalloc(size, GFP_NOFS|__GFP_HIGHMEM, PAGE_KERNEL);
        return kmalloc(size, GFP_NOFS);
[due to cut and paste problems with acroread, I inserted the code
from the ogfs cvs]

  from OpenGFS 0.99.2 There are several problems with such an approach.
  The first one is performance: vmalloc() ed memory requires more TLBs,
  which are a rare resource on most CPUs. A more serious problem arises
  when the osi_free() routine gets involved: it calls vfree() for the
  vmalloc()ed memory, and it s illegal to call vfree() from inter-rupt
  context. This abstraction makes it okay to call the osi_free()
  function from interrupt context sometimes, but not for big
  allocations. A third issue that most tutorials don t mention is that
  while you can use vmalloc() to allo-cate larger chunks of memory, the
  total amount you can allocate is rather limited, in the or-der of 64
  Megabytes on modern machines (de-pending on what PCI hardware is

And indeed this code ise still in the sources
(include/osi_linux_2_4.h).  I'm not deep enough into writing
kernel code to figure out what the correct fix is.  Does the
author suggest to always use kmalloc instead of vmalloc?


Dominik ^_^  ^_^

This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
Opengfs-devel mailing list

[Index of Archives]     [Kernel]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Clusters]     [Linux RAID]     [Yosemite Hiking]     [Linux Resources]

Powered by Linux