linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Error in freeing memory with zone reclaimable always returning true.
@ 2017-06-26  7:29 Ivid Suvarna
  2017-06-26  8:00 ` Michal Hocko
  0 siblings, 1 reply; 6+ messages in thread
From: Ivid Suvarna @ 2017-06-26  7:29 UTC (permalink / raw)
  To: linux-mm

[-- Attachment #1: Type: text/plain, Size: 2306 bytes --]

Hi,

I have below code which tries to free memory,
do
{
free=shrink_all_memory;
}while(free>0);

But kernel gets into infinite loop because shrink_all_memory always returns
1.
When I added some debug statements to `mm/vmscan.c` and found that it is
because zone_reclaimable() is always true in shrink_zones()

if (global_reclaim(sc) &&
            !reclaimable && zone_reclaimable(zone))
            reclaimable = true;

This issue gets solved by removing the above lines.
I am using linux-kernel 4.4 and imx board.

Similar Issue is seen here[1]. And it is solved through a patch removing
the offending lines. But it does not explain why the zone reclaimable goes
into infinite loop and what causes it? And I ran the C program from [1]
which is below. And instead of OOM it went on to infinite loop.

#include <stdlib.h>
#include <string.h>

int main(void)
{
for (;;) {
void *p = malloc(1024 * 1024);
memset(p, 0, 1024 * 1024);
}
}

Also can this issue be related to memcg as in here "
https://lwn.net/Articles/508923/" because I see the code flow in my case
enters:

if(nr_soft_reclaimed)
reclaimable=true;

I dont understand memcg correctly. But in my case CONFIG_MEMCG is not set.

After some more debugging, I found a userspace process in sleeping state
and has three threads. This process is in pause state through
system_pause() and is accessing shared memory(`/dev/shm`) which is created
with 100m size. This shared memory has some files.

Also this process has some anonymous private and shared mappings when I saw
the output of `pmap -d PID` and there is no swap space in the system.

I found that this hang situation was not present after I remove that
userspace process. But how can that be a solution since kernel should be
able to handle any exception.

"I found no issues at all if I removed this userspace process".

So my doubts are:

 1. How can this sleeping process in pause state cause issue in zone
reclaimable returning true always.

 2. How are the pages reclaimed from sleeping process which is using shared
memory in linux?

 3. I tried to unmount /dev/shm but was not possible since process was
using it. Can we release shared memory by any way? I tried `munmap` but no
use.

Any info would be helpful.

  [1]: https://groups.google.com/forum/#!topic/fa.linux.kernel/kWwlQzj8mhc

[-- Attachment #2: Type: text/html, Size: 2883 bytes --]

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

end of thread, other threads:[~2017-06-27  5:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-26  7:29 Error in freeing memory with zone reclaimable always returning true Ivid Suvarna
2017-06-26  8:00 ` Michal Hocko
2017-06-26 13:04   ` Ivid Suvarna
2017-06-26 14:27     ` Michal Hocko
2017-06-27  4:38       ` Ivid Suvarna
2017-06-27  5:14         ` Michal Hocko

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