linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yang Shi <yang.shi@linux.alibaba.com>
To: Michal Hocko <mhocko@kernel.org>
Cc: hughd@google.com, akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: shmem: use proper gfp flags for shmem_writepage()
Date: Wed, 6 Nov 2019 10:23:24 -0800	[thread overview]
Message-ID: <733100ea-97aa-db27-4b43-cf42317afaf8@linux.alibaba.com> (raw)
In-Reply-To: <20191106151820.GB8138@dhcp22.suse.cz>



On 11/6/19 7:18 AM, Michal Hocko wrote:
> On Wed 06-11-19 06:02:31, Yang Shi wrote:
>> The shmem_writepage() uses GFP_ATOMIC to allocate swap cache.
>> GFP_ATOMIC used to mean __GFP_HIGH, but now it means __GFP_HIGH |
>> __GFP_ATOMIC | __GFP_KSWAPD_RECLAIM.  However, shmem_writepage() should
>> write out to swap only in response to memory pressure, so
>> __GFP_KSWAPD_RECLAIM looks useless since the caller may be kswapd itself
>> or in direct reclaim already.
> What kind of problem are you trying to fix here?

I didn't run into any visible problem. I just happened to find this 
inconsistency when I was looking into the other problem.

The add_to_swap() does:

int add_to_swap(struct page *page)
{
...
err = add_to_swap_cache(page, entry,
                         __GFP_HIGH|__GFP_NOMEMALLOC|__GFP_NOWARN);
...
}

Actually, shmem_writepage() does almost the same thing and both of them 
are called in reclaim context, so I didn't see why they should use 
different gfp flag. And, GFP_ATOMIC is also different from the old 
definition as I mentioned in the commit log.

>
>> In addition, XArray node allocations from PF_MEMALLOC contexts could
>> completely exhaust the page allocator, __GFP_NOMEMALLOC stops emergency
>> reserves from being allocated.
> I am not really familiar with XArray much, could you be more specific
> please?

It comes from the comments of add_to_swap(), says:

/*
          * XArray node allocations from PF_MEMALLOC contexts could
          * completely exhaust the page allocator. __GFP_NOMEMALLOC
          * stops emergency reserves from being allocated.

And, it looks the original comment came from pre-git time, TBH I'm not 
quite sure about the specific problem which incurred this. I suspect it 
may be because PF_MEMALLOC context allows ALLOC_NO_WATERMARK.

>
>> Here just copy the gfp flags used by add_to_swap().
>>
>> Cc: Hugh Dickins <hughd@google.com>
>> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
>> ---
>>   mm/shmem.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/shmem.c b/mm/shmem.c
>> index 220be9f..9691dec 100644
>> --- a/mm/shmem.c
>> +++ b/mm/shmem.c
>> @@ -1369,7 +1369,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
>>   	if (list_empty(&info->swaplist))
>>   		list_add(&info->swaplist, &shmem_swaplist);
>>   
>> -	if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {
>> +	if (add_to_swap_cache(page, swap,
>> +			__GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN) == 0) {
>>   		spin_lock_irq(&info->lock);
>>   		shmem_recalc_inode(inode);
>>   		info->swapped++;
>> -- 
>> 1.8.3.1



  reply	other threads:[~2019-11-06 18:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 22:02 [PATCH] mm: shmem: use proper gfp flags for shmem_writepage() Yang Shi
2019-11-06 15:18 ` Michal Hocko
2019-11-06 18:23   ` Yang Shi [this message]
2019-11-06 18:59     ` Hugh Dickins
2019-11-07 20:19       ` Yang Shi
2019-11-07 22:59         ` Hugh Dickins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=733100ea-97aa-db27-4b43-cf42317afaf8@linux.alibaba.com \
    --to=yang.shi@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).