linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Huang\, Ying" <ying.huang@intel.com>
To: Vasily Averin <vvs@virtuozzo.com>
Cc: <linux-mm@kvack.org>, Andrew Morton <akpm@linux-foundation.org>,
	<linux-kernel@vger.kernel.org>, "Aaron Lu" <aaron.lu@intel.com>
Subject: Re: [PATCH 2/2] mm: avoid unnecessary swap_info_struct allocation
Date: Mon, 05 Nov 2018 08:57:05 +0800	[thread overview]
Message-ID: <87sh0gbau6.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <a24bf353-8715-2bee-d0fa-96ca06c5b69f@virtuozzo.com> (Vasily Averin's message of "Mon, 5 Nov 2018 01:13:12 +0300")

Vasily Averin <vvs@virtuozzo.com> writes:

> Currently newly allocated swap_info_struct can be quickly freed.
> This patch avoid uneccessary high-order page allocation and helps
> to decrease the memory pressure.

I think swapon/swapoff are rare operations, so it will not increase the
memory pressure much.  

Best Regards,
Huang, Ying

> Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
> ---
>  mm/swapfile.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 8688ae65ef58..53ec2f0cdf26 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2809,14 +2809,17 @@ late_initcall(max_swapfiles_check);
>  
>  static struct swap_info_struct *alloc_swap_info(void)
>  {
> -	struct swap_info_struct *p;
> +	struct swap_info_struct *p = NULL;
>  	unsigned int type;
>  	int i;
> +	bool force_alloc = false;
>  
> -	p = kvzalloc(sizeof(*p), GFP_KERNEL);
> -	if (!p)
> -		return ERR_PTR(-ENOMEM);
> -
> +retry:
> +	if (force_alloc) {
> +		p = kvzalloc(sizeof(*p), GFP_KERNEL);
> +		if (!p)
> +			return ERR_PTR(-ENOMEM);
> +	}
>  	spin_lock(&swap_lock);
>  	for (type = 0; type < nr_swapfiles; type++) {
>  		if (!(swap_info[type]->flags & SWP_USED))
> @@ -2828,6 +2831,11 @@ static struct swap_info_struct *alloc_swap_info(void)
>  		return ERR_PTR(-EPERM);
>  	}
>  	if (type >= nr_swapfiles) {
> +		if (!force_alloc) {
> +			force_alloc = true;
> +			spin_unlock(&swap_lock);
> +			goto retry;
> +		}
>  		p->type = type;
>  		swap_info[type] = p;
>  		/*

  reply	other threads:[~2018-11-05  0:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-04 22:13 [PATCH 2/2] mm: avoid unnecessary swap_info_struct allocation Vasily Averin
2018-11-05  0:57 ` Huang, Ying [this message]
2018-11-05  5:19   ` Vasily Averin
2018-11-05 10:41     ` Vasily Averin

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=87sh0gbau6.fsf@yhuang-dev.intel.com \
    --to=ying.huang@intel.com \
    --cc=aaron.lu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vvs@virtuozzo.com \
    /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).