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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FC31C30653 for ; Thu, 4 Jul 2024 18:33:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD3276B00B7; Thu, 4 Jul 2024 14:33:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C82828D0001; Thu, 4 Jul 2024 14:33:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B49FD6B00B9; Thu, 4 Jul 2024 14:33:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 94D776B00B7 for ; Thu, 4 Jul 2024 14:33:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0F2A41C2D11 for ; Thu, 4 Jul 2024 18:33:34 +0000 (UTC) X-FDA: 82302918348.22.B7098F7 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id 811DD80009 for ; Thu, 4 Jul 2024 18:33:31 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="Es/ggW1u"; spf=pass (imf02.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720117993; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eODGqcH2zA7MoD8Dq2ygYVhqwlTl4R5IzQxlZiztT4g=; b=FFK1e8xkpBSvgdAfaKhnkdyKqB6qMJdp9g3+bBPe/3oI/epx++Dfc73cE5pjiBS7RzpC7n zNDjAUrCGFTPNNowc/BW3xLnI+bb8L9qKpHccwdfhyvBErHrRTVK00PNYVmdqLnz92naFk AzUzmerUdvTosKNwBy5v/J61krnpRJk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="Es/ggW1u"; spf=pass (imf02.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720117993; a=rsa-sha256; cv=none; b=CaQEyl6YrNKwNUT44ivaeXpxc1lNoDJsDEQeTYNv0JqOXQPeYG+4cPok9KNxp46gkmhhEi 69s1pfVbZS6zvghRzheCp0Dy2GDxZaTg6uv8a7XFVETvNNy1A2IZfuJJEn+R+s2OLYxrjI euKWXzWLp1YJn5X1SpOwDLpw812DLFg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 237DECE0F21; Thu, 4 Jul 2024 18:33:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BFD7C32781; Thu, 4 Jul 2024 18:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1720118006; bh=n5vgE0QBrC52K5xATWxIIUbE1yzT0GmtkrWhx/yuFcI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Es/ggW1umo66oQkkL0ypdYkxmji4n0MTAf8J911bD5JIYCP388YbAzjj1veEYZzE1 As62lY8KptoorRGkmPYnLWAOodFcR9OfmR8xtSVkZQS7/3iDQN91zAJYze/VzWjB8A q2KrM9pftFAhx7y+Q4HGb7uw8GEAYjSsJ0sR1Xfk= Date: Thu, 4 Jul 2024 11:33:25 -0700 From: Andrew Morton To: Ryan Roberts Cc: Jonathan Corbet , David Hildenbrand , Barry Song , Baolin Wang , Lance Yang , Yang Shi , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm: Fix khugepaged activation policy Message-Id: <20240704113325.fb9f1b04f99abaac315b5c88@linux-foundation.org> In-Reply-To: <20240704091051.2411934-1-ryan.roberts@arm.com> References: <20240704091051.2411934-1-ryan.roberts@arm.com> 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-Stat-Signature: o453tnbt5u1m7u65is5idtc3mahr53jw X-Rspam-User: X-Rspamd-Queue-Id: 811DD80009 X-Rspamd-Server: rspam02 X-HE-Tag: 1720118011-507618 X-HE-Meta: U2FsdGVkX1+AikkypIDTJhmHtFmcbzXr5s8fpPaBYMMaLEImYcDQ1YN3twsmN62N9chuLnaaUNIp5bUrJ+vuSft12VFaoFhw11R44zprahlZDCUEg7UW0hlsn1NnHNRDWUfm9HoZgFXAKTunxWGhqq8V6euPL0Ex/wbsdIoPZJlKhoPmdZXs7qjK6rpknnqfb3Dq80gDczoncD7S42+3ruKooqz88M3NwaNdd4QgMFNEwMHw+4hzA3XOGeXf3FoLoSpe8oefiqTukJeqSA7eYCHFvRX4LSgNC1+TPwWUSX4tQ6cnUZ1BUCzVYpK1DomWpEeS1o61w0BkcIxO6ud31Y8nPu9WEMzkzhIyznryTpfua6rWxGaLrvLgW6BEE4R9D6ya1Xuk0ebYp0lDgE74bUKHhaQubKfLlIHaixx3f0S/jiA/wbM8BFD+V1wslZ2fXYxmNN+YFu6sOLfuZNvJaQTftTKPDjBAag4KUj0j1mCUtmcefoNn6Yr2WUiZHUJmV0FlxysGDwe/BGW6SIOqqJgIaVssUxj4TZmVGEerPVUDcDUOtDCT093NhiA62Zt8tJDDAJm7Ts4psDv0iBQ28jQquUo/B3G2EEGbiZOXvUimhniJX61n1/c7pcWXFmJ56504UkyLKAXSxbpNCc+6MieO33N/tOLu2/sGl8B3OIb9gu/8+eQJhBY/Q1YmJ0UMDDv8z3qR/nlUy0YGGq0Qd2KjPAiSt7OxUQo24+hD2uDJ3uXwlD7A19CGq3ps0d6lsytGRxgdSM5Bdr6fKTVis7pWzWH+4/5AK3PgCBihfq7t2DY1J62gv2kO3TTlO+DSIfI72lkWgdCjVoH4aywlroBvMIn1340UMqjX9LHJmYA8UeO7hg6b8NEIQoZXBSY8weebtdxKAASl2EAvjyBm/RUC6Fq9gYZakVrhKu4c6M9DKdCv1RAM2z9Ut6I5xdTrI0/llQjDgZZQRvaKung VYokmG1n A0q3H/Jbt1cb+fVvJMyCfWmjFnWYNkxUQI5HvjrY4iT5zMP4wZJ7qEUfVqlCf0Lbd+R/8o3Zwt62O2cRHPZOlhopgjtmiimmVEzkaqXf6Z8e5IGxWr3L4HuVVrs2+X/lH9c6B93bsRV1hQc+oN8XEVRmW+MxyPaLUms6SMBZg/9fUzrBJx8j9JlcbGuCVuAJLgfgjCcFYSGdxFTf3TEFHZrJG+3NJVi6SJRp60KUjIUpUJDXxMxfLW4dOEVn5RvHDW+uOzNYqlhvmjcGK322+Q6r1wrPJTFIS1kHtqX2S2tOLi6zz/I95hUUaYoTnpJwd2DlJ 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: On Thu, 4 Jul 2024 10:10:50 +0100 Ryan Roberts wrote: > Since the introduction of mTHP, the docuementation has stated that > khugepaged would be enabled when any mTHP size is enabled, and disabled > when all mTHP sizes are disabled. There are 2 problems with this; 1. > this is not what was implemented by the code and 2. this is not the > desirable behavior. > > Desirable behavior is for khugepaged to be enabled when any PMD-sized > THP is enabled, anon or file. (Note that file THP is still controlled by > the top-level control so we must always consider that, as well as the > PMD-size mTHP control for anon). khugepaged only supports collapsing to > PMD-sized THP so there is no value in enabling it when PMD-sized THP is > disabled. So let's change the code and documentation to reflect this > policy. > > Further, per-size enabled control modification events were not > previously forwarded to khugepaged to give it an opportunity to start or > stop. Consequently the following was resulting in khugepaged eroneously > not being activated: > > echo never > /sys/kernel/mm/transparent_hugepage/enabled > echo always > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled > > ... > > -static inline bool hugepage_flags_enabled(void) > +static inline bool hugepage_pmd_enabled(void) > { > /* > - * We cover both the anon and the file-backed case here; we must return > - * true if globally enabled, even when all anon sizes are set to never. > - * So we don't need to look at huge_anon_orders_inherit. > + * We cover both the anon and the file-backed case here; file-backed > + * hugepages, when configured in, are determined by the global control. > + * Anon pmd-sized hugepages are determined by the pmd-size control. > */ > - return hugepage_global_enabled() || > - READ_ONCE(huge_anon_orders_always) || > - READ_ONCE(huge_anon_orders_madvise); > + return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && hugepage_global_enabled()) || > + test_bit(PMD_ORDER, &huge_anon_orders_always) || > + test_bit(PMD_ORDER, &huge_anon_orders_madvise) || > + (test_bit(PMD_ORDER, &huge_anon_orders_inherit) && hugepage_global_enabled()); > } That's rather a mouthful. Is this nicer? static inline bool hugepage_pmd_enabled(void) { /* * We cover both the anon and the file-backed case here; file-backed * hugepages, when configured in, are determined by the global control. * Anon pmd-sized hugepages are determined by the pmd-size control. */ if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && hugepage_global_enabled()) return true; if (test_bit(PMD_ORDER, &huge_anon_orders_always)) return true; if (test_bit(PMD_ORDER, &huge_anon_orders_madvise)) return true; if (test_bit(PMD_ORDER, &huge_anon_orders_inherit) && hugepage_global_enabled()) return true; return false; } Also, that's a pretty large function to be inlined. It could be a non-inline function static to khugepaged.c. But I suppose that's a separate patch.