From nobody Mon Feb 9 01:46:03 2026 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 2EC7A1F130F for ; Tue, 11 Feb 2025 00:41:49 +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=1739234511; cv=none; b=pHS4UBQxju3hd7q4YKx/C7tMp1v+sFmCEmbu2NaM7pJB9fB3RgCjIaFDuW/1wuwfaP/vphCfVuR+dM5QupR0iIlDDgIVqb7fYvx5m9F5o2NvZ9YGHKxZPSAKKdho0/Vk3UlBeRcf+ekcvoopSdaYRYgRpuUMRdFGeR+iJToA1EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739234511; c=relaxed/simple; bh=hewNwPYJ5IwQHNTzWNv8CrtJtwvzBiKdXBLv6qX1L6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSCbX5Ir7y1ZiHZMOAdfzkxUz41MRpQMQ74Xt+f2uTYOC+/i/x+lqQs4o0J0vei+TwbTJTBW2nj6/Ty43dIvWBJMJ7pnubiDTpZ2MhtuBeH5lsWRtIOPP+lUHyLOPTOWLPczpdKbrLg1sdjUaPrKw9KaTtZTE9DZWeCZtDqjrF4= 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=EpLZbfxS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EpLZbfxS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739234509; 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=lueIMS7GNplHH2FDTf2Wie6UZEYR6RkSMcK6ekbEp2Q=; b=EpLZbfxSzWbNNx44sEts5pfaiKupicA4CMIMc6VFN9QVoh/NtYUcykf+5/Y//z5DFyqTrT TTSXgJSa+lqfnDpHXxo6Bp6DWRVJkqvxBlwoWX5LFRPod8DpViUvO887tBCHEVCHLnFmV5 ufQ7i1wxb2oBMv4Fv/6n1WM6dgpuBhU= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-Q5HLC00ENK-uAZBuWss8Hg-1; Mon, 10 Feb 2025 19:41:44 -0500 X-MC-Unique: Q5HLC00ENK-uAZBuWss8Hg-1 X-Mimecast-MFC-AGG-ID: Q5HLC00ENK-uAZBuWss8Hg Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 229591800877; Tue, 11 Feb 2025 00:41:40 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.129]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 108571800873; Tue, 11 Feb 2025 00:41:29 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, willy@infradead.org, kirill.shutemov@linux.intel.com, david@redhat.com, aarcange@redhat.com, raquini@redhat.com, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, tiwai@suse.de, baolin.wang@linux.alibaba.com, corbet@lwn.net, shuah@kernel.org Subject: [RFC v2 1/5] mm: defer THP insertion to khugepaged Date: Mon, 10 Feb 2025 17:40:50 -0700 Message-ID: <20250211004054.222931-2-npache@redhat.com> In-Reply-To: <20250211004054.222931-1-npache@redhat.com> References: <20250211004054.222931-1-npache@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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" setting /transparent_hugepages/enabled=3Dalways allows applications to benefit from THPs without having to madvise. However, the pf handler takes very few considerations to decide weather or not to actually use a THP. This can lead to a lot of wasted memory. khugepaged only operates on memory that was either allocated with enabled=3Dalways or MADV_HUGEPAGE. Introduce the ability to set enabled=3Ddefer, which will prevent THPs from being allocated by the page fault handler unless madvise is set, leaving it up to khugepaged to decide which allocations will collapse to a THP. This should allow applications to benefits from THPs, while curbing some of the memory waste. Signed-off-by: Nico Pache --- include/linux/huge_mm.h | 15 +++++++++++++-- mm/huge_memory.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..fb381ca720ea 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -44,6 +44,7 @@ enum transparent_hugepage_flag { TRANSPARENT_HUGEPAGE_UNSUPPORTED, TRANSPARENT_HUGEPAGE_FLAG, TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, + TRANSPARENT_HUGEPAGE_DEFER_PF_INST_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, @@ -177,6 +178,7 @@ static inline bool hugepage_global_enabled(void) { return transparent_hugepage_flags & ((1<