Re: [PATCH] mm: Free per cpu pages async to shorten program exit time

From: Claudio Imbrenda
Date: Fri Oct 08 2021 - 08:55:18 EST


On Fri, 8 Oct 2021 14:38:15 +0200
Vlastimil Babka <vbabka@xxxxxxx> wrote:

> On 10/8/21 10:17, David Hildenbrand wrote:
> > On 08.10.21 08:39, ultrachin@xxxxxxx wrote:
> >> From: chen xiaoguang <xiaoggchen@xxxxxxxxxxx>
> >>
> >> The exit time is long when program allocated big memory and
> >> the most time consuming part is free memory which takes 99.9%
> >> of the total exit time. By using async free we can save 25% of
> >> exit time.
> >>
> >> Signed-off-by: chen xiaoguang <xiaoggchen@xxxxxxxxxxx>
> >> Signed-off-by: zeng jingxiang <linuszeng@xxxxxxxxxxx>
> >> Signed-off-by: lu yihui <yihuilu@xxxxxxxxxxx>
> >
> > I recently discussed with Claudio if it would be possible to tear down the
> > process MM deferred, because for some use cases (secure/encrypted
> > virtualization, very large mmaps) tearing down the page tables is already
> > the much more expensive operation.
>
> OK, but what exactly is the benefit here? The cpu time will have to be spent
> in any case, but we move it to a context that's not accounted to the exiting
> process. Is that good? Also if it's a large process and restarts
> immediately, allocating all the memory back again, it might not be available
> as it's still being freed in the background, leading to a risk of OOM?

I argue that it is good, at least in some cases.

Depending on the type of process shutting down, restarting it
immediately might still be slow enough that no OOM condition will
arise.

and those are the reasons of the per-arch hook to determine when it
makes sense to do things asynchronously.

>
> > There is mmdrop_async(), and I wondered if one could reuse that concept when
> > tearing down a process -- I didn't look into feasibility, however, so it's
> > just some very rough idea.
> >