From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34A50330648 for ; Tue, 20 Jan 2026 03:32:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768879945; cv=none; b=iPF4THqnh4GmUrL3GMLLdyurzvYR7ITuPLDhNGTFAyjPG28qnUwaEUPc7WyDt5S+/jyRx17wK6OxG9VYkp2inSN/+Z07Ecdj22GNeNNhFEnNsvOMfTEzJkwHUPFTeskLPFyYMf9rsLIc2ugwShPJFU/gJkkHX4jYLCb32cpC9Hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768879945; c=relaxed/simple; bh=HJK3Uel+55sCo8FkfvVMNQ/GF0k2W8Gg0oyqA4j2ULQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=THb9bfqnY5ikm1Ky9dByZY+Zx5QlLuptQWbTE2o1n/zCjvh1WERwMyP2wtwU05gSnzXmuwq2GhaY/IexaVuKCq5fcmvXKOHD0Y6LEeP/m1PYbdgghdoqLK/pe+RBco5nOXGs7kjiNvWAgdxi9r8FVJtFylBKCs2jW2E9E5xA95Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jH8J5iOx; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jH8J5iOx" Message-ID: <062eab31-14ac-4644-814a-daa6f2349d92@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1768879941; 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=HKfBv+U8IaP8ZbaVUMGRPyBDPIVVf8vPcWmFoY99i08=; b=jH8J5iOxvck1BAftxqEvGfdPQyBO4kpnXUI/bHKlqrK9QeWfc1MKCgq0/YtEnOCpY8NWQO Jon1BWdOQXkeOcBTXC6JKBhcCb6N6rf4J1tZ4sKr55NiFwHkxoOFVEeNFnZBo+Kb0MBy9w nsY1zFbODTBveRXHL0lIdGzFvKfA/CM= Date: Tue, 20 Jan 2026 11:32:05 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v1 2/2] mm/memory: handle non-split locks correctly in zap_empty_pte_table() To: "David Hildenbrand (Red Hat)" , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko References: <20260119220708.3438514-1-david@kernel.org> <20260119220708.3438514-3-david@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <20260119220708.3438514-3-david@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 1/20/26 6:07 AM, David Hildenbrand (Red Hat) wrote: > While we handle pte_lockptr() == pmd_lockptr() correctly in > zap_pte_table_if_empty(), we don't handle it in zap_empty_pte_table(), > making the spin_trylock() always fail and forcing us onto the slow path. > > So let's handle the scenario where pte_lockptr() == pmd_lockptr() > better, which can only happen if CONFIG_SPLIT_PTE_PTLOCKS is not set. > > This is only relevant once we unlock CONFIG_PT_RECLAIM on architectures > that are not x86-64. > > Signed-off-by: David Hildenbrand (Red Hat) > --- > mm/memory.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) Reviewed-by: Qi Zheng Thanks! > > diff --git a/mm/memory.c b/mm/memory.c > index c3055b2577c27..3852075ea62d4 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1833,16 +1833,18 @@ static bool pte_table_reclaim_possible(unsigned long start, unsigned long end, > return details && details->reclaim_pt && (end - start >= PMD_SIZE); > } > > -static bool zap_empty_pte_table(struct mm_struct *mm, pmd_t *pmd, pmd_t *pmdval) > +static bool zap_empty_pte_table(struct mm_struct *mm, pmd_t *pmd, > + spinlock_t *ptl, pmd_t *pmdval) > { > spinlock_t *pml = pmd_lockptr(mm, pmd); > > - if (!spin_trylock(pml)) > + if (ptl != pml && !spin_trylock(pml)) > return false; > > *pmdval = pmdp_get(pmd); > pmd_clear(pmd); > - spin_unlock(pml); > + if (ptl != pml) > + spin_unlock(pml); > return true; > } > > @@ -1934,7 +1936,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > * from being repopulated by another thread. > */ > if (can_reclaim_pt && direct_reclaim && addr == end) > - direct_reclaim = zap_empty_pte_table(mm, pmd, &pmdval); > + direct_reclaim = zap_empty_pte_table(mm, pmd, ptl, &pmdval); > > add_mm_rss_vec(mm, rss); > lazy_mmu_mode_disable();