From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.148 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366062; b=qHCludPODG7jWYXKdfpd96eWokJuIri/Hjqt4fAo1V8Y4lIbVkhRmV4ezO1oMdONHsi+ Q2TtKx91GNKL/6OJ9eF55eODV4Ps/9ecU7WmITjdOJcyMkkQwOtvoU1Fqv80PDTyk1XYz a4lkDH9hsyNkRc0XhL45D9sYZpT/lZdTn3Y8K3mWwO5d04CuF9u+fTTL+KrMKC75PkZZa gIZR9eYqcfmzxXFVlobM5YguznyLCHNOB67XzQE7RKA9bffERGNxXB/okOdzp/CFE2MJv FBkQ0O6kRi+/VKKUAalMuqb6iI5+lVQ/KHg25BzoXVQGp+/vJ0gO6BAX00IPeWFBOaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366062; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=Y2V8F4yZM9cOObkxHAYYb1/fAEySSRJMdsSGpvOYnf8=; b=IfuVNRvZj31EPDr4/697LOuBXB+2MLMI0tFVOwiC5324hfT2Zthe+zVDPFYMyhaoINdW Kjc5yswdwJhYb5bxPeHVfnYevO82znHFlirdhLP3YzvPK+lim4gnExe55EKVcifSs2tYB 64Uu0lK3qRMKGymLJ844+8vG5zXrDFy9zo+z1/FZzkq9Xh/ys4ebLwa7PZ4UaC9+jDtzV tCYVpCzvcWSGjkTgWx5okJfKyU4FpCbmsOQ7vpeYvh4eSY0rC9fTO9VmK4lS98/IxZTkJ gCBpmNzqaYZ+4ZwzqRRsaRH0NR/skd4QeBgsZnqA9fT2wIFSS+V9uckfuk62CcK88Ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fN4um51x; arc=none smtp.remote-ip=91.218.175.148 Received: from mta0.migadu.com (out-148.mta0.migadu.com [91.218.175.148]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AF72606A322 for ; Fri, 4 Dec 2026 06:34:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4AF72606A322 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, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fN4um51x X-Envelope-To: linux-doc@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=q/5g6ADhJ23vi6PH0CkgMxsdJO9jvFTcRhuaATsp8iY=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796366059; v=1; x=1796970859; b=fN4um51xT1qrTclJBE0dmjfSe+Gj6IcnD4srfFSL4hu9LvIrBD65fUqCzttsxq2c/oiGFx6F ERwZvlmJEHQHf8M+nOYJPIQyBZoDEP+2iU73ig12V6EFzX/lAR8oAvO6+SmOBcvq4OnXIq2H8aA 9I51DzHuWl2I/stxB7QZ1NGM= X-Envelope-To: linux-doc@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 581ab79c9f1e78e3; Fri, 04 Dec 2026 06:34:19 +0000 X-Mizu-Trace-ID: 581ab79c9f1e78e3 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v2 34/35] mm/hugetlb_cgroup: charge faults to mm->owner From: Muchun Song In-Reply-To: <20261203-hugetlb_fixes_2-v2-34-9bbeabb555d2@kernel.org> Date: Fri, 4 Dec 2026 14:33:45 +0800 Cc: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" , linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan Content-Transfer-Encoding: quoted-printable Message-Id: <37685587-2A0E-426C-9A26-713AA1C64FC5@linux.dev> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-34-9bbeabb555d2@kernel.org> To: "David Hildenbrand (Arm)" X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) = wrote: >=20 > We can bypass hugetlb cgroup limits when a kernel thread faults in > hugetlb pages for a user process: __hugetlb_cgroup_charge_cgroup() > charges the hugetlb cgroup of current, and kernel threads usually live > in the root cgroup, which has no limit. >=20 > For example, a KVM's async page fault repeats a fault of a vCPU that > just failed at the limit in a kworker, which then charges the root > cgroup: >=20 > vCPU thread kworker > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D > __kvm_mmu_faultin_pfn() > hva_to_pfn(), FOLL_NOWAIT > hugetlb_alloc_folio() > charge fails > KVM_PFN_ERR_NEEDS_IO > kvm_setup_async_pf() > async_pf_execute() > get_user_pages_remote() > hugetlb_alloc_folio() > charges the root >=20 > Let's fix it by charging the hugetlb cgroup of mm->owner whenever we > allocate or reserve for an mm, like memcg does. If we don't allocate = for > a specific mm, we use current->mm, again like memcg. Unlike memcg, = which > falls back to the root cgroup, we fail the charge if the mm has no = owner > (anymore), as we would otherwise bypass the limits again. As mm->owner > depends on CONFIG_MEMCG, nothing changes without it. >=20 > This changes the charged hugetlb cgroup in these scenarios: >=20 > (1) Kernel threads that fault on a user mm, such as KVM async page > faults, kvm_xen_set_evtchn() in the irqfd work item and > iommu_sva_handle_mm(), now charge the cgroup of mm->owner instead > of the root cgroup. > (2) vhost kthread workers, which join the cgroups of the task that > created them, now charge the cgroup of mm->owner. > (3) With cgroup v1, threads of a process that are in different hugetlb > cgroups now all charge the cgroup of mm->owner. > (4) Processes that fault on the mm of another process, such as a > userfaultfd monitor (UFFDIO_COPY) or remote GUP through ptrace, > /proc/pid/mem or process_vm_writev(), now charge the cgroup of the > target's mm->owner instead of their own cgroup. >=20 > ... which should just be the right thing to do. >=20 > This has low urgency, as it only affects hugetlb cgroup limits. Let's > not CC stable, as this might not be particularly easy to backport. >=20 > Fixes: 6d76dcf40405 ("hugetlb/cgroup: add charge/uncharge routines for = hugetlb cgroup") > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) Acked-by: Muchun Song (ByteDance) Thanks.