Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1375980pxk; Thu, 10 Sep 2020 13:50:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHnf26QrlwVznenrrHVy9V/U0RYJ0Rf+xcf/fOGBsAn1yMy2kM76hl6NPgYph/oeuRKwtC X-Received: by 2002:a17:906:4b18:: with SMTP id y24mr10550802eju.471.1599771003656; Thu, 10 Sep 2020 13:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599771003; cv=none; d=google.com; s=arc-20160816; b=WH//yj+qjgLrJkqZpZqR5m74c/Sy+F/hqqvKrKaw1RodR//+DrK7R0+0c0Gw+PXvx8 qVaqo2v87DCMuv3A0QQW2D/dgHVJqsRu9B/IerTqvbaZ016p1Xlv1yE6jOdirKjloJdq 4WZTj2DpJs9QhnheUdiL9xhzZkSGQUJEJ01Ivi++Q1XPmJCHJku03HQvea2qLVtWj5JP 3TZwYYs3tIwYSi77V7nBZbpmOEmtpz+pZaWVWfUByn27lgAnQqaKfIqLxKig98Pj/dNk ktwqMTZ9kXqq/Vc2drAvwvQUC+7JVNZ/JZdpe2HP+Ca2o+Qvl+SFdF4h0IoDx78z6uAq fn4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=DYkt/+OLsBBKzpAIjhbg1N2PcF3nqmlb/5nTfGw2yRE=; b=rDA+8GBz7Tyb85kP1ia3DwU6FSaVSca4GNlX20/i+bGgU2zjFYckn1yNWxma2qptBg AayUo2urHjRvYrKQjK+tLjpXtLtUlvJdYym8OjzFR3cSr5GcfhZLM3PDhBW3GWngC77E ehGd7S0iYy6zRV1ijDtM//jwQAdztF0vPEvr68w9Mlp7YANbGrZZWSmwK5PzgIoSekmH i+7ExNzyp5PKVhgHwATGa6Psa5JqUcCphDa4IAAhBvx46Y6NQNvTY793M/GIYspWgqf8 Qn+aYV4GjnbO5uYF5iBkAcUg/1sh0Ew+clH71vSGTrxVq9Sb7zrUxvkcv+5Ota/oTCA9 y4BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=mGGQ5+0d; 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=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si4558189eja.484.2020.09.10.13.49.40; Thu, 10 Sep 2020 13:50: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=@linux.microsoft.com header.s=default header.b=mGGQ5+0d; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726969AbgIJUtH (ORCPT + 99 others); Thu, 10 Sep 2020 16:49:07 -0400 Received: from linux.microsoft.com ([13.77.154.182]:55020 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgIJUrp (ORCPT ); Thu, 10 Sep 2020 16:47:45 -0400 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id DA046210673C; Thu, 10 Sep 2020 13:47:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DA046210673C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1599770863; bh=DYkt/+OLsBBKzpAIjhbg1N2PcF3nqmlb/5nTfGw2yRE=; h=From:To:Cc:Subject:Date:From; b=mGGQ5+0d81e+SlJD8E5doEw9c1QwRe1pDX/d1aaJG/OOZrxvMZOTaRwhBreaOvocN C1CKA0OsdoM5FI7AtDOK9FTbyLHgON0sdcUQHBFYhESOUKy5pVwq82FyxdziskEIOT eFY9V6vdqfyajz1y8DUO6ANtNuqDj1Vi+x+6Zos4= From: Vijay Balakrishna To: Andrew Morton , "Kirill A. Shutemov" , Oleg Nesterov , Song Liu , Andrea Arcangeli , Pavel Tatashin , Vijay Balakrishna , Allen Pais Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [[PATCH]] mm: khugepaged: recalculate min_free_kbytes after memory hotplug as expected by khugepaged Date: Thu, 10 Sep 2020 13:47:39 -0700 Message-Id: <1599770859-14826-1-git-send-email-vijayb@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When memory is hotplug added or removed the min_free_kbytes must 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 leaves the system with small min_free_kbytes which isn't suitable for systems especially with network intensive loads. Typical failure symptoms include HW WATCHDOG reset, soft lockup hang notices, NETDEVICE WATCHDOG timeouts, and OOM process kills. Fixes: f000565adb77 ("thp: set recommended min free kbytes") Signed-off-by: Vijay Balakrishna Cc: stable@vger.kernel.org --- include/linux/khugepaged.h | 5 +++++ mm/khugepaged.c | 13 +++++++++++-- mm/memory_hotplug.c | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index bc45ea1efbf7..c941b7377321 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -15,6 +15,7 @@ extern int __khugepaged_enter(struct mm_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_thp(struct mm_struct *mm, unsigned long addr) { } + +static inline void khugepaged_min_free_kbytes_update(void) +{ +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #endif /* _LINUX_KHUGEPAGED_H */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index cfa0dba5fd3b..4f7107476a6f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -56,6 +56,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; @@ -2292,8 +2295,6 @@ static void set_recommended_min_free_kbytes(void) 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); @@ -2320,3 +2321,11 @@ int start_stop_khugepaged(void) 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); +} diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index e9d5ab5d3ca0..3e19272c1fad 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -857,6 +858,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, zone_pcp_update(zone); init_per_zone_wmark_min(); + khugepaged_min_free_kbytes_update(); kswapd_run(nid); kcompactd_run(nid); @@ -1600,6 +1602,7 @@ static int __ref __offline_pages(unsigned long start_pfn, pgdat_resize_unlock(zone->zone_pgdat, &flags); init_per_zone_wmark_min(); + khugepaged_min_free_kbytes_update(); if (!populated_zone(zone)) { zone_pcp_reset(zone); -- 2.28.0