Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1018783pxb; Sun, 10 Oct 2021 18:11:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ0YPU96rOqctLUxz8PWumFxtkBFHpKpJD82Fhm6gA/0wPo7c2Yvh84/loWr5Zjot/vB4R X-Received: by 2002:a17:906:b183:: with SMTP id w3mr21755292ejy.394.1633914716863; Sun, 10 Oct 2021 18:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633914716; cv=none; d=google.com; s=arc-20160816; b=YsxxmR+jYNv9wqxEEfbxjo4B1hlPHzQo2c6XydpwFn1H1gc0kwkZSWKuUjpUoD3tNQ QqvzEMqBgj8M5yOqjF26GZPA3WZ0AgUtHZcX+Oya9UMWz5+wsJU892VmWMKpwcs618pz S98kCoiKxyOXEguvbNoAclF2lyxZ4a1S812GM2fUg/a8Z+hODlw14DPWGTZxiZM3iqWg QUbi8DcfQSzOZbbnapEvnx+23UzZHjnYdWz1+lOBocRHZ1bDtHXbo3ngGWX4A2bzKhz+ NM1O0RSCbTu2oPRKYQ8upOkJja0qTJ8Av2DkvBmCXFQgQb8xSkxDeuVVOIEKwQZJZ+uZ yZnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=wIBUW6zc6MUbXhHNaYoyVQ0gurfpKZ2/JrmRwbRJyjw=; b=BDKN+CzqKN7BiSvbtUaxVVFUH5LryQ0yQBb2coPGJCSf7Aun6E7YHYC7CyYJu6o8CV s/f9d5Nbn4P6pDY8MIuIJc7CNeBOXaSojepXwN78J715nY8p3Hxk1F0HD9KwGaYICgqC ZoF/N+/4MyVpzz8AI3qImZ2u06aqijInssCUMAxCkefTwNA7f1THs30e042AaQAtFLKk rCy4hdC2KCXqnmD9JwKUyYQxK73/juwwdE0iX701KdRgbzXT6FdzypS7A/WfWvfyfmg5 rhVGFgo06oKM3VEMt1M0Yt56kCi0Mep92s9ycpyt/z7atiCj3HTMCYruYzJifDgHDoOl jgbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Cq3SX6S5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si9256633ejj.369.2021.10.10.18.11.23; Sun, 10 Oct 2021 18:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Cq3SX6S5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233042AbhJJWpz (ORCPT + 99 others); Sun, 10 Oct 2021 18:45:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232586AbhJJWpz (ORCPT ); Sun, 10 Oct 2021 18:45:55 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C438C061570 for ; Sun, 10 Oct 2021 15:43:56 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 75so9015468pga.3 for ; Sun, 10 Oct 2021 15:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=wIBUW6zc6MUbXhHNaYoyVQ0gurfpKZ2/JrmRwbRJyjw=; b=Cq3SX6S5HlMNcDmorjSLbAWhkIOGV1dZn6r/k2GUH4TzkYiBXzAr2jhidjKet5xBGP Q6KXRzwqvatmTMzuy7LjqSUZUM2rjRekZ1JtSfsAvbV67uAuFXpqXjr5QZf0Tr8Y4rL+ hAj1rsokigc3Y2l3z8ieVfpZ70nqwmErdxfbO43WoJYVxnF459Fh1a+dgqW9ybvuKKGg G9Mwgdq4gma9bs612jYAQXB5IEluHUGQ/OqxbZt9nMCgH9jdUM2QtWQ5I8+IuBhy3n0s eheA4hU2iSTpnvL8aqYgJZZirj4/GHdYYa383MSpHuQfPkf/AfHknETN1giEPqKrv0E2 H77Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=wIBUW6zc6MUbXhHNaYoyVQ0gurfpKZ2/JrmRwbRJyjw=; b=p3rbb1XuWAYVnOr5hD3l5u6SHWWo+wB6uPA8zZe23cWuFyhZ5mUxopxIQhPxMEpd3y mKS+n+1jd7b7pxdywMJLx5Y7ET5LrwBhzSgf+ea3KcCqhKHXZhoREeGieBjKbHYicrYI wIoJBHihonazhRxj4IhfVnsEf69K6o3NKN5HVIgLUNme3bqrWbE5JuxjNwXeYltTc/0D hRWW+6F24A/LYti3f/3mbVZpkM6ZMqcIgardunF9M+ZVjgECqyoyFnD1Aauoee5UJ6+f xKbNJqnep1HFL2wSER/PFAlnYjbT7W/dNTn2jWYOFZjtw+2M0ZicDGi1QjP8d4Z+HWMS ZmdA== X-Gm-Message-State: AOAM532HZC48thKrDmYHRhkIF2TqDywq990Yo2Uce0iRlJ14ShRf0hlD RSZ1FPADnP1qby/g12uZDI6IlA== X-Received: by 2002:a63:4f:: with SMTP id 76mr15353398pga.457.1633905835385; Sun, 10 Oct 2021 15:43:55 -0700 (PDT) Received: from [2620:15c:17:3:3280:1d46:7d55:1fbb] ([2620:15c:17:3:3280:1d46:7d55:1fbb]) by smtp.gmail.com with ESMTPSA id z11sm5398218pfk.204.2021.10.10.15.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Oct 2021 15:43:54 -0700 (PDT) Date: Sun, 10 Oct 2021 15:43:53 -0700 (PDT) From: David Rientjes To: Hao Peng cc: "Kirill A. Shutemov" , David Hildenbrand , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm/huge_memory.c: disable THP with large THP size on small present memory In-Reply-To: Message-ID: References: <20211008095123.73b4bubwrpdj6tuz@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 9 Oct 2021, Hao Peng wrote: > > > After setting the page size to 64k on ARM64, the supported huge page > > > size is 512M and 1TB. Therefore, if the thp is enabled, the size > > > of the thp is 512M. But if THP is enabled, min_free_kbytes will > > > be recalculated. At this time, min_free_kbytes is calculated based > > > on the size of THP. > > > > > > On an arm64 server with 64G memory, the page size is 64k, with thp > > > enabled. > > > cat /proc/sys/vm/min_free_kbytes > > > 3335104 > > > > > > Therefore, when judging whether to enable THP by default, consider > > > the size of thp. > > > > > > V2: title suggested by David Hildenbrand > > > > > > Signed-off-by: Peng Hao > > > --- > > > mm/huge_memory.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > > index 5e9ef0fc261e..03c7f571b3ae 100644 > > > --- a/mm/huge_memory.c > > > +++ b/mm/huge_memory.c > > > @@ -437,7 +437,7 @@ static int __init hugepage_init(void) > > > * where the extra memory used could hurt more than TLB overhead > > > * is likely to save. The admin can still enable it through /sys. > > > */ > > > - if (totalram_pages() < (512 << (20 - PAGE_SHIFT))) { > > > + if (totalram_pages() < (512 << (HPAGE_PMD_SHIFT - PAGE_SHIFT))) { > > > > On x86-64 HPAGE_PMD_SHIFT is 21, so you double the amount of memory > > required to enabled THP by default. It doesn't seem to be the intent of > > the patch. > > > > What about something like > > > > if (totalram_pages() < 256 * HPAGE_PMD_NR) > > > > ? > > > I think that setting the threshold to 512M here is also a rough > estimate. If it is 512M > of memory and 2M of THP is used, there are only 256 pages in total. > This is actually > too small. So does this mean that the original intent of the patch is what you proposed? It's not discussed in the changelog so it's unclear. The "extra memory used could hurt more..." statement in the comment depends on other system-wide settings like max_ptes_none and whether you default to faulting hugepages if eligible. There are scenarios where there is no extra memory used, so I think the intent is for sane default behavior and, as you mention, it can always be enabled at runtime as well. By using 64KB native page sizes on small memory capacity systems, you're already opting into this memory bloat. If we are trying to avoid memory bloat then we likely shouldn't be defaulting max_ptes_none to 511 either and that would be a bigger consideration than a minimum memory capacity to enable thp. Or maybe you are questioning the adjustment to min_free_kbytes and whether that is rational or not for small machine sizes (but large page sizes). > In addition, THP is disabled by default, but you can also enable THP > dynamically. > Thanks.