Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5057180imu; Sun, 25 Nov 2018 15:56:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/UnyQ1SPN7UDQNIuYB8lhZxUaPWZ2xVI+/lpdZOYVKoFl7T1uvCcZvcjI+LFq1bzHYfa1yK X-Received: by 2002:a65:6392:: with SMTP id h18mr22914800pgv.107.1543190192868; Sun, 25 Nov 2018 15:56:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543190192; cv=none; d=google.com; s=arc-20160816; b=nOZdhMbGONXEsL1L1I55/Up/iKlmU19lrakhU+2LyxVgePVQU6ElsTG8GriuQPooUj XyZwxFE/Zb7g1lhOXdAQ1jzLg2fr5CSHnnMpqIeGNF8xyJe/ISjhe58MluxzBAJq+Pwv zAxng0e2YjSHBe4jYJ9mtDScRd1Mc7euL9IP8ZuDj6WIQwkSwG40WRI8I/BJjz+wC6Eg eXTjzs2aWsgIhO/DFXLlFv/VUdBMF07sTUiuHfOLBpr+jPxirq+ts6+0b6XSAtuHmIX2 0VX14wAUv4ARotgUFOCLt5fgFzXVUd7iYYG54uhW7rl9j69cMxtfAoWYCfYdSKMgaHiF hZ6w== 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; bh=8e7E7ITWT1VN5QpnjNxebPkq/K1dd8D7jhUafpSEV8I=; b=gMPnPG2WRMKM1berXL4eFMMInCh5TEzqzMdSXgPnFMzhaTaExljlhdUhCUV+meY3f+ ky+UOLzoXOvXApIKsbgorM/kk9fFRYuLrHjnKiRTvt6pS08ErEB9UZJcO3472xnGF0hR 8FTI+Fd/SkekAHIsJD4020F1LSf0vESVpOlWATl49OVBeSWH5OPaShuNqyKEQZYocBzu M0vhwmeyKjDk99Owzm4X3aixpY6zogDb/nKD5N1KldSv6Mgwju1V+LVmLmf7c7gIGpXc GLAuiFjb1BFy5yG4vFkXLrXh/+Bc24PIKZ0I1WeBNYlary2lkxSHTVzmcy7iPJNBXWKn ElGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si39780965plr.178.2018.11.25.15.56.16; Sun, 25 Nov 2018 15:56:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbeKZKr6 (ORCPT + 99 others); Mon, 26 Nov 2018 05:47:58 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:45496 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726027AbeKZKr6 (ORCPT ); Mon, 26 Nov 2018 05:47:58 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 65F923A9DBB2370909C9; Mon, 26 Nov 2018 07:55:36 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wAPNtVEx093301; Mon, 26 Nov 2018 07:55:31 +0800 (GMT-8) (envelope-from yang.yang29@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018112607553337-12876764 ; Mon, 26 Nov 2018 07:55:33 +0800 From: Yang Yang To: akpm@linux-foundation.org Cc: mhocko@suse.com, pavel.tatashin@microsoft.com, vbabka@suse.cz, osalvador@suse.de, rppt@linux.vnet.ibm.com, iamjoonsoo.kim@lge.com, alexander.h.duyck@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, wang.yi59@zte.com.cn, Yang Yang Subject: [PATCH] mm: do not consider SWAP to calculate available when not necessary Date: Mon, 26 Nov 2018 07:58:23 +0800 Message-Id: <1543190303-8121-1-git-send-email-yang.yang29@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-11-26 07:55:33, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-11-26 07:55:30, Serialize complete at 2018-11-26 07:55:30 X-MAIL: mse01.zte.com.cn wAPNtVEx093301 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When si_mem_available() calculates 'available', it takes SWAP into account. But if CONFIG_SWAP is N or SWAP is off(some embedded system would like to do that), there is no need to consider it. Signed-off-by: Yang Yang --- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6847177..10e186b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4700,6 +4700,7 @@ static inline void show_node(struct zone *zone) long si_mem_available(void) { + struct sysinfo i; long available; unsigned long pagecache; unsigned long wmark_low = 0; @@ -4708,6 +4709,7 @@ long si_mem_available(void) struct zone *zone; int lru; + si_swapinfo(&i); for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) pages[lru] = global_node_page_state(NR_LRU_BASE + lru); @@ -4724,9 +4726,13 @@ long si_mem_available(void) * Not all the page cache can be freed, otherwise the system will * start swapping. Assume at least half of the page cache, or the * low watermark worth of cache, needs to stay. + * But if CONFIG_SWAP is N or SWAP is off, do not consider it. */ pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE]; - pagecache -= min(pagecache / 2, wmark_low); +#ifdef CONFIG_SWAP + if (i.totalswap > 0) + pagecache -= min(pagecache / 2, wmark_low); +#endif available += pagecache; /* -- 2.15.2