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 515F6C433F5 for ; Fri, 8 Oct 2021 09:24:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DC14060F70 for ; Fri, 8 Oct 2021 09:24:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC14060F70 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 7FD4B940007; Fri, 8 Oct 2021 05:24:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AD226B0072; Fri, 8 Oct 2021 05:24:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69C55940007; Fri, 8 Oct 2021 05:24:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 5C8376B0071 for ; Fri, 8 Oct 2021 05:24:20 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1631C181BC828 for ; Fri, 8 Oct 2021 09:24:20 +0000 (UTC) X-FDA: 78672734280.19.6B6C386 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 6C2D8F002844 for ; Fri, 8 Oct 2021 09:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633685058; 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=N+kW7TpfSE1zTehVurPmFNQOjEaRU+dQabqRIwbQUzc=; b=WoFdTAxUTBD9ylW06GTUgQcvUwkqDfd1BEfw4gEq38Iaswkfp1FdEk1Xy/vlgojtgwsLWp JxLyPKW4aegGyBD6qtMibNLPhZtJBgTpbLZfIh4cDkzwhZEw1ITPA1hlKIg6Ng7PDr9jzz 1/h4jZ2cCC/wMT3EhUOTYrNxeX0evOc= 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-22-ZHbM2pIGMaqBaQGEZXWDYw-1; Fri, 08 Oct 2021 05:24:17 -0400 X-MC-Unique: ZHbM2pIGMaqBaQGEZXWDYw-1 Received: by mail-wr1-f72.google.com with SMTP id k2-20020adfc702000000b0016006b2da9bso6813606wrg.1 for ; Fri, 08 Oct 2021 02:24:17 -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=N+kW7TpfSE1zTehVurPmFNQOjEaRU+dQabqRIwbQUzc=; b=oy//ycnVE/Pt+XUfh0dVqr9kIhfbcnmZdnsJLUWzp34l29tYdCdRYNKF/2qIXWTLHn UImD/PA77K9D0kP+xofsRS05PsbKX1xZc9L04xJkC0MQV3VrQW6vUPbPCOUoD2WMUQVm BdAlVVDF+LA+AeDXhjVqNADZpKIXKr002yj9DDBcqVOMYAARtca/VelXj1co9As1+QVT ZmC8/JhhWJHf/uenP3pymOY69FJFQjz5rSn3tgR+y5vAuJOqUCbeW/eHb60YhKrD+PIH ETX49Lg1rN2P6KnvbttK7u9DsDWB8+Nb/JbTX0kmsFLHseEqYtJKA+DneiMHbnHoe8Lh 48tA== X-Gm-Message-State: AOAM5327FODfLIte/fmSISbVzOSXfbx8mq5Tii26IK9mol3EIWxit++N sos4UI9Mnvjlc4eSBDHlX4Uxm0zrLH453Ky7sxyHYlxsiLNBeqsg2eatsAO+6nFskFERKeuppO5 8xoKsyglQIQk= X-Received: by 2002:a1c:4d1a:: with SMTP id o26mr2298822wmh.54.1633685056650; Fri, 08 Oct 2021 02:24:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxTA+QFvTcIBel/SjddnSuNDNoKaQyKaFRG1G4Mady2kot1oW0ZmqSNs9wJN/r9Kfal5z+cA== X-Received: by 2002:a1c:4d1a:: with SMTP id o26mr2298796wmh.54.1633685056414; Fri, 08 Oct 2021 02:24:16 -0700 (PDT) Received: from [192.168.3.132] (p5b0c676e.dip0.t-ipconnect.de. [91.12.103.110]) by smtp.gmail.com with ESMTPSA id n68sm11151469wmn.13.2021.10.08.02.24.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Oct 2021 02:24:16 -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> <1db11d75-d2d8-ef71-471a-ddad5c90a733@redhat.com> <20211008112235.1d37f2db@p-imbrenda> From: David Hildenbrand Organization: Red Hat Message-ID: Date: Fri, 8 Oct 2021 11:24:14 +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: <20211008112235.1d37f2db@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 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WoFdTAxU; spf=none (imf11.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6C2D8F002844 X-Stat-Signature: x1ushqftdj5956tpzn6zwbgxstmmruhd X-HE-Tag: 1633685059-490605 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 11:22, Claudio Imbrenda wrote: > On Fri, 8 Oct 2021 11:15:25 +0200 > David Hildenbrand wrote: > >> 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. >> > > yes, that is one of the possible solutions I had thought of. > > although probably the small patch I posted above is even less intrusive > and should hopefully raise even fewer eyebrows, while also leaving the > door open to arch-specific code to do more than just mmput_async, if > needed. More flexibility might raise more eyebrows. :) -- Thanks, David / dhildenb