<div dir="ltr"><div><div><div>Hi,<br><br>I have below code which tries to free memory, <br>do<br>{<br>free=shrink_all_memory;<br>}while(free>0);<br><br><div>But kernel gets into infinite loop because shrink_all_memory always returns 1.<br>When
I added some debug statements to `mm/vmscan.c` and found that it is
because zone_reclaimable() is always true in shrink_zones()<br><br>if (global_reclaim(sc) &&<br> !reclaimable && zone_reclaimable(zone))<br> reclaimable = true;<br><br>This issue gets solved by removing the above lines. <br>I am using linux-kernel 4.4 and imx board.<br><br>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.<br><br>#include <stdlib.h> <br> #include <string.h> <br> <br> int main(void) <br> { <br> for (;;) { <br> void *p = malloc(1024 * 1024); <br> memset(p, 0, 1024 * 1024); <br> } <br> } <br><br>Also can this issue be related to memcg as in here "<a target="_blank" href="https://lwn.net/Articles/508923/">https://lwn.net/Articles/<wbr>508923/</a>" because I see the code flow in my case enters:<br><br>if(nr_soft_reclaimed)<br></div><div>reclaimable=true;<br><br></div><div>I dont understand memcg correctly. But in my case CONFIG_MEMCG is not set.<br></div><br>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. <br><br>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.<br><br>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.<br><br>"I found no issues at all if I removed this userspace process".<br><br>So my doubts are:<br><br> 1. How can this sleeping process in pause state cause issue in zone reclaimable returning true always.<br><br> 2. How are the pages reclaimed from sleeping process which is using shared memory in linux?<br><br> 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.<br><br>Any info would be helpful.<br><br> [1]: <a target="_blank" href="https://groups.google.com/forum/#%21topic/fa.linux.kernel/kWwlQzj8mhc">https://groups.google.com/<wbr>forum/#!topic/fa.linux.kernel/<wbr>kWwlQzj8mhc</a><br></div><br></div>Regards,<br></div>Ivid<br></div>