Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp993850lqm; Thu, 2 May 2024 01:53:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVE5aiv4c47OUyQNaujmjo+JRH85iNBKGuzR41Z6PshaEJa9SGnWFiEGjVbrq2CdeUK7lDqNYYFWQl9dHVOj7oWoJ+V5RlYpNYTzOITOA== X-Google-Smtp-Source: AGHT+IEVx+d7Ua6xvPbRd4slc0Kd0KaRfnBUIXZL4E+Y1VTl4Rpup5fIDBADQrlXoGiXgNyJArZS X-Received: by 2002:a05:6808:8d8:b0:3c7:4ffe:c6e0 with SMTP id k24-20020a05680808d800b003c74ffec6e0mr5472500oij.39.1714640017077; Thu, 02 May 2024 01:53:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714640017; cv=pass; d=google.com; s=arc-20160816; b=l8QdIWSMn4cCJmg8ZLE8U6MShdPgTxVPEh5FuUS1Dgt/belbYPLQertf1rRiUhdgK2 R/qx1zhd5Ko0Oqm1XZ0iVkzmQ40BTM251xYlm6NSM6RwIXiJjVASQZEBRiYPOLNytwHY 2uNQfSMkQ4LNuxwBOHlLex9aaB5VjvvfXqQQBZTubA+SKxkxxzaNt192VlKGi9BfFp6N puw1L3S/owEYPjzAFgs4GY15HryB8Z9dm5WynPC3sJmixBVPcV9+iBrgahC4Ku4q4+hO nERJnGsoQIxqQBHZJ9jC3F0uJxgwbjw9AuOu4j0nAhXVxvBVscKWTY5ICFqPWYLXjIOa y5Ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=T0uhogWZMK2FCWUvbV0NVhLRqNmBD8nexNysXl5gy1w=; fh=J8wFRvNcqY50wsPXTXgKF2h1h8iG+05KG6arTwYbWoM=; b=ygfrhyRAFATH/fAxQF8ZHcJt0RLnNkcIpJldf5wEIXFV265O2mUOIPYjdvrc4A4nES Wsp/YwgshjGvuDAIeKEo0XZksvPfelHBZU2o0EzW20X63xNUCtFPxFh4270LMwC+oBzz n11HlPBYS5+aDABx1dkLkFRJ/BTdRK7x3Jm/pttp4NX9JXqABnMYWUTtMdQ8Ly++7cPZ VGlPcKrBrCOMgKnMxCOvCjsaff22Zgrk2uwyl2gI0i0bTD2wlytYFJdvpKPAkFk+/RHA bSE3W7ImYZNTjVeJovHMpdcpHvcQfHNM5JYV6VuILFwJ8QNBH1SVgGA8cPZZerIcIXbs iZVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bDgTxs/P"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-166158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f3-20020ac87f03000000b004370939eef7si500793qtk.532.2024.05.02.01.53.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 01:53:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="bDgTxs/P"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-166158-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C7CFA1C210C4 for ; Thu, 2 May 2024 08:53:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD40E537F0; Thu, 2 May 2024 08:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bDgTxs/P" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4DABF524A6 for ; Thu, 2 May 2024 08:53:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714639994; cv=none; b=gF5x8GWNfc5wTslZnb8Ul2ZPbOFosL13P/3XaM7hp5Ithl3s9wQZ1EAEkcg+ZZ+RajKppjvz/dUkjr3l6fPOkC4AJTwLZKIn2fISwThYW/iUTaQpuvqZ3GWY2IfAQvSZiMFDjWq8kkENNnllC108DwhsOniv/XL+X9vIXCP1sRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714639994; c=relaxed/simple; bh=2P0XQ3f/nErLPEazYra6MFwog6B2HmsLDNWBea6YiYQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIaVHqX9dUdgV/cJLkbz0Q6kWUGLZSMFVefKAKjwZ3wEcYuEJ6bPGvxLfZ+pK9ooVyWbF1jkVVlcxgj6KZagtzFx9coXGwyUtYBAoBLTcvgpX9cHIOHVi4L2W2LFxYrIyYW2QYsJODqbSMurzXayj0E4pwcqeP1w8U5vrewN3yM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bDgTxs/P; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714639990; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T0uhogWZMK2FCWUvbV0NVhLRqNmBD8nexNysXl5gy1w=; b=bDgTxs/P2/76qrH/X++uUJ8cvSOdBxWxNU03Xk2kOBUNGlN4PcyekdWuBgWopvrtsTUkFq TLaXXxjICKFN+x+v94bL+nqjw2iz7vfCmWQ4DZkH/91qsgHkkotXX4td97pQxw/4nZW2pe EmdzUj3Sc35Y38FNX//UE/jidCs6u7E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-rpnWT_B-O0-ApCVzbzjOLA-1; Thu, 02 May 2024 04:53:07 -0400 X-MC-Unique: rpnWT_B-O0-ApCVzbzjOLA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8D9B6811029; Thu, 2 May 2024 08:53:06 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.193.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8ED1A40ED2F; Thu, 2 May 2024 08:53:04 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Muchun Song , Shuah Khan , Peter Xu Subject: [PATCH v1 2/2] mm/hugetlb: document why hugetlb uses folio_mapcount() for COW reuse decisions Date: Thu, 2 May 2024 10:52:59 +0200 Message-ID: <20240502085259.103784-3-david@redhat.com> In-Reply-To: <20240502085259.103784-1-david@redhat.com> References: <20240502085259.103784-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 Let's document why hugetlb still uses folio_mapcount() and is prone to leaking memory between processes, for example using vmsplice() that still uses FOLL_GET. More details can be found in [1], especially around how hugetlb pages cannot really be overcommitted, and why we don't particularly care about these vmsplice() leaks for hugetlb -- in contrast to ordinary memory. [1] https://lore.kernel.org/all/8b42a24d-caf0-46ef-9e15-0f88d47d2f21@redhat.com/ Suggested-by: Peter Xu Signed-off-by: David Hildenbrand --- mm/hugetlb.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 417fc5cdb6eeb..a7efb350f5d07 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5963,6 +5963,13 @@ static vm_fault_t hugetlb_wp(struct folio *pagecache_folio, /* * If no-one else is actually using this page, we're the exclusive * owner and can reuse this page. + * + * Note that we don't rely on the (safer) folio refcount here, because + * copying the hugetlb folio when there are unexpected (temporary) + * folio references could harm simple fork()+exit() users when + * we run out of free hugetlb folios: we would have to kill processes + * in scenarios that used to work. As a side effect, there can still + * be leaks between processes, for example, with FOLL_GET users. */ if (folio_mapcount(old_folio) == 1 && folio_test_anon(old_folio)) { if (!PageAnonExclusive(&old_folio->page)) { -- 2.44.0