[patch-2.3.40-pre6] kzalloc() (ala kmem_zalloc() of SVR4)

Tigran Aivazian tigran en sco.COM
Sab Ene 22 14:56:01 CST 2000


On Fri, 21 Jan 2000, Jens Axboe wrote:

> On Fri, Jan 21 2000, Jes Sorensen wrote:
> > Tigran> Hi Linus, a common code sequence of calling kmalloc() and then
> > Tigran> memset(p,0,size) can be optimized into a single exported
> > 
> > The only thing it does is to introduce a new non standard name which
> > makes current code less readable.
> 
> I tend to agree. When (if) the concept of zeroing pages during idle
> time ever gets into the kernel, then it might be worth it having
> a way to get kmalloc() to return zeroed memory. For now it simply
> reduces readability for zero gain.

Consider this:

get_free_page() returns a zeroed page. __get_free_page() returns a page.
Both names are readable. What is the benefit of doing
 
  page = get_free_page(GFP_KERNEL);
  if (!page)
     /* failed */  
  .. use page ..
  free_page(page);

rather than:

  page = __get_free_page(GFP_KERNEL);
  if (!page)
      /* failed */
  clear_page((void *)page);
  ... use page ...
  free_page(page);

You do agree that the first form is more readable although it wastes an
extra if() (one is done inside get_free_page()), don't you? Therefore, for
the same reason it is more readable to use kzalloc() in cases where you
would do kmalloc()/memset(). What is the difference? (other than the fact
that I made it a function instead of a macro or inline as Ingo correctly
pointed out).

Regards,
Tigran.


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



Más información sobre la lista de distribución Ayuda