From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBA49C433EF for ; Fri, 8 Oct 2021 09:15:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 583AC6101E for ; Fri, 8 Oct 2021 09:15:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 583AC6101E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E49026B0071; Fri, 8 Oct 2021 05:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF844900002; Fri, 8 Oct 2021 05:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE6CE6B0073; Fri, 8 Oct 2021 05:15:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id BE71C6B0071 for ; Fri, 8 Oct 2021 05:15:40 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 71D5239F25 for ; Fri, 8 Oct 2021 09:15:40 +0000 (UTC) X-FDA: 78672712440.02.8DFBA0E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 1CEC95077C59 for ; Fri, 8 Oct 2021 09:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633684539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h0m6F+5zadgowouPrrExZ1kaPYuwRnHxBe9uh7+Mk/A=; b=Fge/KvtxQ3SGwXJ7wu7ULr8vnNxqM50cT1x+uxSwAkr0fPCBxHmchJ45mYAjJPoJxwt/av m9eh7xv5Eb8hKn4Z5J51XDyfTIPtW7RmCtrx79I4BpA9yrbV6eryl7/+ohCzUs8JU5cIq4 wPToolH4eSNUbXvmNDgaIQE1wWRMfYo= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-p66ZEMyiP3muAW86HN3fjw-1; Fri, 08 Oct 2021 05:15:28 -0400 X-MC-Unique: p66ZEMyiP3muAW86HN3fjw-1 Received: by mail-wr1-f72.google.com with SMTP id y12-20020a056000168c00b00160da4de2c7so3711693wrd.5 for ; Fri, 08 Oct 2021 02:15:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=h0m6F+5zadgowouPrrExZ1kaPYuwRnHxBe9uh7+Mk/A=; b=YrZNlnmdE0Y0imevnEk+mVQPbqqIAk8Z6wpJKf+2ocDwl99OJatE3sPIlmKtCdNTaZ Rfu4n38FvldIZQMDoGLYgxlAtencWG24A3PdTzYYWEY6VBMFj71Brt2ylH9ea9hj+rUK J/5oY3DXxB/mKjAUfOPFtEu5Cq+U9vQKlqkK1tOL/SveGyfyFciPBKERF22hQRyRq0nT 3t6vdItKO5HrLgEMQVV/OhzRU3D/pBjR2OpxwhSAPC2XkNTD3aN8nK+aogobdboSHbCs 4YMA/9mernxQK9NVMmFWevHFApklV6ebrDSwJquOgZPtJoqPPpegi6UEtHoynOAUiWFU uI1g== X-Gm-Message-State: AOAM531q0YVqK3EDNU8x9MBc5yXKD5s97XR+da3OqxF08W1scZ8Ii6hc ViG8AioUgAT4yZknnL10AO+oz5kLDlQXM2TJuHQ530uMJ5mNzemvvaTxP8MOzm88EUqjPd6DjTy Bj2kriQqFcXQ= X-Received: by 2002:adf:bb49:: with SMTP id x9mr2494946wrg.413.1633684527150; Fri, 08 Oct 2021 02:15:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhjA72Z1ecXLKtLAZyfPsXgHBVALcs7blHK+2or3JE8vZJ+3NQO1m7NUe/Dr5DdGK+hGCqCQ== X-Received: by 2002:adf:bb49:: with SMTP id x9mr2494918wrg.413.1633684526901; Fri, 08 Oct 2021 02:15:26 -0700 (PDT) Received: from [192.168.3.132] (p5b0c676e.dip0.t-ipconnect.de. [91.12.103.110]) by smtp.gmail.com with ESMTPSA id u24sm10586859wmj.48.2021.10.08.02.15.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Oct 2021 02:15:26 -0700 (PDT) Subject: Re: [PATCH] mm: Free per cpu pages async to shorten program exit time To: Claudio Imbrenda Cc: ultrachin@163.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, brookxu.cn@gmail.com, chen xiaoguang , zeng jingxiang , lu yihui References: <20211008063933.331989-1-ultrachin@163.com> <20211008105205.07d2f205@p-imbrenda> From: David Hildenbrand Organization: Red Hat Message-ID: <1db11d75-d2d8-ef71-471a-ddad5c90a733@redhat.com> Date: Fri, 8 Oct 2021 11:15:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20211008105205.07d2f205@p-imbrenda> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1CEC95077C59 X-Stat-Signature: hmap3ytiffjrx1qwm491fgibpt7ucpfn Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Fge/Kvtx"; spf=none (imf05.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1633684539-281871 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 08.10.21 10:52, Claudio Imbrenda wrote: > On Fri, 8 Oct 2021 10:17:50 +0200 > David Hildenbrand wrote: > >> On 08.10.21 08:39, ultrachin@163.com wrote: >>> From: chen xiaoguang >>> >>> 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 >>> Signed-off-by: zeng jingxiang >>> Signed-off-by: lu yihui >> >> 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. >> >> 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. > > I have done some experiments by unconditionally replacing mmdrop with > mmdrop_async in exit.c and nothing broke, and exit time of large > processes was almost instant (with the actual cleanup being performed in > background) > > my approach is probably simpler/cleaner: > > diff --git a/include/asm-generic/mmu_context.h b/include/asm-generic/mmu_context.h > index 91727065bacb..900931a6a105 100644 > --- a/include/asm-generic/mmu_context.h > +++ b/include/asm-generic/mmu_context.h > @@ -73,4 +73,8 @@ static inline void deactivate_mm(struct task_struct *tsk, > } > #endif > > +#ifndef arch_exit_mm_mmput > +#define arch_exit_mm_mmput mmput > +#endif > + > #endif /* __ASM_GENERIC_MMU_CONTEXT_H */ > diff --git a/kernel/exit.c b/kernel/exit.c > index 9a89e7f36acb..604cb9c740fa 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -498,7 +498,7 @@ static void exit_mm(void) > task_unlock(current); > mmap_read_unlock(mm); > mm_update_next_owner(mm); > - mmput(mm); > + arch_exit_mm_mmput(mm); > if (test_thread_flag(TIF_MEMDIE)) > exit_oom_victim(); > } > > these are the minimal changes to common code, then each architecture can > define their own arch_exit_mm_mmput as they see fit (for example, to free > asynchronously only for certain classes of mm, like big ones, VMs, or so). > > Another option is to simply always replace mmput with mmput_async, which I > expect will raise more eyebrows. Thanks Claudio. I guess we'd use some heuristic to keep the eyebrows down. Having something like if (should_mput_async_on_exit(mm)) mmput_async(mm); else mmput(mm); whereby the heuristic can optionally consult the arch/config-knobs/... doesn't sound too wrong to me if it works. -- Thanks, David / dhildenb