From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EE43372B41 for ; Thu, 21 May 2026 11:24:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779362668; cv=none; b=g96hIsygdfDI4ery0LdiCbnss5ddKdnKGDersgAmQSfXYKabphBz8YM3uHtOizoxTzJnwn6UXl14P0RCU0b9qTdUzij9BzRWDvNsXrpOxQnX7ZgFciysk4NkoOiUbTonw3s21JiwqNjSMNYW8Y7PmFRU+FksHV8Hpyun4tyMz0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779362668; c=relaxed/simple; bh=YUoIKZ6fjqCMA7Nsur2Z6SraVqMh2aFofJ9GzDnYzjc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cze3p0/GCmy1f4SqxOBe2b1t1Xx5Lp4Wo7KLHgyiCYi5yq6xj+Y6zAUGZKlj9xN0AQbsB6PpBqpWRkGCTgD6KAqi3sNvjeDeNRBjtUJ7lvY9gS5aQ+LdVHc/K29YM1zK5hY/z1LMpLFJ8hXtG3JzoY6mMhaH+uDaFwjziKoCNnQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Jp808FfH; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="Jp808FfH" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 727763D76; Thu, 21 May 2026 04:24:20 -0700 (PDT) Received: from [10.57.91.212] (unknown [10.57.91.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CC2C53F7B4; Thu, 21 May 2026 04:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1779362665; bh=YUoIKZ6fjqCMA7Nsur2Z6SraVqMh2aFofJ9GzDnYzjc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Jp808FfHIf2INAyNUKjyzFUDdoLUap7tdKuaWXl/u4wTfkRyOswfekFS1kCxGiUyH wnDgqh7JHFp2HxVALetvKZYV93X1ts82Px1WEYektmnKkpF1jkJWcRv/b2OsfAUkpF 9Q3XkDfhEXL6TjeFsp5oAm5RuO2Loah1MmBnB0QU= Message-ID: <60542cd7-d01c-4247-8957-8423b54ae99d@arm.com> Date: Thu, 21 May 2026 12:24:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [RFC] arm64: mmu: use range based TLB flushing when hot unplugging memory Content-Language: en-GB To: Balbir Singh Cc: Alistair Popple , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, catalin.marinas@arm.com, will@kernel.org, david@kernel.org, anshuman.khandual@arm.com, dev.jain@arm.com, jhubbard@nvidia.com References: <20260521042426.2128731-1-apopple@nvidia.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 21/05/2026 11:46, Balbir Singh wrote: > On Thu, May 21, 2026 at 09:50:04AM +0100, Ryan Roberts wrote: >> On 21/05/2026 05:24, Alistair Popple wrote: >>> Hot unplugging memory on ARM64 requires a TLB invalidate after unmapping >>> the page to be hot unplugged from the direct map. Currently that happens >>> one page at a time, meaning range based invalidates cannot be used. The >>> result of this is that removing large amounts of memory takes a long >>> time and in some cases can trigger an RCU stall warning. >>> >>> For example on one system hot unplugging 480GB of memory takes ~1 >>> minute. With this change the same operation took ~1 second, a 60x >>> improvement. >>> >>> Signed-off-by: Alistair Popple >>> >>> --- >>> >>> This is an RFC, because I'm not sure the change is correct as it frees >>> the PTE page before flushing the TLB. I'm not familiar enough with ARM64 >>> architecture to be sure this is safe, for example I don't know if HW >>> can update PTE bits such as access/dirty in the page through a stale >>> TLB entry. >>> >>> If so this would open a window during which the page is free but could >>> still be written to. Likely the safe option would be to collect all the >>> pages to be free on a list and free them after doing the range based TLB >>> flush, but wanted to get feedback on the approach before implementing it >>> which is the goal of this RFC. >> >> Hi Alistair, >> >> This patch doesn't apply on v7.1-rc4 because it conflicts with this patch: >> >> Commit 48478b9f79137 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") >> >> which has a very similar performance improvement, so hopefully it solves your >> problem? >> >> There are two paths which use this logic; unmapping the linear map and unmapping >> the corresponding vmemmap. In the latter case, the memory is also freed, so we >> can't safely do the range optimizaiton there since the TLB needs to be flushed >> before freeing the memory. But the linear map is the big, slow bit so hopefully >> it's sufficent for you? >> > > I assume vmemmap path is for tearing down the struct pages corresponding > to the physical memory and vmemmap teardowns taking a flush should be > OK. It is worth checking if the issue is already fixed. Yes, exactly. Assuming you're using 64K pages, I think vmemmap is mapped using base pages. So you'd get 1024 struct pages on a page, so 1 TLBI per 64M of memory that is being unplugged on the vmemmap path. On the linear map path, it's a single range tlbi operation to over the entire range. Alistair's patch is doing it per 512M in both cases, but is unsafe for vmemmap as currently written. > > Balbir >