Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp171376pxk; Wed, 16 Sep 2020 01:00:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1/4KGLNZRdE/IAwbav+7BaXPHHzI7JlUNIS4qCkGmKFSsDik9hnvIgSQ5r52S6eiAxZdm X-Received: by 2002:aa7:cd06:: with SMTP id b6mr25426200edw.196.1600243219504; Wed, 16 Sep 2020 01:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600243219; cv=none; d=google.com; s=arc-20160816; b=jgXdatjG3Y7uzJxSoFqZkWgmIfffv24CvBuCPSv/kDpLqMIWgdy0mimuDnEr2eNZRn Eilm6WjXX/9ARwxOcAOVGCT8yPxrPQgGG1om+tzogGGkG9q8f7wv+NjhF2hHqQZL93OZ qRqB8LKz+HR9S0Mn38PEQEFZXHDRmPNTklfFqsnELS18yuAnp7OG4aFFrD9ENKQazISv DkTbjsm6MW4QdxO3tJ884sujtgkvf8+FYACnHrA/t2dVGTaqt7TZXUyr04bs1VQ3h7c4 Y6IcPL9QmNIT0wyS+3jqiFQgfesIYzSueJdpp98dSP2c4jXwHNQLSsKB2yuG7L6AM27w YCmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=F/R8pHJlyNy4DF2ePc8Ccy/t3zZ4OHfyQ6d6gtQDbeE=; b=bkWs3gwkkBX+X2TNycwqqlVrTRcMTexFX4+Xu9xaTavvlKJzLIkGeFwvLWHyeb6HL0 uPzAus/OcjqvJXsE17Ux3JPgZE25ug2eo+URgGOJM89dF6UKw8VhbkPV/pE9ARgsb1wO MYKcTL2s1l25jzEQZ0mrmvvaUrYutP6QzWFq32Jl7pWupEyQib9f1Lyk3P0i/pP6nary IQ/7cWV2x3nhW8CoTQEjpR9N4tCt3lH7f8Iv0NRu94vU+7zuqNcxmdPa+XLH6lZTNwx4 Ums9Pv1EnJFBZozv1HmMa47o5liqiy4dJ0E+ifgGsuwHidyVNJVIAnMwsQzRPc39FOLv +C6w== ARC-Authentication-Results: i=1; mx.google.com; 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 bz3si41558ejc.81.2020.09.16.00.59.55; Wed, 16 Sep 2020 01:00:19 -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; 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 S1726473AbgIPH7F (ORCPT + 99 others); Wed, 16 Sep 2020 03:59:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:48372 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbgIPH7E (ORCPT ); Wed, 16 Sep 2020 03:59:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7FC68AFF8; Wed, 16 Sep 2020 07:59:18 +0000 (UTC) Date: Wed, 16 Sep 2020 09:59:00 +0200 From: Michal Hocko To: Vijay Balakrishna Cc: Andrew Morton , "Kirill A. Shutemov" , Oleg Nesterov , Song Liu , Andrea Arcangeli , Pavel Tatashin , Allen Pais , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [v2 2/2] mm: khugepaged: avoid overriding min_free_kbytes set by user Message-ID: <20200916075900.GE18998@dhcp22.suse.cz> References: <1600204258-13683-1-git-send-email-vijayb@linux.microsoft.com> <1600204258-13683-2-git-send-email-vijayb@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1600204258-13683-2-git-send-email-vijayb@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 15-09-20 14:10:58, Vijay Balakrishna wrote: > set_recommended_min_free_kbytes need to honor min_free_kbytes set by the > user. Post start-of-day THP enable or memory hotplug operations can > lose user specified min_free_kbytes, in particular when it is higher than > calculated recommended value. Also modifying "recommended_min" variable > type to "int" from "unsigned long" to avoid undesired result noticed > during testing. It is due to comparing "unsigned long" with "int" type. > > Signed-off-by: Vijay Balakrishna > Cc: stable@vger.kernel.org > Reviewed-by: Pavel Tatashin > --- > mm/khugepaged.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 4f7107476a6f..b4b753ba411a 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -2253,7 +2253,7 @@ static void set_recommended_min_free_kbytes(void) > { > struct zone *zone; > int nr_zones = 0; > - unsigned long recommended_min; > + int recommended_min; > > for_each_populated_zone(zone) { > /* > @@ -2280,12 +2280,12 @@ static void set_recommended_min_free_kbytes(void) > > /* don't ever allow to reserve more than 5% of the lowmem */ > recommended_min = min(recommended_min, > - (unsigned long) nr_free_buffer_pages() / 20); > + (int) nr_free_buffer_pages() / 20); nr_free_buffer_pages can oveflow in int on very large machines. > recommended_min <<= (PAGE_SHIFT-10); > > - if (recommended_min > min_free_kbytes) { > + if (recommended_min > user_min_free_kbytes) { This can decrease the size theoretically. Because user_min_free_kbytes is -1 by default and recommended_min might be <= min_free_kbytes. You need to check both. Also can we make user_min_free_kbytes 0 by default? From a quick look, nobody should really care. > if (user_min_free_kbytes >= 0) > - pr_info("raising min_free_kbytes from %d to %lu to help transparent hugepage allocations\n", > + pr_info("raising min_free_kbytes from %d to %d to help transparent hugepage allocations\n", > min_free_kbytes, recommended_min); > > min_free_kbytes = recommended_min; > -- > 2.28.0 > -- Michal Hocko SUSE Labs