On Wed, Aug 7, 2024 at 4:38 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote: > > On Thu, 1 Aug 2024 14:30:52 +0800 zhiguojiang <justinjiang@xxxxxxxx> wrote: > > > > Dumb question: why can't this be done in userspace? The exiting > > > process does fork/exit and lets the child do all this asynchronous freeing? > > The logic optimization for kernel releasing swap entries cannot be > > implemented in userspace. The multiple exiting processes here own > > their independent mm, rather than parent and child processes share the > > same mm. Therefore, when the kernel executes multiple exiting process > > simultaneously, they will definitely occupy multiple CPU core resources > > to complete it. > > What I'm asking is why not change those userspace processes so that they > fork off a child process which shares the MM (shared mm_struct) and > then the original process exits, leaving the asynchronously-running > child to clean up the MM resources. Not Zhiguo. From my perspective as a phone engineer, this issue isn't related to the parent-child process or the wait() function. Phones rely heavily on mechanisms similar to the OOM killer to function efficiently. For instance, if you're using apps like YouTube, TikTok, and Facebook, and then you open the camera app to take a photo, the camera app becomes the foreground process and demands a lot of memory. In this scenario, the phone might decide to terminate the most memory-consuming and less important apps, such as TikTok or YouTube, to free up memory for the camera app. TikTok and YouTube become less important because they are no longer occupying the phone's screen and have moved to the background. The faster TikTok and YouTube can be unmapped, the quicker the camera app can launch, enhancing the user experience. An important reason why apps can launch very slowly is due to the time latency of alloc_pages(). That's why I'm quite interested in Zhiguo's patchset. On the other hand, mTHP can help alleviate the situation by releasing swap slots three times faster in my other patch: https://lore.kernel.org/linux-mm/20240806012409.61962-1-21cnbao@xxxxxxxxx/ This is likely another advantage of mTHP. Thanks Barry