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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99D88C433F5 for ; Sat, 8 Jan 2022 19:23:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E98A16B0096; Sat, 8 Jan 2022 14:23:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E22C46B0099; Sat, 8 Jan 2022 14:23:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9C776B009A; Sat, 8 Jan 2022 14:23:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id B880E6B0096 for ; Sat, 8 Jan 2022 14:23:07 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 75010181DA567 for ; Sat, 8 Jan 2022 19:23:07 +0000 (UTC) X-FDA: 79008092814.11.C8AAA13 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf29.hostedemail.com (Postfix) with ESMTP id D501612000D for ; Sat, 8 Jan 2022 19:23:06 +0000 (UTC) Received: by mail-ed1-f52.google.com with SMTP id a18so35022857edj.7 for ; Sat, 08 Jan 2022 11:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HAp9U7GC794so0DPwUoyAc6XCFDGP/6ZZKph1pyeqFk=; b=NRMT/9P1QQzMSkdfnte3DU53C3Y1PSFTN+V+KqzGbKXoKK2OAv2RLtbwuzMrPxLoBG tlvVMUV9Qa8v4n8Tv8abXCecPdYAwmxJiiGHGnEhAEDmj8AzzeB5VIU5Z+E4ACqTBBe4 JooZU0paUl/jNDEl0WaRTfAUMwgcf1UIoxgl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HAp9U7GC794so0DPwUoyAc6XCFDGP/6ZZKph1pyeqFk=; b=ZBkkxyWXt7LONDznnSHh5TrMFvs/3xrxPB0KuqZZDgS2ssdcazvKPzNbHEO0gUNtSC HyEL/gvm9Frx+bs6UnOkUfyRAhBsGQ/YYzuBx5q++wVkhQAGane0aU4HejYyDm+DLVoa iy3c+z9ubNQ1IvS4yLDircANRVlLbWBWLP8tjlcfpP1T0pr1jTE1+5Yi8ClJkxmEp2w/ lAYcdoqAmfjl5vjoWQpxcEP3MHzgharEEzY8LaA8W8xkK4jOu8m7sY5p2fMv9WZjBIuZ P+qfC4+/pqyMabXkeUVmW5cn8XDeGarni9YucfY2G0hFN5KW/mM4tPlJ6iQdY7FU87m/ EeJg== X-Gm-Message-State: AOAM5336bLpdwm/Q4dqSjTnarTCUNE/cyyiR/9SiYrazp/pt/9J5yvHo G5KJJ8pPWlq3fMT83sER4/RvjA2zKgAaqMBV X-Google-Smtp-Source: ABdhPJy62ybyV3jQfO5151cqHHKaur5sLZQRpExaXDcw/KIJmie09F3/YxEwEzG7AcazaGoZKqTLKw== X-Received: by 2002:aa7:db8d:: with SMTP id u13mr66256565edt.111.1641669785097; Sat, 08 Jan 2022 11:23:05 -0800 (PST) Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com. [209.85.128.51]) by smtp.gmail.com with ESMTPSA id gs17sm730852ejc.116.2022.01.08.11.23.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Jan 2022 11:23:04 -0800 (PST) Received: by mail-wm1-f51.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so4174907wmb.1 for ; Sat, 08 Jan 2022 11:23:04 -0800 (PST) X-Received: by 2002:a1c:19c6:: with SMTP id 189mr12513195wmz.155.1641669784282; Sat, 08 Jan 2022 11:23:04 -0800 (PST) MIME-Version: 1.0 References: <7c9c388c388df8e88bb5d14828053ac0cb11cf69.1641659630.git.luto@kernel.org> In-Reply-To: <7c9c388c388df8e88bb5d14828053ac0cb11cf69.1641659630.git.luto@kernel.org> From: Linus Torvalds Date: Sat, 8 Jan 2022 11:22:48 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 16/23] sched: Use lightweight hazard pointers to grab lazy mms To: Andy Lutomirski Cc: Andrew Morton , Linux-MM , Nicholas Piggin , Anton Blanchard , Benjamin Herrenschmidt , Paul Mackerras , Randy Dunlap , linux-arch , "the arch/x86 maintainers" , Rik van Riel , Dave Hansen , Peter Zijlstra , Nadav Amit , Mathieu Desnoyers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D501612000D X-Stat-Signature: 6q7rjn73ped4r8bqj7m7y1oxbcijsn5e Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b="NRMT/9P1"; spf=pass (imf29.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.52 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-HE-Tag: 1641669786-674793 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 Sat, Jan 8, 2022 at 8:44 AM Andy Lutomirski wrote: > > To improve scalability, this patch adds a percpu hazard pointer scheme to > keep lazily-used mms alive. Each CPU has a single pointer to an mm that > must not be freed, and __mmput() checks the pointers belonging to all CPUs > that might be lazily using the mm in question. Ugh. This feels horribly fragile to me, and also looks like it makes some common cases potentially quite expensive for machines with large CPU counts if they don't do that mm_cpumask optimization - which in turn feels quite fragile as well. IOW, this just feels *complicated*. And I think it's overly so. I get the strong feeling that we could make the rules much simpler and more straightforward. For example, how about we make the rules be - a lazy TLB mm reference requires that there's an actual active user of that mm (ie "mm_users > 0") - the last mm_users decrement (ie __mmput) forces a TLB flush, and that TLB flush must make sure that no lazy users exist (which I think it does already anyway). Doesn't that seem like a really simple set of rules? And the nice thing about it is that we *already* do that required TLB flush in all normal circumstances. __mmput() already calls exit_mmap(), and exit_mm() already forces that TLB flush in every normal situation. So we might have to make sure that every architecture really does that "drop lazy mms on TLB flush", and maybe add a flag to the existing 'struct mmu_gather tlb' to make sure that flush actually always happens (even if the process somehow managed to unmap all vma's even before exiting). Is there something silly I'm missing? Somebody pat me on the head, and say "There, there, Linus, don't try to get involved with things you don't understand.." and explain to me in small words. Linus