From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B47C433FE for ; Mon, 11 Oct 2021 03:56:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0515E60F38 for ; Mon, 11 Oct 2021 03:56:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0515E60F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 69B206B006C; Sun, 10 Oct 2021 23:56:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64AE86B0071; Sun, 10 Oct 2021 23:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 513136B0072; Sun, 10 Oct 2021 23:56:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 419826B006C for ; Sun, 10 Oct 2021 23:56:25 -0400 (EDT) Received: from smtpin34.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id ED76A1811CE5E for ; Mon, 11 Oct 2021 03:56:24 +0000 (UTC) X-FDA: 78682794288.34.0ECD9B4 Received: from mail-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) by imf16.hostedemail.com (Postfix) with ESMTP id 9A434F00236E for ; Mon, 11 Oct 2021 03:56:24 +0000 (UTC) Received: by mail-vs1-f54.google.com with SMTP id j22so2508608vsl.5 for ; Sun, 10 Oct 2021 20:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hm/WnPjACRBoXScfbY0rQ9zM9UXlZisRQsmhTz6cU6o=; b=NoJf0g/i/EvNgprP5JthR3UA1KqGONFpUy/5x+DhivykLN5l0jCd5xucAoiKuGMtlj 1esRKukL5+qMFwAD3s8JLv4dyBintdVA1qWN/37qCJWo03eXayAUGRhAsOh4QKcJe3IY O81MlB9w+DvTDWVe4y7ybit5SIb4vCTFD6BAIWVZswck6kRo7G1QkteU8cSFbiMoF04/ y2WLC9dqj6ka9lkxiQ68OIOV/ArRx/D+L8SJbsrA0WEJrE51vYOlGGHwC5Rv6wobQ6Jp JjJkRvYhXs5sEsoSwA6nV+dPv+svBSAkBM50kfZqC0eTkz1OSN58aVJjAuOk2Rohkhoj cQyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hm/WnPjACRBoXScfbY0rQ9zM9UXlZisRQsmhTz6cU6o=; b=2ibDWb2XeUp9/Thq4uduJaSEDqkhf00LwQ7yWhJzQuaLGIqEsHMIhChikY2olMMn6t b4LVFNaMGTSRDu4gDvvmJ9Rd73K3N3sEnCVXRvPMf3zJ0kt6o7SO7M5RMKv7YKbRNY2E VpKT/n7BhZLB+hFPBa5swag2n0WKrbp+He/s+5fVybF5xtuD8T8/TDBdn6KXPqOXSJlN R49sQCgsr0m8KWwOvLF5+/2dOpKGHhsMyx9HOlELXQ7ZZ9m2dyiMtuV1A+2uTywu/vmA n/hek/MshMGiGHnjAzgW/xjyx/hYr/3LAb9kSmvVY506FXo+5HYsdb3zZqhdM3TZZYH+ xrJw== X-Gm-Message-State: AOAM533BjNnrJZt6ph1ZpEe4NlsoyfViNZb40kgK7+asW/amQ1YV9O4/ 9T/UKqUyVBKr3rxm1UF3qFdMn95CSIIxmqK+UXo= X-Google-Smtp-Source: ABdhPJwnwkAkJ1q/wmyPmrl6FYjETg+oftnturOvq1SlZkbfBqz+4zN1f0ODqYkUFzRtNZHipE0d3p+CxoXOFaRJkPo= X-Received: by 2002:a67:dc0c:: with SMTP id x12mr1008048vsj.17.1633924583922; Sun, 10 Oct 2021 20:56:23 -0700 (PDT) MIME-Version: 1.0 References: <20211008095123.73b4bubwrpdj6tuz@box.shutemov.name> In-Reply-To: From: Hao Peng Date: Mon, 11 Oct 2021 11:55:52 +0800 Message-ID: Subject: Re: [PATCH v2] mm/huge_memory.c: disable THP with large THP size on small present memory To: David Rientjes Cc: "Kirill A. Shutemov" , David Hildenbrand , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9A434F00236E X-Stat-Signature: 8t7s3p7kgiyuhqow3f3auoaqi84j3f4g Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="NoJf0g/i"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of flyingpenghao@gmail.com designates 209.85.217.54 as permitted sender) smtp.mailfrom=flyingpenghao@gmail.com X-HE-Tag: 1633924584-349314 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: On Mon, Oct 11, 2021 at 6:43 AM David Rientjes wrote: > > 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. > I have considered this point, but I think the initial threshold is only a rough estimate. And THP can be enabled at runtime, so this threshold does not need to be accurate. > 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 it is on an arm64 machine with a small memory system, such as a mobile phone, it generally uses 4KB native page size, so the page size of THP is 2MB. > 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). > The main reason for my modification is that excessively large THP page size may make min_free_kbytes too large when enabled, especially on systems without swap that easily trigger OOM. > > In addition, THP is disabled by default, but you can also enable THP > > dynamically. > > Thanks. >