Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80BF2606A31C for ; Sun, 29 Nov 2026 16:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=agy1MfKv Received: by kanga.kvack.org (Postfix) id 1EEB66B05B1; Sun, 29 Nov 2026 11:25:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DB036B05B2; Sun, 29 Nov 2026 11:25:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE4A16B05B3; Sun, 29 Nov 2026 11:25:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B03026B05B1 for ; Sun, 29 Nov 2026 11:25:19 -0500 (EST) Received: from smtpin09.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2E73D1C40D7 for ; Sun, 29 Nov 2026 16:25:19 +0000 (UTC) X-FDA: 85488681558.09.2B150DE Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf10.hostedemail.com (Postfix) with ESMTP id 58EF3C000A for ; Sun, 29 Nov 2026 16:25:17 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=agy1MfKv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795969517; b=8Ky2nTX5QoW5izb0fHmmMHoDE713DQgqvQ1HH1zHzr+RKBpq2h7HbqG/eJg64m1CLpDIL/ JCjhKPMJ5KP+Nj6lkQys6CYBGXJ7FVS+eQHjXNunQ/G92f7RMlnGyBPAvIlKqG5xcl3Pc+ 4jBvCgAnPxaURh5kA1HSAGwKxokFuyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795969517; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yrdxx25UgRaDfmJO0J0ewGeDWEKMaIvttudBnUzz5NQ=; b=djio1WwGf4JBIrXHSciR6tbon9b3bvboa4+sKnX43cCxm7ZI+eeDVaFcUvNZuqBek1LXlw ICOs/6k+h2qqpKnKXZZOquKKpNRrJ03K2/VY1lOiKOvXn9ER/HZZVQaQsDoDdEQaelkP6f EAMlSlEfFnAWmLBSW4+6tNdTUF6Mdoc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=agy1MfKv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 7AD63430D3; Sun, 29 Nov 2026 16:25:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E10C71F000C1; Sun, 29 Nov 2026 16:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795969516; bh=yrdxx25UgRaDfmJO0J0ewGeDWEKMaIvttudBnUzz5NQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=agy1MfKvFnXpCU0ipCYv9GTu/Rh6+VAYE2CsBih4KfD5nyLRSaCF1kB8mmopGzlDS qeLCGp4BmO+nM5SQrvHMLiaUQuU8XuGUJeJWPtZOaPDpzOewqS8rKWEwgdZT4UdUO6 CGCjUqnu438TVI+oanHCDeIypLZauFhP+YSqO6qwvAUmUAywyIcLwFk2/wnRoUu9Wv F/5HFjfoKHEaKQk4kk83+nttz9QgeG1sb51QBydUf4QkTePYuoRJkh9vXMDrtRZ3L+ H3N7e8ebWn369ixs7At2A5tGZ2LHnRWpeNLV49wB5Ab3HNPetc4hYulEX2pbftqhL/ +msvVUFxV9rOA== From: Mike Rapoport Date: Sun, 29 Nov 2026 18:25:07 +0200 Subject: [PATCH 1/2] mm/userfaultfd: account memory allocated for unmap events X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-fixes-uffd-fork-acct-v1-1-f39cc449d92c@kernel.org> References: <20261129-fixes-uffd-fork-acct-v1-0-f39cc449d92c@kernel.org> In-Reply-To: <20261129-fixes-uffd-fork-acct-v1-0-f39cc449d92c@kernel.org> To: Andrew Morton , David Hildenbrand Cc: Chris Mason , Mike Rapoport , Peter Xu , linux-mm@kvack.org X-Mailer: b4 0.16.1-dev X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 58EF3C000A X-Stat-Signature: 1syhwz3w18ydbwdhieiwmaq17b48aw8c X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1795969517-918696 X-HE-Meta: U2FsdGVkX181VcA0AFPGQg962zVmLlNvGfU11/9QZb21kxZmvPr3TTdd3Hmq1IHbkpgtWFW/hghdiPBmM4g24smW7ou0xut7QNXTfQb0Dq5XuZBuAEu8JZDCIVaxoAVkBdKQq6AdWxoXFwturm7W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yHDs3cCcZqPo52FvuL8ZrPXmhFAp8yMgchc/NwFHdSKY6GNgIazqbQVX+5KnzQjQi9LX6EvlM1U5zqOP5wdP+ip9J05x+FwdpPZoHBHeOhhxnUVxcWf5nZ/2hqRNf9syEDLBMRgzg2Twq5k+PPkbdzkvYcL/rFi86/pgmLAhJhbAORnmN59fufGf5OCHIIsXKDavodWgOEVlNbdvT7PxC2WwzuycW0ttA== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Chris Mason When memory registered with UFFD_FEATURE_EVENT_UNMAP is unmapped, userfaultfd_unmap_prep() allocates a small structure for each userfaultfd context that should be notified. These structures are usually freed only after the monitor reads the events, so userspace controls how many of them are allocated and how long they stay around. They are allocated with GFP_KERNEL, so this memory is not charged to any memory cgroup and memory cgroup limits don't apply to it. Use GFP_KERNEL_ACCOUNT to charge this memory to the memory cgroup of the task that does the unmap. When the memory cgroup reaches its limit, the allocation can now trigger reclaim or the OOM killer there. If the charge fails, it is handled in the same way as any other failure of this allocation. Fixes: 897ab3e0c49e ("userfaultfd: non-cooperative: add event for memory unmaps") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) [rppt: rewrote the changelog] Signed-off-by: Mike Rapoport (Microsoft) --- mm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 15ad69ec2fc0..2ed520c36f71 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -3264,7 +3264,7 @@ int userfaultfd_unmap_prep(struct vm_area_struct *vma, unsigned long start, has_unmap_ctx(ctx, unmaps, start, end)) return 0; - unmap_ctx = kzalloc_obj(*unmap_ctx); + unmap_ctx = kzalloc_obj(*unmap_ctx, GFP_KERNEL_ACCOUNT); if (!unmap_ctx) return -ENOMEM; -- 2.53.0