From nobody Fri Dec 19 20:51:13 2025 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 985DF18EFFE for ; Mon, 29 Jul 2024 22:28:01 +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=1722292083; cv=none; b=NCqTe388a2RjEyo7yE4GwYGIZTIGH/PWzf2RUm3Xlian/OX6yoXowzq8oAX9mzGzjqmQ4J4bEeNItDRV5nojiqt2rCLf7t+spEqE7NP6qeFqxdnLDUlkZhWVHggnQzIQ/uu9HU+qJ9zorAJwPIYd4TZDw4JeK55HF5maVExvdog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722292083; c=relaxed/simple; bh=CEko05szOCw0XiJtm9L2zhHDjsOD8IGT7jJQzada6fY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qelBAJ/mm4GFHqs6smNoWsoOsuiaLcd9m9ki4EQpdC/QLVhfdweoVoSf1x5oHsf/kM62Wj05hVb8Eyg1KgaaK/rkUi6qltT5rY2cGdPQUruqPawnhOjH2J4KuqiUzBqGAPoI2SQMtdKcD8hZx3x3Xpw1JypEHpudgV6l2/4o/Zg= 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=UbHp6JLj; 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="UbHp6JLj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722292080; 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=Bx7PoZA+3BaXuBlEAlsF0yYgH6+llN/9+YIdocNVsPk=; b=UbHp6JLjGIuxpf5ahVQ2PZeX13w0NB1CYdSXojG3MH8biNZNag7kF+sX5o+TZO3+zAsMLk cmE+k+/BxcQVzWRh2G8IYgwyS68T3qz1+PvBj6ESOBSVCGdyEXiqe6unBpQ+YJQB/A9egu GcCjCOjT1lqPkb0BGcUtnd1eThiIT+4= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-zMAMeneGNAWQ5cntbgBMYQ-1; Mon, 29 Jul 2024 18:27:53 -0400 X-MC-Unique: zMAMeneGNAWQ5cntbgBMYQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFA261955F49; Mon, 29 Jul 2024 22:27:51 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.10.55]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 290111955F3B; Mon, 29 Jul 2024 22:27:47 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Matthew Wilcox , Barry Song , Ryan Roberts , Baolin Wang , Lance Yang , Peter Xu , Zi Yan , Rafael Aquini , Andrea Arcangeli , Jonathan Corbet Subject: [RFC 1/2] mm: defer THP insertion to khugepaged Date: Mon, 29 Jul 2024 16:27:26 -0600 Message-ID: <20240729222727.64319-2-npache@redhat.com> In-Reply-To: <20240729222727.64319-1-npache@redhat.com> References: <20240729222727.64319-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.0 on 10.30.177.17 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. Cc: Andrew Morton Cc: David Hildenbrand Cc: Matthew Wilcox Cc: Barry Song Cc: Ryan Roberts Cc: Baolin Wang Cc: Lance Yang Cc: Peter Xu Cc: Zi Yan Cc: Rafael Aquini Cc: Andrea Arcangeli Cc: Jonathan Corbet 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 e25d9ebfdf89..7ef7d3e2f5c6 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -45,6 +45,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, @@ -125,6 +126,7 @@ static inline bool hugepage_global_enabled(void) { return transparent_hugepage_flags & ((1<