Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2959848rdb; Mon, 4 Dec 2023 12:16:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrk+g91ZLuZ//6uLbGxI7hBiLJXUIBrk9ge/ilisanszE9x1ZtDAa4y1pjKvzUfgkmAMk4 X-Received: by 2002:a17:902:e843:b0:1cf:d24c:7b6c with SMTP id t3-20020a170902e84300b001cfd24c7b6cmr2552245plg.59.1701720974535; Mon, 04 Dec 2023 12:16:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701720974; cv=none; d=google.com; s=arc-20160816; b=QRSomQ/fP3kiH2O+10T/mqMETENII1/sLrQGvx/kEuaAhgsOPZdAOKi+OZIjsuhPnJ BO7g52UlGFZxMt9cM7QHYRObJ4fkINYyMokqlxNwqnalHoIE39gpatvvPtdWviDSfMKW FmKeaQ9wFH9eaknH6EJOMZc+Pl9xHDr6ToRm+dX2ZDV3Nsm+hMgW+O2Klkdvcd+aSD6B ktNBv8UE0BPlP3tb4xhBbTT0AiDoAmfDSWsrus5CBjvVwqFp6i1QMMDkDCj4PsumZDXO 41NF580S8NTE7Iv9RDqmdQDMpz174+vrdYEX/nR8YCbFQbm99Gnmg2rfZQFc1EHXg+aG SXJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=j4a2keWogdso4fUlAgHqKHIlC0vOWbd1pKMDRnrrrAI=; fh=8Aiet1oUCkdewLrEIm7OPIwcR//OAak49L25sYh/5WI=; b=zO7hZPmFrSQ969WAOjHb69TqEkWfUPrR2LJeZkVgZzLKvHyWFow7TIuvbR+LwHnfPz 8r8q4NoV69Fr1RJ0GNDe5ottegx/RXTAKVeOXsGQ+3ubcED5idnD5Oc9zId9L7RrDXRe Q3K9KnONWYYfIaoMzS89LPbe7+orsgqdI1OQZChS9Nrnaa8mKZlV/7QeqKWZd+2kk4nA Bmjl9aj7U4cZk5iA0tj4bNHmWfpyGYZxtf/BBLHFu+GcED2YYfPYxAtVgHQ3csoslZ/0 g/Dp+nPX7ibm//2vkWBUxIDOvQmd5LO9pwYLbZgbMp3gnrUOKKl7IL6Glm0hlh/m2/CK REbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=pvZROeSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y18-20020a170902d65200b001cfb52ebfdbsi3441236plh.152.2023.12.04.12.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=pvZROeSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 31C9180784E5; Mon, 4 Dec 2023 12:15:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233626AbjLDUPU (ORCPT + 99 others); Mon, 4 Dec 2023 15:15:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjLDUPT (ORCPT ); Mon, 4 Dec 2023 15:15:19 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86272D2 for ; Mon, 4 Dec 2023 12:15:25 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E85EDC433C7; Mon, 4 Dec 2023 20:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1701720925; bh=Oa+AKNnfNJKYaj5c5DLXMZSQbG2uQbsRvEdWdjOKPxE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pvZROeSiPwT0U9Ds4tzHhAfzYiGa8TlQ8YX3RHsa7xnOqpQNt6rX2SdCG53uQ0Ax5 rOE+cr/D7DDykyuEdJQg3wsmj56gubbWf+APhs1arrAJqJW/sGzZf4Za3UVDl/kORY WDvtLe1kGvWVrHW+rMQ4ZMZ9H2Tr/8IFN3pQAx/E= Date: Mon, 4 Dec 2023 12:15:24 -0800 From: Andrew Morton To: Dmytro Maluka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/thp: add CONFIG_TRANSPARENT_HUGEPAGE_NEVER option Message-Id: <20231204121524.dfa9f98e809c91b353968d34@linux-foundation.org> In-Reply-To: References: <20231204163254.2636289-1-dmaluka@chromium.org> <20231204111301.7e087b2f851b30121561e8fc@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 12:15:36 -0800 (PST) On Mon, 4 Dec 2023 20:57:33 +0100 Dmytro Maluka wrote: > On Mon, Dec 04, 2023 at 11:13:01AM -0800, Andrew Morton wrote: > > On Mon, 4 Dec 2023 17:32:54 +0100 Dmytro Maluka wrote: > > > > > Add an option to disable transparent hugepages by default, in line with > > > the existing transparent_hugepage=never command line setting. > > > > > > Rationale: khugepaged has its own non-negligible memory cost even if it > > > is not used by any applications, since it bumps up vm.min_free_kbytes to > > > its own required minimum in set_recommended_min_free_kbytes(). For > > > example, on a machine with 4GB RAM, with 3 mm zones and pageblock_order > > > == MAX_ORDER, starting khugepaged causes vm.min_free_kbytes increase > > > from 8MB to 132MB. > > > > > > So if we use THP on machines with e.g. >=8GB of memory for better > > > performance, but avoid using it on lower-memory machines to avoid its > > > memory overhead, then for the same reason we also want to avoid even > > > starting khugepaged on those <8GB machines. So with > > > CONFIG_TRANSPARENT_HUGEPAGE_NEVER we can use the same kernel image on > > > both >=8GB and <8GB machines, with THP support enabled but khugepaged > > > not started by default. The userspace can then decide to enable THP > > > (i.e. start khugepaged) via sysfs if needed, based on the total amount > > > of memory. > > > > > > This could also be achieved with the existing transparent_hugepage=never > > > setting in the kernel command line instead. But it seems cleaner to > > > avoid tweaking the command line for such a basic setting. > > > > > > P.S. I see that CONFIG_TRANSPARENT_HUGEPAGE_NEVER was already proposed > > > in the past [1] but without an explanation of the purpose. > > > > > > ... > > > > > > --- a/mm/Kconfig > > > +++ b/mm/Kconfig > > > @@ -859,6 +859,12 @@ choice > > > madvise(MADV_HUGEPAGE) but it won't risk to increase the > > > memory footprint of applications without a guaranteed > > > benefit. > > > + > > > + config TRANSPARENT_HUGEPAGE_NEVER > > > + bool "never" > > > + help > > > + Disabling Transparent Hugepage by default. It can still be > > > > s/Disabling/Disable/ > > It is in line with the descriptions of TRANSPARENT_HUGEPAGE_ALWAYS and > TRANSPARENT_HUGEPAGE_MADVISE: "Enabling Transparent Hugepage ..." Those are incorrect also. > > > + enabled at runtime via sysfs. > > > endchoice > > > > The patch adds the config option but doesn't use it? > > I should have been more precise: it is not a new option but a new choice > for CONFIG_TRANSPARENT_HUGEPAGE, in addition to the existing ALWAYS and > MADVISE choices. In mm/huge_memory.c in the declaration of the > transparent_hugepage_flags variable, if either ALWAYS or MADVISE is > chosen, transparent_hugepage_flags is initialized with such a value > that makes khugepaged being started by default during bootup. This patch > allows enabling CONFIG_TRANSPARENT_HUGEPAGE without setting either > ALWAYS or MADVISE, so that transparent_hugepage_flags is initialized > with such a value that khugepaged is not started by default. OK, thanks.