Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1197210pxb; Mon, 11 Oct 2021 00:03:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjxo/nAUTFwHlk/qp+poihrjRIOk81eq2wbxR89KE8BjfE/ZgSRZb68wlLbsP8iLhz2pKe X-Received: by 2002:a17:906:c2ca:: with SMTP id ch10mr24096654ejb.311.1633935783354; Mon, 11 Oct 2021 00:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633935783; cv=none; d=google.com; s=arc-20160816; b=hxKCaqLlmj9lD2v0MtqzmThV75nMYQmlstaccfqd6H3FkuKfAFfAVekOZ7cyrQmDYp onzbPQb30njD74zWO6ilw/mLgDUOIN2reuB9+5s8QTGpqqjB8x37Ov1YT3btIZ7Am2o0 03sQo3r4fOZTdk3Vf4F7rxzViLO3Cu4U08gJAWKgEirqI1AbqMClEaeHdp7cJWJ3V35X HtvHpfYqTHe3RH1iKGjsbnO0qURYedskAxn+cnUFyl0fd71vsCVhfUV8iKOFGTRKoYUM RMTKZxDngfQ6dZXN97yYItrCsNncIlJX8hQK5TVGDvat2PvIVNj4J3Q7aLxseRCUnVxW pZjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hm/WnPjACRBoXScfbY0rQ9zM9UXlZisRQsmhTz6cU6o=; b=z5ACWwXIQeA29E3UQqSNrQsd9Qavl+2vPa39F756oW86fHJ0IejoPcIN/aZRL7SRR9 wlbQYjo6Orzhz8mroABrd1JhxN51ZYi1uf+OUyXy31AqXzImLblphpGex43caq+N0xOi mQE9j+9xBI2DCyD12WjIuccAbZiXUsBDo8UzbjWoPOTX0qoSGTHsoc1wJQ7AHgJ8/fHS wlTzIkJhdwDtB1kkVIZRdFZCU/BRXPx0pCJO8m11xl0hEiAXCyNCHkOKOsTRlBL7R8Mq WLnVJgSJg2WhhcO4Bo+pUVzLxpZcVKiDJm0OOvIEMKqXcx6G37hqqeYCTFtZYZvR4ipA Bvzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="NoJf0g/i"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si11519557ejc.492.2021.10.11.00.01.54; Mon, 11 Oct 2021 00:03:03 -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=@gmail.com header.s=20210112 header.b="NoJf0g/i"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbhJKD6Z (ORCPT + 99 others); Sun, 10 Oct 2021 23:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbhJKD6Y (ORCPT ); Sun, 10 Oct 2021 23:58:24 -0400 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11702C061570 for ; Sun, 10 Oct 2021 20:56:25 -0700 (PDT) Received: by mail-vs1-xe35.google.com with SMTP id i7so288211vsm.4 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=hrWARTj2A/QcSGGGNffs9ZZKmRbkl2kgjGQ9c+rWzE30H7wU/+Xd6lpsvgNUWgBrnI ASP1gyllZUn+xKJdaV+LYiCsQIfER8t0ERUnmm7PJTku7ZOZ6FpAF/j6d6Uh6I65PzUe ByecJHnWXtndVGdJX3hcAg/bAvHg7xhkfufewuBA8dSOjS+RGblLkWj7leCBWK1gQBkz XGaaF86P7QfOsCr+L4Ew+kc+nyjq6WPgl9x1Sx9y0QAX+55XAjGeGVdaH7GQiqbkzpx3 XocOOJt5CxzXKPzyK+HJL2U+dGJyq8OttpGKzyl5KD0ccPLuImF0cQ+efenUTAuLAp6J DN+w== X-Gm-Message-State: AOAM532jvd1C9BUQAmcB8BccL1jOH5l/MyciOFpOXQQII6vv5AYTMMnp vVrOnPYzBRe+KbGHblYKNBHv6sjysf2nWdS7C8s= 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. >