From patchwork Thu May 2 08:52:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13651450 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 D52A7C4345F for ; Thu, 2 May 2024 08:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 685C56B00A7; Thu, 2 May 2024 04:53:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 634E86B00A6; Thu, 2 May 2024 04:53:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43DC86B00A9; Thu, 2 May 2024 04:53:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 170FA6B00A6 for ; Thu, 2 May 2024 04:53:11 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C640DA0B19 for ; Thu, 2 May 2024 08:53:10 +0000 (UTC) X-FDA: 82072841340.25.AEC2286 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 296A480002 for ; Thu, 2 May 2024 08:53:08 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QPPwEtaF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714639989; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T0uhogWZMK2FCWUvbV0NVhLRqNmBD8nexNysXl5gy1w=; b=CQtWejgaAGlIL3kH1bBLm+DriqJztHMekiwHzpwBmZLnBoplhmz52axTPSn3hEBig38RVk sL+elnHQn+f9w7pem0TDxZOf8Cgdp05JipWXM12ql7YtpvF5DQdMvWx/BEOsvDF1kyxOSD 1ImEjsTSgbpyVef/CVa1j5iBpogHu1E= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QPPwEtaF; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714639989; a=rsa-sha256; cv=none; b=Yv4RcieIKsSH87Ua9bvdvU8QvfKILiyohwhjxd43IBSGzaPJ2flsTpLypSDGNa2Bc+0efF k/cLaIShgcKHJIdR6lSHG11CuKoLMeM1h9kBK+ZLCpS2KPhi28+m1rubrUBlZBEKshzlGk BuaEZ8PUmT5CpOm/8jFPerSqwYGMdFc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714639988; 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=QPPwEtaFpGclaWZXmRjXtQMGi9qRoDAe2SBpO7RsOauemWSIgmsZ9aymeye/ScCc9vwBi1 V3bP7bgbzi3ofwhiXpsZBBlFHfCNN98kx2+4wNpoNgF/4b1SgRyEE3rJuuH40a67k9Idy6 bxIUvViZZufCNOormXgn86fFjzpFzPM= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Stat-Signature: qyowwbydiwzkseabr7ynymuzp73d8tgd X-Rspamd-Queue-Id: 296A480002 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1714639988-171236 X-HE-Meta: U2FsdGVkX18ZgQccx1lfJ+txAHzeKM8Grv/geAgrW/DfLzjG/T4dcN2nQ3uHJ37TWOuY5CavZL0zzG9lU7pF3Sv5LM1ztBvUPX70LGAhzVTzY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qWQNXpfOiw/017Kph+WlpY4gLUI3tC2whCB1Lfsibxd1VE6BeqoXeZoKSICliE/lq1lAnNxw== 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: List-Subscribe: List-Unsubscribe: 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)) {