From patchwork Mon Jul 29 22:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13745843 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 1C3F0C3DA4A for ; Mon, 29 Jul 2024 22:28:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 613CD6B0089; Mon, 29 Jul 2024 18:27:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C4296B008A; Mon, 29 Jul 2024 18:27:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48BB26B008C; Mon, 29 Jul 2024 18:27:59 -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 29F4A6B0089 for ; Mon, 29 Jul 2024 18:27:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C5B41160125 for ; Mon, 29 Jul 2024 22:27:58 +0000 (UTC) X-FDA: 82394229036.10.05C112F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 061B2160016 for ; Mon, 29 Jul 2024 22:27:55 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EKwjATJg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722292033; a=rsa-sha256; cv=none; b=oxq8Ud4W2qDSaLeGjrFoMH+zV+v3guKYr4v5NVoo6gxslH7LVlNXTO7nyGOc8UQA56Mvq3 QxD0h166GhUTJnqJrOZNDqFsplDJsPHoF+MOhPADawtXTFr8k275h2VSAVSc3kmg5saqEb ntdnQtB8eS51KOg4aVQkYgUF5jOCgx8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EKwjATJg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722292033; 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:references:dkim-signature; bh=4Q5RykvPxYoFpCQpWDRHF5h7ZQ9BlxcuCpJcIY9nYUE=; b=fVUUdE8+Avz/syd/KU1QlhVKEqlmdqU3Je7YZ0bhk08QPPl5w16ArIQOcU98E9vFN7/BU1 TSC+kUEz2RFg9A/I7K+6Y1ghlq3WAQsh/AqVmbVxCa6wegTEKvjehsN2F3yvsYpjJ6t1ry SsvgezY7v0gkcMcz/hudX7OwcEq4Al8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722292075; 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; bh=4Q5RykvPxYoFpCQpWDRHF5h7ZQ9BlxcuCpJcIY9nYUE=; b=EKwjATJgKlEFNQbaiQtwOtpssJFEqM3qtxh9GmJQVwQBcCZfRCAKWyZKYIzFIDvjMok71M 0sbjEJId/yIxX7GfIzUwgszivorwK9R9m99yy7U605Id8MTKxr9lPeWpy9IFlSxG5tcRXx EMhikDKgY0v2cw4PqfvguQfc5r14zio= 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-563-uTyRrDj5N6GtKax1PpQkQw-1; Mon, 29 Jul 2024 18:27:50 -0400 X-MC-Unique: uTyRrDj5N6GtKax1PpQkQw-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 234F81956095; Mon, 29 Jul 2024 22:27:48 +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 D6DEE1955F40; Mon, 29 Jul 2024 22:27:43 +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 0/2] mm: introduce THP deferred setting Date: Mon, 29 Jul 2024 16:27:25 -0600 Message-ID: <20240729222727.64319-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 061B2160016 X-Stat-Signature: md1wqmfpus15gyc6qbccayu4jhgzye11 X-Rspam-User: X-HE-Tag: 1722292075-965527 X-HE-Meta: U2FsdGVkX19DIA43lB/UI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9bdpE6hLCyVl0ose+XQpQ6a6u4taMppKbus7Oy1+SOU5zuMDu4XSjK25ZbpKBMPwZFQU/xkSc/dSJmQshfudKKQdEhWRS+ASFA4YgD9sGzNK64OevnJWsFLEXcXueVobIKUrbxV8WFoGp8XgCXy0UScDGqgnqHZSmnYNNZoXOkpT2zhyDG0AD0iI3ctHD0WDlSAYwGrXabXI2H8DwY5rVUkygtx5Np2ySD/gDJ9iMXAXtImK5Y3gzNYKOJQzyH8Zbqi6ZIzJqPaYklQamMktS4ktseG3GUdgm+w6Uwxj7QHPVaIYnMZHrbhSLtgiGnjJHOS2WZ2C6eZ6ilJlLT2/qIj1tKZgDfKpIR28gIskPHJUR31NI7t9TpUxG5YwRAVI4Y6wkoJHINl2EtbfFsTM2KazC+7VROEUH9EFMJ3ra84P7wnMABEmV1Feq4Q10flO8KPAP6F0vS2Ki4Uev07Id9otccZlX6GYggS4o8kIr+c1xI2hZm162wtpbv8F5XPRMT3d441dgxIZ4l6Vw02FEGoqUJIgJaUOLgCuhGCw44e1Y3PgJFhKRqUyX2wcB 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: We've seen cases were customers switching from RHEL7 to RHEL8 see a significant increase in the memory footprint for the same workloads. Through our investigations we found that a large contributing factor to the increase in RSS was an increase in THP usage. For workloads like MySQL, or when using allocators like jemalloc, it is often recommended to set /transparent_hugepages/enabled=never. This is in part due to performance degradations and increased memory waste. This series introduces enabled=defer, this setting acts as a middle ground between always and madvise. If the mapping is MADV_HUGEPAGE, the page fault handler will act normally, making a hugepage if possible. If the allocation is not MADV_HUGEPAGE, then the page fault handler will default to the base size allocation. The caveat is that khugepaged can still operate on pages thats not MADV_HUGEPAGE. This allows for two things... one, applications specifically designed to use hugepages will get them, and two, applications that don't use hugepages can still benefit from them without aggressively inserting THPs at every possible chance. This curbs the memory waste, and defers the use of hugepages to khugepaged. Khugepaged can then scan the memory for eligible collapsing. Admins may want to lower max_ptes_none, if not, khugepaged may aggressively collapse single allocations into hugepages. RFC note ========== Im not sure if im missing anything related to the mTHP changes. I think now that we have hugepage_pmd_enabled in commit 00f58104202c ("mm: fix khugepaged activation policy") everything should work as expected. Nico Pache (2): mm: defer THP insertion to khugepaged mm: document transparent_hugepage=defer usage Documentation/admin-guide/mm/transhuge.rst | 18 ++++++++++--- include/linux/huge_mm.h | 15 +++++++++-- mm/huge_memory.c | 31 +++++++++++++++++++--- 3 files changed, 55 insertions(+), 9 deletions(-) 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