linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: do not consider SWAP to calculate available when not necessary
@ 2018-11-25 23:58 Yang Yang
  2018-11-26  2:01 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Yang @ 2018-11-25 23:58 UTC (permalink / raw)
  To: akpm
  Cc: mhocko, pavel.tatashin, vbabka, osalvador, rppt, iamjoonsoo.kim,
	alexander.h.duyck, linux-mm, linux-kernel, zhong.weidong,
	wang.yi59, Yang Yang

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 <yang.yang29@zte.com.cn>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: do not consider SWAP to calculate available when not necessary
  2018-11-25 23:58 [PATCH] mm: do not consider SWAP to calculate available when not necessary Yang Yang
@ 2018-11-26  2:01 ` Matthew Wilcox
  2018-11-26  7:41   ` Vlastimil Babka
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2018-11-26  2:01 UTC (permalink / raw)
  To: Yang Yang
  Cc: akpm, mhocko, pavel.tatashin, vbabka, osalvador, rppt,
	iamjoonsoo.kim, alexander.h.duyck, linux-mm, linux-kernel,
	zhong.weidong, wang.yi59

On Mon, Nov 26, 2018 at 07:58:23AM +0800, Yang Yang wrote:
> 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.

I don't understand this patch.  The pagecache can be written back to
storage if it is dirty, regardless of whether there is swap space.

> @@ -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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: do not consider SWAP to calculate available when not necessary
  2018-11-26  2:01 ` Matthew Wilcox
@ 2018-11-26  7:41   ` Vlastimil Babka
  0 siblings, 0 replies; 3+ messages in thread
From: Vlastimil Babka @ 2018-11-26  7:41 UTC (permalink / raw)
  To: Matthew Wilcox, Yang Yang
  Cc: akpm, mhocko, pavel.tatashin, osalvador, rppt, iamjoonsoo.kim,
	alexander.h.duyck, linux-mm, linux-kernel, zhong.weidong,
	wang.yi59

On 11/26/18 3:01 AM, Matthew Wilcox wrote:
> On Mon, Nov 26, 2018 at 07:58:23AM +0800, Yang Yang wrote:
>> 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.
> 
> I don't understand this patch.  The pagecache can be written back to
> storage if it is dirty, regardless of whether there is swap space.
> 
>> @@ -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

I guess the first sentence in the comment above might be misleading by
using the word 'swapping', where 'thrashing' would be more accurate and
unambiguous.

So this is not related to the swap, but to the assumption that somebody
is accessing the pages in pagecache, and if too much would be freed,
most accesses would mean reading data from disk, i.e. thrashing.

>>  	 * 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
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-26  7:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-25 23:58 [PATCH] mm: do not consider SWAP to calculate available when not necessary Yang Yang
2018-11-26  2:01 ` Matthew Wilcox
2018-11-26  7:41   ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).