From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C3DE9318BB5 for ; Fri, 27 Mar 2026 05:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774590160; cv=none; b=IoG6kA0QKI9NSpmMbkt8U2gnzLNVfxSXVbzzw2uZ84ITlHObz0tAAsCGgtgFjhYLAnqqCTWKIIidjTou+o/ojjyVtm7wix2dcPR9/tKc6SzNJt99hkiFEL6pu4cwmE2kO+FlYsk0CtSPQb3BDVucnHwbR7JZE91R1obwI+TrY4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774590160; c=relaxed/simple; bh=M3yhklj1LSgjvqFVJOXiEJ8tXr8x4LCP2Dv44XWj7Ms=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=a0+SKb5Lf9wMRMSd5VB3L21qct6qHCz8IipYPqWGrEWDA3KevqjCOxw5E65X02z9Yqxj4KEVK1UML9YMTddcZzX5R5uqj8vQeJTjTyV5X5tLbTGQLacqjygTnEDFGqAZCpK9/hbzjf9Hc/Pu3x18MrJSWr2Kpsv91EvCKm5efQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=nMVg/aQs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="nMVg/aQs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 144EAC19423; Fri, 27 Mar 2026 05:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1774590160; bh=M3yhklj1LSgjvqFVJOXiEJ8tXr8x4LCP2Dv44XWj7Ms=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nMVg/aQsknpt/6YD0Ec352VbThWsH3IQnRZ35TCjfoIL+crnXVhK1f+QBHw9lcn3y /cHhc3MoNXa/z+/tB+d4yJtmHM4kwsvbNsMnhZi9hl7E9avTgc/6KdvzJLIdX5Nyjm 52VhB0qs1ecpt/nYaaFFbktocvqtS/Va+Ot6cOlQ= Date: Thu, 26 Mar 2026 22:42:39 -0700 From: Andrew Morton To: "Lorenzo Stoakes (Oracle)" Cc: "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jann Horn , Pedro Falcato , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jianzhou Zhao , Oscar Salvador Subject: Re: [PATCH 0/3] mm: improve map count checks Message-Id: <20260326224239.9052f8be3ddb9cac600f59f5@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 11 Mar 2026 17:24:35 +0000 "Lorenzo Stoakes (Oracle)" wrote: > Firstly, in mremap(), it appears that our map count checks have been overly > conservative - there is simply no reason to require that we have headroom > of 4 mappings prior to moving the VMA, we only need headroom of 2 VMAs > since commit 659ace584e7a ("mmap: don't return ENOMEM when mapcount is > temporarily exceeded in munmap()"). > > Likely the original headroom of 4 mappings was a mistake, and 3 was > actually intended. > > Next, we access sysctl_max_map_count in a number of places without being > all that careful about how we do so. > > We introduces a simple helper that READ_ONCE()'s the field > (get_sysctl_max_map_count()) to ensure that the field is accessed > correctly. The WRITE_ONCE() side is already handled by the sysctl procfs > code in proc_int_conv(). > > We also move this field to internal.h as there's no reason for anybody else > to access it outside of mm. Unfortunately we have to maintain the extern > variable, as mmap.c implements the procfs code. > > Finally, we are accessing current->mm->map_count without holding the mmap > write lock, which is also not correct, so this series ensures the lock is > head before we access it. > > We also abstract the check to a helper function, and add ASCII diagrams to > explain why we're doing what we're doing. This little series has no reviews, if anyone is wanting to boost our R-b stats. Or not. I plan to upstream it unless someone stops me.