Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5816057rwe; Tue, 18 Apr 2023 11:59:36 -0700 (PDT) X-Google-Smtp-Source: AKy350b8Xbhu/Yg3qF7Gqk5zgvI7aMdVeUmP9cSjaH57S1X66OKseBURS59TkUTow8dFfnDl8KNI X-Received: by 2002:a17:902:f7d3:b0:19e:2fb0:a5d9 with SMTP id h19-20020a170902f7d300b0019e2fb0a5d9mr2542275plw.32.1681844376232; Tue, 18 Apr 2023 11:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681844376; cv=none; d=google.com; s=arc-20160816; b=UCv+Oajn5uAyArCse9YCWDiv6HIwKckiGOWvfVAU65K1ALPvN5NCHkse9uRaN/7ykd Bl+NMCCAZtlRsXMStDOAffdfrUtxSqWnpw0DD2YcIUC4xxCpBw0k9N7+dcOj0fgfmK6w Uxt1zpPjRw+mn/dkdCjtSIk6q3xf8f/E+PsEJ35+Od3V/QtpWybhYmLscNRUNkbJ+FwG 7q4JYjyLJWYw9Rz2H4syIjLEhkAIqtih8IEC8yGz0dw6EhSJPUVGAdg5ztDrT1bZNX/K Z46w6HK9LyjKl8lq5StzNGElt/ImUsN2MEVkIbnoC52/h3OMqSFgbYHMXhXbklPoB2cL dQsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BB7vJoU3HrrLNxTi8Xk72x9Aag8/v7/whz+Iy4S1B8Q=; b=IfK+DYKXbg9eusOLvYVsC7Nv6ZsYnrVmL0ubZHnyUW2MgdSKS+IQH/MvNItXtwHdfl 3c0YrgbCOlf9Cv0BmyKu03aaIye5iQGLIdSvLs+yePqzxShXf1Vwb+t9TWqalBrHC9Ke Zsj6J3zjzywvyjhZryADQ0guiGEhSSB3GN0T3KcR0XShm1jLRiVrR+4bHjTkoI0JrTUz A05TrDfqYx24P4gWrh+6W/zV2iW7haRSAVjeaf9LAk5BDpThvirKc4z81PZvjn7Fg1Kb LwLzXqYRLpYgWc47ujKQ4CYu220tX7fQ5Fphf0K05IrRp0vG7UOko3f/6IR5iZPBHQYG 4C+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="LXhFFRg/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4-20020a170902d88400b001a04202f77bsi14256027plz.431.2023.04.18.11.59.21; Tue, 18 Apr 2023 11:59:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="LXhFFRg/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232554AbjDRSrG (ORCPT + 99 others); Tue, 18 Apr 2023 14:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbjDRSrD (ORCPT ); Tue, 18 Apr 2023 14:47:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020FF2694 for ; Tue, 18 Apr 2023 11:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681843580; 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=BB7vJoU3HrrLNxTi8Xk72x9Aag8/v7/whz+Iy4S1B8Q=; b=LXhFFRg/NVCzPkYdOh1yK9Ophktn4fgdMyxYo0QnFRerKYP31w83TpZnNx+yW4fgOo5DK1 IfB1O98ECxqAqBDwig6sX7o6KRaHu+cntczFftZS5+oIGpZRiBfTXzTsbWEHktipd5LkY0 zhqL33YXNCeWUk4lXEkcpl+wbDS34Zw= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-LtQTkdBIO7C4mUIZ7IzFuA-1; Tue, 18 Apr 2023 14:46:18 -0400 X-MC-Unique: LtQTkdBIO7C4mUIZ7IzFuA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3ecd50d9db9so4601141cf.0 for ; Tue, 18 Apr 2023 11:46:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681843578; x=1684435578; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BB7vJoU3HrrLNxTi8Xk72x9Aag8/v7/whz+Iy4S1B8Q=; b=PQk2G6Fu0nVKZgB3rUnzVMxmhAfdUJ5WOyohS+XWQaWPYe/Y8rUivhxnhwMpP7K9QJ 0U0D89DsPBB9Stli9QtkyYyKHVNz95BBATRSMJlUm7R77AQrRcGY4kidplj+RlAv0YaE xUaM0B04a9lX7OruFJ7yWzFMf5g3C49CW1cJsCM7qCtaWIKN96gTEMNfyXg+hx66r12h fkjwAb6VTo/PIfciygDWhzQZD1FZHE5IsvjtCx0ZQnngpDUGW9FJ3aEymzQ7o/KZwb4U CoEWyZh+nA2KgItxbB7WAfRtUkIeCDHk7AgplafWlmOkLEzmkN9tm/6RH75GbeBkTzk8 Ws3w== X-Gm-Message-State: AAQBX9ciSlWmlK3NgtZ6SVcoej+OCC19CPckceE/a8QATm/jFyX7iltW nXcME7BMoKHXuZM1W4+DRtL+NjCwPPpyC6dfTwZ094qCMGVpTGzVrEp43LXjqntSVdkp/uWSuyo XVRuFMc85DsoEnhTFWUXbXCpt X-Received: by 2002:a05:622a:1352:b0:3ef:37fa:e1d6 with SMTP id w18-20020a05622a135200b003ef37fae1d6mr7109281qtk.2.1681843578060; Tue, 18 Apr 2023 11:46:18 -0700 (PDT) X-Received: by 2002:a05:622a:1352:b0:3ef:37fa:e1d6 with SMTP id w18-20020a05622a135200b003ef37fae1d6mr7109253qtk.2.1681843577799; Tue, 18 Apr 2023 11:46:17 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id l5-20020a05620a210500b0074cf009f443sm2553280qkl.85.2023.04.18.11.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 11:46:17 -0700 (PDT) Date: Tue, 18 Apr 2023 14:46:15 -0400 From: Peter Xu To: Suren Baghdasaryan Cc: Matthew Wilcox , akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v2 1/1] mm: do not increment pgfault stats when page fault handler retries Message-ID: References: <20230415000818.1955007-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 18, 2023 at 09:45:52AM -0700, Suren Baghdasaryan wrote: > On Tue, Apr 18, 2023 at 8:48 AM Peter Xu wrote: > > > > On Tue, Apr 18, 2023 at 04:32:27PM +0100, Matthew Wilcox wrote: > > > ... when we called clone()? A thread by definition has a reference to > > > its own mm. > > > > Ah yes.. thanks! > > re: I also had a quick look on do_exit() but I also didn't see where > do we e.g. wait for all the threads to stop before recycles a mm. > > We recycle mm after all refcounts are dropped in the exit path: > do_exit > exit_mm > mmput(if !mm->mm_users) > mmdrop(if !mm->mm_count) > free_mm I assume Matthew means when the task_struct is created with part of kernel_clone(). copy_mm() has: if (clone_flags & CLONE_VM) { mmget(oldmm); mm = oldmm; } else { mm = dup_mm(tsk, current->mm); if (!mm) return -ENOMEM; } If CLONE_VM, we'll mmget() on the existing mm. If !CLONE_VM, we'll just create a new one with reference held. For the latter, I think that hides in mm_init() where it'll just set it to 1: atomic_set(&mm->mm_users, 1); With mm_users>0, do_exit() will leave the mm_struct* alone since mmput() will still be called but not the final step on mmdrop(). Thanks, -- Peter Xu