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 X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AF58C48BDF for ; Mon, 14 Jun 2021 00:45:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A38E661378 for ; Mon, 14 Jun 2021 00:45:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A38E661378 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F29B16B0036; Sun, 13 Jun 2021 20:45:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED8466B006E; Sun, 13 Jun 2021 20:45:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D53186B0070; Sun, 13 Jun 2021 20:45:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id A2B5E6B0036 for ; Sun, 13 Jun 2021 20:45:29 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2E2BB181AEF0B for ; Mon, 14 Jun 2021 00:45:29 +0000 (UTC) X-FDA: 78250485978.35.CC13AD2 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf24.hostedemail.com (Postfix) with ESMTP id D33F0A0001CF for ; Mon, 14 Jun 2021 00:45:20 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id q15so7282978pgg.12 for ; Sun, 13 Jun 2021 17:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=XxuG7Ca+3NTnEr0aQpNCozkotiEBll347Hs/ZeeBTEE=; b=mm2A1acBjDH7g2IowT4ikVA0PGuvvUKAqKzu0e1WiA7lFyUa/IlSllbZTfUlcwYGgI SwY2xIh2GjsYJSZkx8ezsCjaRxCJeKFP0aBwLHlECyiXyLU3CQsShC9mUFO88Jo2GW7j jHkGQsMV153/u1T9xp86sMn5EyV+97RBdP+HkwVmjTTcpG7/AwiY6g0VhXL00nWz6Ikz E6UhlEfr1QOet/Kb36AM9BRuYqt4j0SORqJJ4Ja0XHE13zOobYtwVo2w1hZS7ifKGRQG jrIlNZOrfeETCuB9HlDjdKurGlFn369VV65lIgM1JiNWrQ3vmKG7pG6rg48DFQu3FPjt wAkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=XxuG7Ca+3NTnEr0aQpNCozkotiEBll347Hs/ZeeBTEE=; b=bhtGrLxRYiV9jhdYTRvphRk8zY45s8abQsTZ2OPeYUSE7TYRXoiKgwUDEee3K+huwG Tf6pM2/i4d/4Lkl6RHMTEyykcOASA4qiVognWxp4p0aHz5+hB6dxk20Ygq303xoAU79m iI/s7+3OwxAcjraKyqR3GfDvvKidH1QyvbMwpfZVFWxGFBpbipcbRbx94B6HuQif+taG xigBbH1I63LOb4lR/le8pgx6nn9E87bxdnSMKYC6riQ/xOd9vn0ts3aNSC6+DM6Jjpbj 59IeYsLEUDLpdhVhmcGlS2hz6ClDQY676S+JCcFRLpDj2Rj7JU3Eu4hE4BGtGULGgwER QHLg== X-Gm-Message-State: AOAM5338awQNuwj2pREtbmSTPCJ4uK4ks0388WqFshm7MMgm90espsjT ngOe+XM2j8XeGhVOGZr9TlU= X-Google-Smtp-Source: ABdhPJx0cMBzdEpBTdoXhdRfERuKep5LD+E6eqItgLbvkLf7+nCitT8/U5nRSCNsZiXV0o1/PEHbmw== X-Received: by 2002:a62:bd14:0:b029:2de:8bf7:2df8 with SMTP id a20-20020a62bd140000b02902de8bf72df8mr19268697pff.60.1623631527972; Sun, 13 Jun 2021 17:45:27 -0700 (PDT) Received: from localhost (60-242-147-73.tpgi.com.au. [60.242.147.73]) by smtp.gmail.com with ESMTPSA id em22sm2575307pjb.27.2021.06.13.17.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Jun 2021 17:45:27 -0700 (PDT) Date: Mon, 14 Jun 2021 10:45:22 +1000 From: Nicholas Piggin Subject: Re: [PATCH v4 2/4] lazy tlb: allow lazy tlb mm refcounting to be configurable To: Andrew Morton , Andy Lutomirski Cc: Anton Blanchard , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, Randy Dunlap , Linus Torvalds References: <20210605014216.446867-1-npiggin@gmail.com> <20210605014216.446867-3-npiggin@gmail.com> <8ac1d420-b861-f586-bacf-8c3949e9b5c4@kernel.org> In-Reply-To: <8ac1d420-b861-f586-bacf-8c3949e9b5c4@kernel.org> MIME-Version: 1.0 Message-Id: <1623629185.fxzl5xdab6.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=mm2A1acB; spf=pass (imf24.hostedemail.com: domain of npiggin@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: ba3yqz8aqre36kn99r6cer3wwhm43nmx X-Rspamd-Queue-Id: D33F0A0001CF X-Rspamd-Server: rspam06 X-HE-Tag: 1623631520-483161 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: Excerpts from Andy Lutomirski's message of June 9, 2021 2:20 am: > On 6/4/21 6:42 PM, Nicholas Piggin wrote: >> Add CONFIG_MMU_TLB_REFCOUNT which enables refcounting of the lazy tlb mm >> when it is context switched. This can be disabled by architectures that >> don't require this refcounting if they clean up lazy tlb mms when the >> last refcount is dropped. Currently this is always enabled, which is >> what existing code does, so the patch is effectively a no-op. >>=20 >> Rename rq->prev_mm to rq->prev_lazy_mm, because that's what it is. >=20 > I am in favor of this approach, but I would be a lot more comfortable > with the resulting code if task->active_mm were at least better > documented and possibly even guarded by ifdefs. active_mm is fairly well documented in Documentation/active_mm.rst IMO. I don't think anything has changed in 20 years, I don't know what more is needed, but if you can add to documentation that would be nice. Maybe moving a bit of that into .c and .h files? > x86 bare metal currently does not need the core lazy mm refcounting, and > x86 bare metal *also* does not need ->active_mm. Under the x86 scheme, > if lazy mm refcounting were configured out, ->active_mm could become a > dangling pointer, and this makes me extremely uncomfortable. >=20 > So I tend to think that, depending on config, the core code should > either keep ->active_mm [1] alive or get rid of it entirely. I don't actually know what you mean. core code needs the concept of an "active_mm". This is the mm that your=20 kernel threads are using, even in the unmerged CONFIG_LAZY_TLB=3Dn patch, active_mm still points to init_mm for kernel threads. We could hide that idea behind an active_mm() function that would always=20 return &init_mm if mm=3D=3DNULL, but you still have the concept of an activ= e mm and a pointer that callers must not access after free (because some cases will be CONFIG_LAZY_TLB=3Dy). > [1] I don't really think it belongs in task_struct at all. It's not a > property of the task. It's the *per-cpu* mm that the core code is > keeping alive for lazy purposes. How about consolidating it with the > copy in rq? I agree it's conceptually a per-cpu property. I don't know why it was=20 done this way, maybe it was just convenient and works well for mm and=20 active_mm to be adjacent. Linus might have a better insight. > I guess the short summary of my opinion is that I like making this > configurable, but I do not like the state of the code. I don't think I'd object to moving active_mm to rq and converting all usages to active_mm() while we're there, it would make things a bit more configurable. But I don't see it making core code fundamentally less complex... if you're referring to the x86 mm switching monstrosity, then that's understandable, but I admit I haven't spent enough time looking at it to make a useful comment. A patch would be enlightening, I have the leftover CONFIG_LAZY_TLB=3Dn patch if you were thinking of=20 building on that I can send it to you. Thanks, Nick