public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* Re: GFP_ATOMIC allocations...
@ 2002-08-29 15:59 Bryan Henderson
  2002-08-29 16:25 ` Doug Ledford
  2002-08-29 16:50 ` Alan Cox
  0 siblings, 2 replies; 13+ messages in thread
From: Bryan Henderson @ 2002-08-29 15:59 UTC (permalink / raw)
  To: Doug Ledford; +Cc: linux-scsi, patman


>GFP_KERNEL *should* never fail until
>we get to a true OOM condition because it will block and wait for the vm
>subsystem to free us up some space.  Under true OOM conditions it will
>return NULL AFAIK.

That (the NULL case) doesn't sound right to me.  The purpose of the OOM
Killer is to choose wisely which processes should die when there's simply
not enough memory to go around.  And it does it by terminating a process
directly, not by affecting the return value of kmalloc().  So if
kmalloc(GFP_KERNEL) returns NULL when the system is out of memory, the
system is arbitrarily killing whoever is the next guy to ask for memory,
thus defeating the purpose of the OOM Killer.

Incidentally, I've had to explain GFP_ATOMIC to many people, and I believe
the reason for its incorrect usage is that people know it's supposed to be
called by processes that can't wait, and they think that means "I can't
wait for this memory, so be sure you give it to me _now_."  Simple
explanations of GFP_ATOMIC give you the impression that it's just a higher
priority request than GFP_KERNEL.

One thing about GFP_ATOMIC that is often overlooked is that what it really
means is that the caller, instead of VM, is responsible for doing the
waiting and retrying and whatever to deal with memory allocation failure.
Failing some operation permanently because a kmalloc(GFP_ATOMIC) it did
failed is usually the wrong thing to do.

Again, many people have just the opposite impression.  One person told me
he used GFP_ATOMIC instead of GFP_KERNEL because he needed to be guaranteed
the allocation wouldn't fail.




^ permalink raw reply	[flat|nested] 13+ messages in thread
* GFP_ATOMIC allocations...
@ 2002-08-29  0:25 Doug Ledford
  2002-08-29  0:47 ` Patrick Mansfield
  0 siblings, 1 reply; 13+ messages in thread
From: Doug Ledford @ 2002-08-29  0:25 UTC (permalink / raw)
  To: linux-scsi

I'm looking through some of the new code that has been put in the kernel 
scsi subsystem lately and I'm seeing a few of the same mistakes that the 
old code made.  So, I'm pointing out one of them here.  There are lots of 
places in the SCSI mid layer that are called outside of any spinlocks and 
not from interrupt context where there is absolutely no need to use 
GFP_ATOMIC allocations for memory.  In general, if you don't need to use 
GFP_ATOMIC, then don't use it.  You're more likely to fail the allocation 
and therefore fail the operation.  So, if you are working on a section of 
code, please think about this when doing allocations and do whatever is 
right for the code snippet you are currently hacking.  Fixing places in 
the existing code that use GFP_ATOMIC needlessly is a plus ;-)

-- 
  Doug Ledford <dledford@redhat.com>     919-754-3700 x44233
         Red Hat, Inc. 
         1801 Varsity Dr.
         Raleigh, NC 27606
  

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2002-09-03 16:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-29 15:59 GFP_ATOMIC allocations Bryan Henderson
2002-08-29 16:25 ` Doug Ledford
2002-08-29 16:50 ` Alan Cox
  -- strict thread matches above, loose matches on Subject: below --
2002-08-29  0:25 Doug Ledford
2002-08-29  0:47 ` Patrick Mansfield
2002-08-29  1:42   ` Doug Ledford
2002-08-29 10:47     ` Alan Cox
2002-08-29 15:58       ` Doug Ledford
2002-08-29 17:10     ` Patrick Mansfield
2002-08-30 16:22     ` Patrick Mansfield
2002-08-30 16:46       ` James Bottomley
2002-08-30 18:58         ` Doug Ledford
2002-09-03 16:07       ` Pete Zaitcev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox