Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4343895pxu; Mon, 12 Oct 2020 16:57:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQK71xlEVW8W3w6rrEu/agkpg94RtDGpo9PxSk1cDu7nUQlOvIlg2IEJK4q3DgIj7jFLE3 X-Received: by 2002:a50:a452:: with SMTP id v18mr16631963edb.143.1602547040708; Mon, 12 Oct 2020 16:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602547040; cv=none; d=google.com; s=arc-20160816; b=mD7A6AKKPlklyrxZVEoa3ObMxEf6VcHY6af5IQ+vPLWAKadIHoJT3Au3wJpx/p8Tz5 zeImLMZvvddr4efGNbslvq8m3tum3IjVnIph6U0Q8IThgnJhBkBqYUMgm82StJLSA5PY +oZK0nc1AQcBp4vgSXo+rI6NB4zhrWJeF+0U8socsQ34LMsQRAwl65D70SjLQYPghQJU VCILUqBoswlqk31BURduC0DOycWaVFzJdavmdzFOqTC9V6X1cs7zs2bZYv1YPnKYb6mq UhGvoE6Mcr+GpxevMFYsZ//s3u2Lw2fgUwxf+U3zE0nP8gLNQh3WVKw0hw2lC5WHEikb BaFg== 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=9M0GC1T59E4bexsq4ANgRyWUHu+O06bNTH5KIIQwlF8=; b=Lik1W3oikvovnP+u8UBYR6Wjzo1l9jesZSGUz3J1yAHF+bPq/2G4bUE2WUoc9hFkY8 MpGa4DA3kuCAOGSDObP2MX+iZkkPoTLj+H0k9VOhiH0G7g1L0my94+gdxcFNMbQziHdg n6oemouCe1jwNJBrp8zfwrzKtxyp3fDAFkiqtmDLYPTg6BxkrAUG/vdYP2gzE5MWa/8g m+GGIJhgEfz8aKP36zZu63j3FEYGdDwYHjHme9c3PQtCeV8F32m4chIH4YG2ujDbZUWl gyathww8jwr5751nv+eY8RB1r/XfrWBuY3tRflPg8nFz+0LeKn6nqvnWFAXFq3oTIH7O MFpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sZj9lNRt; 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 k20si2662099edq.431.2020.10.12.16.56.57; Mon, 12 Oct 2020 16:57:20 -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=sZj9lNRt; 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 S2390646AbgJLN5d (ORCPT + 99 others); Mon, 12 Oct 2020 09:57:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:46224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389352AbgJLNnk (ORCPT ); Mon, 12 Oct 2020 09:43:40 -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 4FB142222C; Mon, 12 Oct 2020 13:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510205; bh=h38KTzA9i2IQ0UwwxS+Rh6Tqi79PtZvsBlEp9rvc2fE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sZj9lNRtEnu3gRtHZ9kqlNDsOwwE93WcMS3NXwLlgHAS4Btp4SU6yYQlrH79zCDEd ikaH8S1W50PmKF6L8wb966dh1FVJNNdDM/8ihmWNqHdpHfK/0+whHnDGvinjyqg4J/ zAL4ad3qhJrLFs1U9DoiDDBlOSVRX1WKdTjuC+qg= 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 5.4 77/85] mm: khugepaged: recalculate min_free_kbytes after memory hotplug as expected by khugepaged Date: Mon, 12 Oct 2020 15:27:40 +0200 Message-Id: <20201012132636.545846832@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132632.846779148@linuxfoundation.org> References: <20201012132632.846779148@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 @@ -15,6 +15,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); #ifdef CONFIG_SHMEM extern void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr); #else @@ -85,6 +86,10 @@ static inline void collapse_pte_mapped_t unsigned long addr) { } + +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 @@ -54,6 +54,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; @@ -2177,8 +2180,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); @@ -2205,3 +2206,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 @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -7870,6 +7871,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)