Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1271845ybk; Thu, 14 May 2020 05:01:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0I6yqIndQsy/j0snwLVY85koOw4GdlqTHgkwCMw85vUilGZJqSdaCfvcNSHpSLU6jfwaf X-Received: by 2002:a50:e04c:: with SMTP id g12mr3718797edl.74.1589457709789; Thu, 14 May 2020 05:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589457709; cv=none; d=google.com; s=arc-20160816; b=zX9vEzAHmAT38zf5NXPHmNhlWD+UxpNWK2AeYPcq42uC6D6T35gudRFmQml93Nw62G WZTkId4T1134n5lo37xH46zqm8SZL14fSFSqf9VUIzL7z/ixWKfwxZEm9PN4jSlcrsfZ FMn3PH/Li97psKAaO/N7fa+qoNiNJITSDNl+8r+KYlAPu+aAMZHReQg6GCJcTe5v5vZO BrAmChpv8Qjn6yNS65A9XaW1NsG3BE88iGBXnBs5qUIwPmqUcqlROezax3p6OwOHl74a WsoV630LyXXR0gaoYYo8ALeUpvX9oI89ZUjWaHPJ+WHeiEHPo+CGd4Zdtz/TYkDfHPk8 EklQ== 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 :dmarc-filter:dkim-signature; bh=GWge08NUpx9hYk85PE+U6cP3rNMxXJ52WIEvWFBmNxA=; b=H6Lwg9pJsGNgGakDNbgbPIo3TdpR5xPVoqANJ3Gsdi6dpZgfB4TCR+Ciwn11Q2wztX pj6ZaydfMfCSjzKCD1Yuk9C2pRzMikFULepvU+KLECnFHtJwveNRaz9w7953rn7Ax01D Hj/4t/difXTe2hwjxfo4Up5agJRlkusGivLqAf16fxkTd0S2cU3zELu6/rul9NPL0kDq pcZIUNwUC1lEhz5bnyvg6wETWJoRS5PWXj0TwZMLdRRN2bXKz809eRmy9kJOoyyzod5N K5Q/EyVfErkC8j6oOHPndQqGP1XwnH7TYc+N9JcTAifF7bBjDIedC08CGsdG2qggJpWt O57w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=B3UIZ7fC; 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 v5si1469263edt.317.2020.05.14.05.01.24; Thu, 14 May 2020 05:01:49 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=B3UIZ7fC; 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 S1726763AbgENL7a (ORCPT + 99 others); Thu, 14 May 2020 07:59:30 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:63304 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgENL7a (ORCPT ); Thu, 14 May 2020 07:59:30 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1589457569; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=GWge08NUpx9hYk85PE+U6cP3rNMxXJ52WIEvWFBmNxA=; b=B3UIZ7fCnhcpHa+WJIcTpIAA/QdBu/6UFqr0TkLwsdA3RlhfQrA891uhLbMaPX88GK8eRqy/ ZJTpDa55Qf+42ZpmeggG0+gGRl+tSoogeZJohqAFLtOh8MZnO9TlbApwRXsR1AqYrGzXM5f7 S0gpy9YXMC822l+qFpemfCwX6rA= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5ebd32a1.7fa3df0c8ce0-smtp-out-n05; Thu, 14 May 2020 11:59:29 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 0195AC433F2; Thu, 14 May 2020 11:59:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=ham autolearn_force=no version=3.4.0 Received: from charante-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: charante) by smtp.codeaurora.org (Postfix) with ESMTPSA id B1A7DC433D2; Thu, 14 May 2020 11:59:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B1A7DC433D2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=charante@codeaurora.org From: Charan Teja Reddy To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, vinmenon@codeaurora.org, Charan Teja Reddy Subject: [PATCH v2] mm, page_alloc: reset the zone->watermark_boost early Date: Thu, 14 May 2020 17:28:31 +0530 Message-Id: <1589457511-4255-1-git-send-email-charante@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Updating the zone watermarks by any means, like min_free_kbytes, water_mark_scale_factor e.t.c, when ->watermark_boost is set will result into the higher low and high watermarks than the user asked. Below are the steps pursued to reproduce the problem on system setup of Android kernel running on Snapdragon hardware. 1) Default settings of the system are as below: #cat /proc/sys/vm/min_free_kbytes = 5162 #cat /proc/zoneinfo | grep -e boost -e low -e "high " -e min -e Node Node 0, zone Normal min 797 low 8340 high 8539 2) Monitor the zone->watermark_boost(by adding a debug print in the kernel) and whenever it is greater than zero value, write the same value of min_free_kbytes obtained from step 1. #echo 5162 > /proc/sys/vm/min_free_kbytes 3) Then read the zone watermarks in the system while the ->watermark_boost is zero. This should show the same values of watermarks as step 1 but shown a higher values than asked. #cat /proc/zoneinfo | grep -e boost -e low -e "high " -e min -e Node Node 0, zone Normal min 797 low 21148 high 21347 These higher values are because of updating the zone watermarks using the macro min_wmark_pages(zone) which also adds the zone->watermark_boost. #define min_wmark_pages(z) (z->_watermark[WMARK_MIN] + z->watermark_boost) So the steps that lead to the issue is like below: 1) On the extfrag event, watermarks are boosted by storing the required value in ->watermark_boost. 2) User tries to update the zone watermarks level in the system through min_free_kbytes or watermark_scale_factor. 3) Later, when kswapd woke up, it resets the zone->watermark_boost to zero. In step 2), we use the min_wmark_pages() macro to store the watermarks in the zone structure thus the values are always offsetted by ->watermark_boost value. This can be avoided by resetting the ->watermark_boost to zero before it is used. Signed-off-by: Charan Teja Reddy --- v2: Improve the commit message v1: (https://patchwork.kernel.org/patch/11540751/) mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index cef05d3..d001d61 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7761,9 +7761,9 @@ static void __setup_per_zone_wmarks(void) mult_frac(zone_managed_pages(zone), watermark_scale_factor, 10000)); + zone->watermark_boost = 0; zone->_watermark[WMARK_LOW] = min_wmark_pages(zone) + tmp; zone->_watermark[WMARK_HIGH] = min_wmark_pages(zone) + tmp * 2; - zone->watermark_boost = 0; spin_unlock_irqrestore(&zone->lock, flags); } -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation