Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3156904pxk; Tue, 15 Sep 2020 11:29:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpQSGGy4n6xucUsE4Zz7nO5dtM9EIdgXgAXkqnTduMk55kax4CUusCxu0BVsIzLEU43l+u X-Received: by 2002:a05:6402:209:: with SMTP id t9mr24836660edv.208.1600194577213; Tue, 15 Sep 2020 11:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600194577; cv=none; d=google.com; s=arc-20160816; b=PEFWFeDgV1fRv4O1p+LHEYBtBN0/XjmgxOi6+Anx6syfMXdZuC/Ze9Bw1hXw0FJZ/J Zt62DTgvOe6nKLcFjZBRRwfblmbk8cn3Im+DklxtDdxkwd8srDpVckoebBFwemDr1VmL ZwUwTA1hBgXqfVvAXzNqBLdTvOUkhlv647Ilz/UOF62fTonVAi14WXhDApgTUSdfmoEP P+hBt+AyTPKJmR9ZFy+IfJc2WpcljO3JIZ2d46/tZlu3PquZW+Y8MsicODSh3/B5ObSR nCJjcc35/7JZwW1jWgq5215ozZq2rnh8nJENXti/TdwSImU6q3PuF/ZoJ1RFCJPfzMLc +FPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+ShJFz3O2UoFV/lQCaUWLOKhWZytgwFxTiuG7a5D3cE=; b=J11uLVEVTJI6kbwpZU4AMxFi+D6G91eb0KfaZQUtfzHnzYw27Ec1YcLDAQ3RWXLHOo hb+6la8+81PZscsvgUF4Nmwq9OOC4osvE4xa57Ql+cNqbn2ikNujkFMDo0azqjch4cF3 owO0TeGnzjVJOzd15H/Zz2tjcM2qhtkJYiSi4uxRbxCuEz5dHBTzzVW6DJBkYahiKros awlxkpCMf+PfxlouwtyKf0S6wVzdYqFJVv2YQclnRxu+/p/iYU5q67Z6Q6z4a6HH98BO Z9uiYJ/Qpff8Efl88esZoxggNR7iTE5Roe3INojRpQJo3/fRnmMzxDyQOmzQEWEvOVnT tPjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=n6trtHxT; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z34si11152572ede.447.2020.09.15.11.29.14; Tue, 15 Sep 2020 11:29:37 -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=@soleen.com header.s=google header.b=n6trtHxT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727872AbgIOS1h (ORCPT + 99 others); Tue, 15 Sep 2020 14:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727915AbgIOSXu (ORCPT ); Tue, 15 Sep 2020 14:23:50 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A75C1C061353 for ; Tue, 15 Sep 2020 11:23:10 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id gr14so6495933ejb.1 for ; Tue, 15 Sep 2020 11:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+ShJFz3O2UoFV/lQCaUWLOKhWZytgwFxTiuG7a5D3cE=; b=n6trtHxTcQjtJZGdvYFQ6qKRCrutxbVnecrpqzmMhwzyuU9Ny4ZkfwWLVyc0r7w4EX /PcgXTQasrpTvLF3ZXFmI6iAzuNbTobxASgARI/RpwPhiJdjDGweUSirtgJNA68Ucoq3 rY93Xyt9CayLfEeNYHBtTJnUYT5iR7AopYfUv1Zfcw4DmtpNZD1ALyfUdMdeoWiKNCSe LnahvlfCADtUOlcSBHdf8hguPwQ8BlodxxBE+b5gVEzKcvHRRTHruRTGSIs02JmpVsMe RzKlHD+XrhPX3Ree5CXvO+wSLpFZd4/7YZzt19+PXyaVp5pjRg3lFCqVardeSzR2lOlJ Orsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+ShJFz3O2UoFV/lQCaUWLOKhWZytgwFxTiuG7a5D3cE=; b=gdZqIpZZtvfUhwJX9g0OKhvQOJxS2iPQqUfGkTjf5eDGQauJr3eWf2X/LmQIh1iaCw L9GVfyx2VbarW/63WmLWkMltj+12VlVqCMylj1AkLu3WOJ4pC7M64mWloTvNnlx4OjtL uOXeaeYL8Xs++qRg1rz6dnjzxy/73Wh6AmcMKgoRr+taNIWRZHQ/xAtNqgRCwQqnIpsW 6NUZUTfMf/HBgt/fZvbS1QGDCKhlGb8MClN7Vqo+XY8axmoXk3GcYYU8zSJRM53yLOzd e1Pabhx7qYAY96pTvOkbxuPvDJQRpXRBtF6CUJRFEcVqhP0yVgr17JkYOma7yF69KZlD 3qdQ== X-Gm-Message-State: AOAM530FTaimLJ9KoqaLo2op2jSq/JYwSWfgXIE3cMcduW3kNfC2rore 3lLtxpHD+2e887YxOtyvVcGWwovkvlZGo9lM0zg6XQ== X-Received: by 2002:a17:906:d787:: with SMTP id pj7mr20596675ejb.340.1600194189281; Tue, 15 Sep 2020 11:23:09 -0700 (PDT) MIME-Version: 1.0 References: <1599770859-14826-1-git-send-email-vijayb@linux.microsoft.com> In-Reply-To: <1599770859-14826-1-git-send-email-vijayb@linux.microsoft.com> From: Pavel Tatashin Date: Tue, 15 Sep 2020 14:22:33 -0400 Message-ID: Subject: Re: [[PATCH]] mm: khugepaged: recalculate min_free_kbytes after memory hotplug as expected by khugepaged To: Vijay Balakrishna Cc: Andrew Morton , "Kirill A. Shutemov" , Oleg Nesterov , Song Liu , Andrea Arcangeli , Allen Pais , LKML , linux-mm Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 4:47 PM Vijay Balakrishna wrote: > > 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(); The bug makes sense that min_free_kbytes should be consistent after reboot or after hot-add, hence Reviewed-by: Pavel Tatashin