Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4272159pxu; Mon, 12 Oct 2020 14:28:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGHRCPifgQK39FOA/x0zbLuVCVZAcKVTognvgT3pUDrvHFZXY9Pf1TW7kqvjY/lP5sbK+p X-Received: by 2002:a05:6402:395:: with SMTP id o21mr16369762edv.2.1602538123953; Mon, 12 Oct 2020 14:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602538123; cv=none; d=google.com; s=arc-20160816; b=loUsyC8LxORjk/zQPYW6MSd3i7F99MEeD3FLxj8ZIvUHMGTbEvXacDNh0LxbbG2ulY WcvhIg6hYEmf5h85oKtmczZb2oGlsZncQ6R5M0rMXF9g+/nYgKmhj9k0kjMA9ZkplS+c ytGd+2yoCX2wZ/UsJSs+uYtBuACKzFp5BQbJnRT7WJV8l2jUf9CAr3OIzvIQ3xsMNc+2 i2cbBJyJNnI7hT8lKjGM2lLWf6QjwQTlWEIfBD6NYwhDX0CMTfEVxNC1EtYkTNb5ZfRz kgO4WfFg+Mz4OQGY3x+UVrBSbLdZHHw7UGXfnk+ZFWA2eSd43xBYNQgt7WYTImCrHBzu d8ZA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=10B0FcinwVZlQ10jv4fXy0rYMXx3bIO0m3kirtwIaSA=; b=JFwDOdjofAVome9A5C1R8BbxfNhFqXIzvrzDPKA5ihL3B8I2yTjPclo3PML4Mq0tdB Q8VYIxLPlLOtpSTBtHh3AWRidAIqykMUGVk8wwonqYzDc7ZoVKybAfwm0XikDaRYkQWy m4VIIwlOITg2uSfncJfXfD3z+fs2yCOJVdSowTm9lOBnNTl+QS+4uPj8PXzc3xjB1xQr mwdii2bPoMnYqPc8II6Ue21GpWjizaFzZxg+otp+gJvsIsE0FbyiR8QaIcrRCO5bxKlU NtUADBJjuBRCGtYNO805gxSLm3QKIccGhd8jkRso4sI0fWjzvEjzvqpCiuicA4lNwu+U Xwxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Y+/c2VCc"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si13556072edl.534.2020.10.12.14.28.21; Mon, 12 Oct 2020 14:28:43 -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=@kernel.org header.s=default header.b="Y+/c2VCc"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730858AbgJLNg4 (ORCPT + 99 others); Mon, 12 Oct 2020 09:36:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730833AbgJLNfi (ORCPT ); Mon, 12 Oct 2020 09:35:38 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 459572222C; Mon, 12 Oct 2020 13:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509730; bh=fmW3+WNtypgBnhzxFnE4Gy7I1zsUGl/9BllpV+I2avY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y+/c2VCczErs85Fq7FVbIDAtozvA26/rLmeqJEle2ZqX9on0YfhAyQnG9tSg6bqH9 5aGV8tIcETAGBOHDA33WzAAy4voRYNjisD7nQIuuY9MQkQvJfNij/hIx7oMrLjRZK6 TzIB5MOQ2xOh8SE1L7qYgnMefV6eW0zlaG9S7f9w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vijay Balakrishna , Andrew Morton , Pavel Tatashin , Michal Hocko , Allen Pais , Andrea Arcangeli , "Kirill A. Shutemov" , Oleg Nesterov , Song Liu , Linus Torvalds Subject: [PATCH 4.9 53/54] mm: khugepaged: recalculate min_free_kbytes after memory hotplug as expected by khugepaged Date: Mon, 12 Oct 2020 15:27:15 +0200 Message-Id: <20201012132632.029610828@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132629.585664421@linuxfoundation.org> References: <20201012132629.585664421@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vijay Balakrishna commit 4aab2be0983031a05cb4a19696c9da5749523426 upstream. When memory is hotplug added or removed the min_free_kbytes should be recalculated based on what is expected by khugepaged. Currently after hotplug, min_free_kbytes will be set to a lower default and higher default set when THP enabled is lost. This change restores min_free_kbytes as expected for THP consumers. [vijayb@linux.microsoft.com: v5] Link: https://lkml.kernel.org/r/1601398153-5517-1-git-send-email-vijayb@linux.microsoft.com Fixes: f000565adb77 ("thp: set recommended min free kbytes") Signed-off-by: Vijay Balakrishna Signed-off-by: Andrew Morton Reviewed-by: Pavel Tatashin Acked-by: Michal Hocko Cc: Allen Pais Cc: Andrea Arcangeli Cc: "Kirill A. Shutemov" Cc: Oleg Nesterov Cc: Song Liu Cc: Link: https://lkml.kernel.org/r/1600305709-2319-2-git-send-email-vijayb@linux.microsoft.com Link: https://lkml.kernel.org/r/1600204258-13683-1-git-send-email-vijayb@linux.microsoft.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/khugepaged.h | 5 +++++ mm/khugepaged.c | 13 +++++++++++-- mm/page_alloc.c | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -13,6 +13,7 @@ extern int __khugepaged_enter(struct mm_ extern void __khugepaged_exit(struct mm_struct *mm); extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long vm_flags); +extern void khugepaged_min_free_kbytes_update(void); #define khugepaged_enabled() \ (transparent_hugepage_flags & \ @@ -70,6 +71,10 @@ static inline int khugepaged_enter_vma_m { return 0; } + +static inline void khugepaged_min_free_kbytes_update(void) +{ +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_KHUGEPAGED_H */ --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -50,6 +50,9 @@ enum scan_result { #define CREATE_TRACE_POINTS #include +static struct task_struct *khugepaged_thread __read_mostly; +static DEFINE_MUTEX(khugepaged_mutex); + /* default scan 8*512 pte (or vmas) every 30 second */ static unsigned int khugepaged_pages_to_scan __read_mostly; static unsigned int khugepaged_pages_collapsed; @@ -1948,8 +1951,6 @@ static void set_recommended_min_free_kby int start_stop_khugepaged(void) { - static struct task_struct *khugepaged_thread __read_mostly; - static DEFINE_MUTEX(khugepaged_mutex); int err = 0; mutex_lock(&khugepaged_mutex); @@ -1976,3 +1977,11 @@ fail: mutex_unlock(&khugepaged_mutex); return err; } + +void khugepaged_min_free_kbytes_update(void) +{ + mutex_lock(&khugepaged_mutex); + if (khugepaged_enabled() && khugepaged_thread) + set_recommended_min_free_kbytes(); + mutex_unlock(&khugepaged_mutex); +} --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -6785,6 +6786,8 @@ int __meminit init_per_zone_wmark_min(vo setup_min_slab_ratio(); #endif + khugepaged_min_free_kbytes_update(); + return 0; } postcore_initcall(init_per_zone_wmark_min)