Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp2174950pxb; Fri, 8 Oct 2021 02:26:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRkqFBbZ83VCkF7/BJ+jDKs6GVvqZxNi5T9Yd8rrl88lbfXFHgVZ882gKcSgB2mCsj04Vt X-Received: by 2002:a17:90a:af93:: with SMTP id w19mr11316554pjq.10.1633685160982; Fri, 08 Oct 2021 02:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633685160; cv=none; d=google.com; s=arc-20160816; b=FW5xV4Bu/pciAr+W35Wd/os68przL1jr9DWC64m/wUayOMZQYG+LEvaNt+Xqbv3MTi cJP2eY/41ttVGtw7eqFWQWHL6Z3pm5OnxWfN7iOYZQVW4YsHQl3rIWeZlHCbkvEJh/CB Yi3aRCvpCKmsHeITNJsrH0irVI6jrS4mD2DeB4jqaiMmfEn+JW7Pb8+rYbED3v3ArOig xUveJpJOEgZrZKhhboEpMQrB+VaK/dZJ3jSTwpEGb5iRF3aKQ1fRnAblxWDIX09/VSrX YcKFvZFR6sEC6F70rpbRFNBn3BXOaL+AicbmhiOliYDJbfCVFBXk5bE5FKmtSnL4HDlw VApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=N+kW7TpfSE1zTehVurPmFNQOjEaRU+dQabqRIwbQUzc=; b=P4Kl3fUjJq4MbDoQlJJSYQzgQy7uN6XP+JH19QgWVIFZzeZW79lUmg7h7IKDfw/pBB xBkzwaVON+1UlLuIjam0Qniqk7UpqelnRauGuWOPc6uznvkjjfhJQQDZGIoTyjwQwmX9 z9I1EvqQXSEAUKgizGWzoDuwAYdbIFBOIayof2wRHDTVarjYTpVSEC98BEFYIexujPs2 yljQegwA65aHKViOkkhlCBqvYquuh60C3cSvnwwkvXaj35o4OTmsdajwzGPZtX5x5lga jKOs6UmpG7hLwN26lmPH8O+6amyT8nrSshvztIZv8oMiroCYb4lRDHkaX3jvsHhpJnOD wBJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WoFdTAxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si2404988plp.424.2021.10.08.02.25.47; Fri, 08 Oct 2021 02:26:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WoFdTAxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238070AbhJHJ0O (ORCPT + 99 others); Fri, 8 Oct 2021 05:26:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41141 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236335AbhJHJ0O (ORCPT ); Fri, 8 Oct 2021 05:26:14 -0400 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-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-WYJ3kBb4MeKd2X-kwgjbBw-1; Fri, 08 Oct 2021 05:24:17 -0400 X-MC-Unique: WYJ3kBb4MeKd2X-kwgjbBw-1 Received: by mail-wr1-f71.google.com with SMTP id c4-20020a5d6cc4000000b00160edc8bb28so1025640wrc.9 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=fqEhlgs08Hl6vp8mjqpGG1wBXGXBeN8qmxZO+1fI+qh0EFt34IaEwAITST9LdwjJh8 rlZgWvvjvcURF8aVK5tuMdAHG5qUNqIHBBfhkN8tMA5TcBkULylVZO9mYlvpSphdEdyS zWtnxjMqz7TXcGig4bTSou/sHIU4/E+Qg1bmIgvREI5HrsEDI7tgs6866lJLVLVRnmDY oBSx718xaeI2UKpnySaZYoln+BVkLkLGkz6gsZ0P84lyf15zQCtZDthq+IAraLA5Lgkv aK8icwKTbtJMRHke8pinuga/T/diOVoI/fYx0u623CfCObU2VVBfFE+PXj4dFe/ovZBM jU4w== X-Gm-Message-State: AOAM5330BYAkqEee6WzAYtkOBlIei/OMTbvaX6O2O1BTu7R4dQRUUhul EkhJAt1kGZTwC2PRaJv2/Z7ITGnv9TsJnw6g57dvsbCXLzEnvfE1nPYtLPiWi/Gmp9f4W8Myv1W hHsc5IeRauci/RjaC1nYmfGg0 X-Received: by 2002:a1c:4d1a:: with SMTP id o26mr2298814wmh.54.1633685056597; Fri, 08 Oct 2021 02:24:16 -0700 (PDT) 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> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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