Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4578160imm; Mon, 30 Jul 2018 18:07:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeR1cH+VX8Orr/FzXPl7Fy88ZVmOKgf7CtwYj2dDCCbO2bIpvyuOdMALYDqSUz1S7InIegl X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr13178362pll.82.1532999245748; Mon, 30 Jul 2018 18:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532999245; cv=none; d=google.com; s=arc-20160816; b=eh77dmcTQfPifyZJL2uHruYun7BZ0bd+khFMOxrh6B7VAsxJX0etjxhfymsFxyG+Ik ABmi6Ta4z02U711/0b2iKS9PwiMztKGeWepi3tVES7xIpdxb+D7QMqD7+PggHNLbfz1X KDJ1m/NUR+qJO96Eud3fu/IeCRF92j4xQDjRFodjv5kshWX7c7iAeHV2I1RdIKdVyibf r5IXTg9rMroCwR4w9ZbVtMVgO0FH4YSqxar7OULfyiQEEEDkhTse+cePwO34VJBVZ4ax 728wkv/xVNFK0ZF3WnP78Tcarxd1ovQLe5JGcfeYeGLY0G4raZ5wpGZeGoPek8vb52At 8q3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to:date :cc:to:from:subject:message-id:arc-authentication-results; bh=bVkqonFH1zDKEtxPyb+D2eeiug3u8WYshYmsYIt1hWM=; b=cLdn/tWRVq0WxufMBeDrsBCBKMc2GYSisV8bC2E6pFaOaTVWkrXud5wAu907DwT7r4 SJZUnzvS1homsJmrW2Pun4JtVLeIluX8GtSntEECxt/Aybn5MAwbUR8NOQUCV8eB0dA7 3YG5OMRMe7mwuPNcHpRWtAw5SPopqDhmuP0ZRlShbi0/2AA8Nr0BVXnHYP2znDg22kbS I/VAKvihOIwsm5Ckf5waeT5fIrSTU0/3q7SozU8Jng7+rg6Y8LnzdyEwSHYB9mq/6X0b yW9ugakn4tIwB30sKDuXq9k6ccPOkFxXaTIzolLZQdnhZ48mTX0fnAfShZe/EOUiy4zy yBTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68-v6si12810554pff.55.2018.07.30.18.07.11; Mon, 30 Jul 2018 18:07:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731831AbeGaCnv (ORCPT + 99 others); Mon, 30 Jul 2018 22:43:51 -0400 Received: from shelob.surriel.com ([96.67.55.147]:50716 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729138AbeGaCnv (ORCPT ); Mon, 30 Jul 2018 22:43:51 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fkJ6p-000106-FK; Mon, 30 Jul 2018 21:05:55 -0400 Message-ID: <1532999155.28585.56.camel@surriel.com> Subject: Re: [PATCH v2 11/11] mm,sched: conditionally skip lazy TLB mm refcounting From: Rik van Riel To: Peter Zijlstra Cc: Andy Lutomirski , LKML , kernel-team , X86 ML , Vitaly Kuznetsov , Ingo Molnar , Mike Galbraith , Dave Hansen , Catalin Marinas , Benjamin Herrenschmidt Date: Mon, 30 Jul 2018 21:05:55 -0400 In-Reply-To: <20180730162653.GM2494@hirez.programming.kicks-ass.net> References: <20180728215357.3249-1-riel@surriel.com> <20180728215357.3249-11-riel@surriel.com> <20180729155452.37eddc11@imladris.surriel.com> <20180730095502.GG2494@hirez.programming.kicks-ass.net> <1532961011.28585.30.camel@surriel.com> <20180730162653.GM2494@hirez.programming.kicks-ass.net> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-E7KE3RR1bBJyyka+rda/" X-Mailer: Evolution 3.26.6 (3.26.6-1.fc27) Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-E7KE3RR1bBJyyka+rda/ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 2018-07-30 at 18:26 +0200, Peter Zijlstra wrote: >=20 > So for ARCH_NO_ACTIVE_MM we never touch ->active_mm and therefore > ->active_mm =3D=3D ->mm. Close, but not true for kernel threads, which have a=20 NULL ->mm, but a non-null ->active_mm that gets passed to enter_lazy_tlb(). I stuck to the structure of your code, but ended up removing all the ifdefs because the final mmdrop requires that we actually keep track of the ->active_mm across potentially several kernel->kernel context switches. Ifdefs around the reference counting code are also not needed, because grab_lazy_mm and drop_lazy_mm already contain the equivalent of an ifdef themselves. By morning I should know what the test results look like. I expect they will be identical to my patches, since the refcounting is disabled completely anyway :) > > + /* > > + * kernel -> kernel lazy + transfer active > > + * user -> kernel lazy + mmgrab() active > > + * > > + * kernel -> user switch + mmdrop() active > > + * user -> user switch > > + */ > > + if (!next->mm) { // to > > kernel > > + enter_lazy_tlb(prev->active_mm, next); > > + >=20 > #ifndef ARCH_NO_ACTIVE_MM > > + next->active_mm =3D prev->active_mm; > > + if (prev->mm) // from > > user > > + mmgrab(prev->active_mm); >=20 > else > prev->active_mm =3D NULL; > > +#endif > > + } else { // to user > > + switch_mm_irqs_off(prev->active_mm, next->mm, > > next); > > + >=20 > #ifndef ARCH_NO_ACTIVE_MM > > + if (!prev->mm) { // from > > kernel > > + /* will mmdrop() in finish_task_switch(). > > */ > > + rq->prev_mm =3D prev->active_mm; > > + prev->active_mm =3D NULL; > > + } > > +#endif >=20 >=20 --=20 All Rights Reversed. --=-E7KE3RR1bBJyyka+rda/ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEKR73pCCtJ5Xj3yADznnekoTE3oMFAltftfMACgkQznnekoTE 3oPq/ggAuz6InKyTy2j2MY+yjCf8dKDUbsE/AYffIZfSRjj2k2SNu6fqx7VPPM4M UmAgECAp3RpBJFB0dH70GFb/dD+j1KLzCfNZA+1Qz+WZ7DdeylZcujos9Lph7nMw fD1MQFxO9bk+zt1XuVCChnNx1FphE2GVauZMDWRRYgs5oehegesRwQ5MC4HWhNe1 AqhqSIg+FZx5EZo1vQmsBHPIS2ygMXHx8+6vQ84o1D+QNEDuMesmQmzWMozNZYak ar13GRAvo9+J41WMeaqq0zGh+jHBmzGwKYlMHkCwiN/79IDiodAscIJ+H8EUQY9v CxN+UM5kRBGsHW0Y4HY0nnTs04Jt/Q== =hkbD -----END PGP SIGNATURE----- --=-E7KE3RR1bBJyyka+rda/--