From: Vlastimil Babka <vbabka@suse.cz>
To: Sasha Levin <sasha.levin@oracle.com>, linux-kernel@vger.kernel.org
Cc: mhocko@suse.cz, Andrew Morton <akpm@linux-foundation.org>,
Mel Gorman <mgorman@suse.de>,
Johannes Weiner <hannes@cmpxchg.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
open@kvack.org, list@kvack.org,
MEMORY MANAGEMENT <linux-mm@kvack.org>
Subject: Re: [PATCH 1/2] mm: free large amount of 0-order pages in workqueue
Date: Wed, 01 Apr 2015 14:57:55 +0200 [thread overview]
Message-ID: <551BEB53.8080402@suse.cz> (raw)
In-Reply-To: <1427839895-16434-1-git-send-email-sasha.levin@oracle.com>
On 04/01/2015 12:11 AM, Sasha Levin wrote:
> Freeing pages became a rather costly operation, specially when multiple debug
> options are enabled. This causes hangs when an attempt to free a large amount
> of 0-order is made. Two examples are vfree()ing large block of memory, and
> punching a hole in a shmem filesystem.
>
> To avoid that, move any free operations that involve batching pages into a
> list to a workqueue handler where they could be freed later.
Is there a risk of creating a situation where memory is apparently
missing, because the work item hasn't been processed? Leading to
allocation failures, needless reclaim, spurious OOM, etc? If yes, such
situations should probably wait for completion of the work first?
And maybe it shouldn't be used everywhere (as patch 2/2 does) but only
where it makes sense. Process exits, maybe?
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> ---
> mm/page_alloc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 46 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 5bd9711..812ca75 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -1586,10 +1586,11 @@ out:
> local_irq_restore(flags);
> }
>
> -/*
> - * Free a list of 0-order pages
> - */
> -void free_hot_cold_page_list(struct list_head *list, bool cold)
> +static LIST_HEAD(free_hot_page_list);
> +static LIST_HEAD(free_cold_page_list);
> +static DEFINE_SPINLOCK(free_page_lock);
> +
> +static void __free_hot_cold_page_list(struct list_head *list, bool cold)
> {
> struct page *page, *next;
>
> @@ -1599,6 +1600,47 @@ void free_hot_cold_page_list(struct list_head *list, bool cold)
> }
> }
>
> +static void free_page_lists_work(struct work_struct *work)
> +{
> + LIST_HEAD(hot_pages);
> + LIST_HEAD(cold_pages);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&free_page_lock, flags);
> + list_cut_position(&hot_pages, &free_hot_page_list,
> + free_hot_page_list.prev);
> + list_cut_position(&cold_pages, &free_cold_page_list,
> + free_cold_page_list.prev);
> + spin_unlock_irqrestore(&free_page_lock, flags);
> +
> + __free_hot_cold_page_list(&hot_pages, false);
> + __free_hot_cold_page_list(&cold_pages, true);
> +}
> +
> +static DECLARE_WORK(free_page_work, free_page_lists_work);
> +
> +/*
> + * Free a list of 0-order pages
> + */
> +void free_hot_cold_page_list(struct list_head *list, bool cold)
> +{
> + unsigned long flags;
> +
> + if (unlikely(!keventd_up())) {
> + __free_hot_cold_page_list(list, cold);
> + return;
> + }
> +
> + spin_lock_irqsave(&free_page_lock, flags);
> + if(cold)
> + list_splice_tail(list, &free_cold_page_list);
> + else
> + list_splice_tail(list, &free_hot_page_list);
> + spin_unlock_irqrestore(&free_page_lock, flags);
> +
> + schedule_work(&free_page_work);
> +}
> +
> /*
> * split_page takes a non-compound higher-order page, and splits it into
> * n (1<<order) sub-pages: page[0..n]
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2015-04-01 12:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-31 22:11 [PATCH 1/2] mm: free large amount of 0-order pages in workqueue Sasha Levin
2015-03-31 22:11 ` [PATCH 2/2] mm: __free_pages batch up 0-order pages for freeing Sasha Levin
2015-04-01 12:48 ` Rasmus Villemoes
2015-03-31 22:31 ` [PATCH 1/2] mm: free large amount of 0-order pages in workqueue Andrew Morton
2015-03-31 22:39 ` Sasha Levin
2015-03-31 22:54 ` Andrew Morton
2015-04-01 13:20 ` Sasha Levin
2015-04-25 21:51 ` Sasha Levin
2015-04-01 12:57 ` Vlastimil Babka [this message]
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=551BEB53.8080402@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=list@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.cz \
--cc=open@kvack.org \
--cc=rientjes@google.com \
--cc=sasha.levin@oracle.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).