Re: Out of memory vs memory leak

2010-01-08 Thread Mulyadi Santosa
Hi...

I saw that others had replied your questions with good answers, so
probably I just add something...

On Thu, Jan 7, 2010 at 10:04 PM, Anand Raj Manickam  wrote:
> I have a few doubts regarding Out of Memory  .
>
> 1.Does memory leak in the kernel always lead to OOM ?

sooner or later yes. And kernel won't get OOM-ed...it will simply
continously leaking if the code is buggy until it stop by itself. Or
the kernel no longer has free memory pages available from all zones. I
think, in the worst case scenario, it will silently crash the kernel.

> 2. I wrote a kernel  test module testing the memory leak , which on
> exit kmallocs
>
> exit_module ()
> {
>   while(1)
>   kmalloc((8*1024),GFP_KERNEL);
> }
>
> so when i rmmod test , the kernel never panicked on OOM , but it
> panicked on the page allocation stat (sorry for not attaching the
> dump)

sorry, what do you mean by "page allocation stat"?

> Does the kernel differentiate between a Memory Leak and a Out of
> memory situation ?

IMHO it's not about whether we see it from kernel or user space
perspective. It's about each of their meaning.

Memory leak is a condition where allocation happens but reclaim
doesn't happen at the same amount of allocation, thus there is an
(growing) amount of stale memory.

While OOM refers to a condition where allocator no longer able to find
and assign free memory page for the requester, whether it comes from
free directly memory pool or by previously flush page cache.

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: Out of memory vs memory leak

2010-01-08 Thread Manish Katiyar
On Thu, Jan 7, 2010 at 8:34 PM, Anand Raj Manickam  wrote:
> I have a few doubts regarding Out of Memory  .
>
> 1.Does memory leak in the kernel always lead to OOM ?
>
> 2. I wrote a kernel  test module testing the memory leak , which on
> exit kmallocs
>
> exit_module ()
> {
>   while(1)
>   kmalloc((8*1024),GFP_KERNEL);
> }
>
> so when i rmmod test , the kernel never panicked on OOM , but it
> panicked on the page allocation stat (sorry for not attaching the
> dump)
> Does the kernel differentiate between a Memory Leak and a Out of
> memory situation ?

You don't panic immediately. Memory leaks eventually leads to out of
memory because the memory manager has given all the memory to someone
and hasn't got back (leaked !!). So if a new requestor comes he
doesn't have anything to allocate and you get out of memory.

Thanks -
Manish

>
> Google didnt help me in the releation between memory leak and OOM .
>
> Thanks,
> Anand
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecar...@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Thanks -
Manish
==
[$\*.^ -- I miss being one of them
==

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: Out of memory vs memory leak

2010-01-08 Thread Bernd Petrovitsch
On Don, 2010-01-07 at 20:34 +0530, Anand Raj Manickam wrote:
> I have a few doubts regarding Out of Memory  .
> 
> 1.Does memory leak in the kernel always lead to OOM ?
If the leaking code is occasionally used, it's just a question of time.

> 2. I wrote a kernel  test module testing the memory leak , which on
> exit kmallocs
> 
> exit_module ()
> {
>while(1)
>kmalloc((8*1024),GFP_KERNEL);
> }
> 
> so when i rmmod test , the kernel never panicked on OOM , but it
> panicked on the page allocation stat (sorry for not attaching the
> dump)
Here you have the out-of-memory situation.

> Does the kernel differentiate between a Memory Leak and a Out of
> memory situation ?
> 
> Google didnt help me in the releation between memory leak and OOM .
OOM (as used above) usually occurs if the userspace runs out of memory
(or one process or ...).
Memory management within the kernel is somewhat different because: If a
user process hits memory limits (or the systems memory runs out), that
process can (usually) be killed - just like a `kill -9` from user space
-  and it's resources are freed. And the kernel can do this as he knows
everything of a user space process.
If kmalloc() in some kernel module (or core code) fails, that module
must cleanup and/or decide what to do (or the host will eventually
panic) - and such a module is plain simply buggy BTW.
Possible actions are e.g. failing sys-calls or the like.

Bernd
-- 
mobil: +43 664 4416156  http://bernd.petrovitsch.priv.at/
Linux Software Entwicklung, Beratung und Dienstleistungen


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Re: Out of memory vs memory leak

2010-01-08 Thread Anand Raj Manickam
I have a few doubts regarding Out of Memory  .

1.Does memory leak in the kernel always lead to OOM ?

2. I wrote a kernel  test module testing the memory leak , which on
exit kmallocs

exit_module ()
{
  while(1)
  kmalloc((8*1024),GFP_KERNEL);
}

so when i rmmod test , the kernel never panicked on OOM , but it
panicked on the page allocation stat (sorry for not attaching the
dump)
Does the kernel differentiate between a Memory Leak and a Out of
memory situation ?

Google didnt help me in the releation between memory leak and OOM .

Thanks,
Anand

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ



Out of memory vs memory leak

2010-01-08 Thread Anand Raj Manickam
I have a few doubts regarding Out of Memory  .

1.Does memory leak in the kernel always lead to OOM ?

2. I wrote a kernel  test module testing the memory leak , which on
exit kmallocs

exit_module ()
{
   while(1)
   kmalloc((8*1024),GFP_KERNEL);
}

so when i rmmod test , the kernel never panicked on OOM , but it
panicked on the page allocation stat (sorry for not attaching the
dump)
Does the kernel differentiate between a Memory Leak and a Out of
memory situation ?

Google didnt help me in the releation between memory leak and OOM .

Thanks,
Anand

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ