linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shaohua Li <shaohua.li@intel.com>
To: Hugh Dickins <hughd@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Zhang, Yanmin" <yanmin.zhang@intel.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH 5/7] tmpfs: simplify prealloc_page
Date: Fri, 10 Jun 2011 10:02:03 +0800	[thread overview]
Message-ID: <1307671323.15392.76.camel@sli10-conroe> (raw)
In-Reply-To: <alpine.LSU.2.00.1106091535510.2200@sister.anvils>

On Fri, 2011-06-10 at 06:39 +0800, Hugh Dickins wrote:
> The prealloc_page handling in shmem_getpage_gfp() is unnecessarily
> complicated: first simplify that before going on to filepage/swappage.
> 
> That's right, don't report ENOMEM when the preallocation fails: we may
> or may not need the page.  But simply report ENOMEM once we find we do
> need it, instead of dropping lock, repeating allocation, unwinding on
> failure etc.  And leave the out label on the fast path, don't goto.
> 
> Fix something that looks like a bug but turns out not to be: set
> PageSwapBacked on prealloc_page before its mem_cgroup_cache_charge(),
> as the removed case was doing.  That's important before adding to LRU
> (determines which LRU the page goes on), and does affect which path it
> takes through memcontrol.c, but in the end MEM_CGROUP_CHANGE_TYPE_
> SHMEM is handled no differently from CACHE.
> 
> Signed-off-by: Hugh Dickins <hughd@google.com>
> Cc: Shaohua Li <shaohua.li@intel.com>
> Cc: "Zhang, Yanmin" <yanmin.zhang@intel.com>
> Cc: Tim Chen <tim.c.chen@linux.intel.com>
> ---
>  mm/shmem.c |   59 ++++++++++++---------------------------------------
>  1 file changed, 15 insertions(+), 44 deletions(-)
> 
> --- linux.orig/mm/shmem.c	2011-06-09 11:39:32.361240481 -0700
> +++ linux/mm/shmem.c	2011-06-09 11:39:42.845292474 -0700
> @@ -1269,9 +1269,9 @@ repeat:
>  			goto failed;
>  		radix_tree_preload_end();
>  		if (sgp != SGP_READ && !prealloc_page) {
> -			/* We don't care if this fails */
>  			prealloc_page = shmem_alloc_page(gfp, info, idx);
>  			if (prealloc_page) {
> +				SetPageSwapBacked(prealloc_page);
>  				if (mem_cgroup_cache_charge(prealloc_page,
>  						current->mm, GFP_KERNEL)) {
>  					page_cache_release(prealloc_page);
> @@ -1403,7 +1403,8 @@ repeat:
>  			goto repeat;
>  		}
>  		spin_unlock(&info->lock);
> -	} else {
> +
> +	} else if (prealloc_page) {
>  		shmem_swp_unmap(entry);
>  		sbinfo = SHMEM_SB(inode->i_sb);
>  		if (sbinfo->max_blocks) {
> @@ -1419,41 +1420,8 @@ repeat:
>  		if (!filepage) {
>  			int ret;
>  
> -			if (!prealloc_page) {
> -				spin_unlock(&info->lock);
> -				filepage = shmem_alloc_page(gfp, info, idx);
> -				if (!filepage) {
> -					spin_lock(&info->lock);
> -					shmem_unacct_blocks(info->flags, 1);
> -					shmem_free_blocks(inode, 1);
> -					spin_unlock(&info->lock);
> -					error = -ENOMEM;
> -					goto failed;
> -				}
> -				SetPageSwapBacked(filepage);
> -
> -				/*
> -				 * Precharge page while we can wait, compensate
> -				 * after
> -				 */
> -				error = mem_cgroup_cache_charge(filepage,
> -					current->mm, GFP_KERNEL);
> -				if (error) {
> -					page_cache_release(filepage);
> -					spin_lock(&info->lock);
> -					shmem_unacct_blocks(info->flags, 1);
> -					shmem_free_blocks(inode, 1);
> -					spin_unlock(&info->lock);
> -					filepage = NULL;
> -					goto failed;
> -				}
> -
> -				spin_lock(&info->lock);
> -			} else {
> -				filepage = prealloc_page;
> -				prealloc_page = NULL;
> -				SetPageSwapBacked(filepage);
> -			}
> +			filepage = prealloc_page;
> +			prealloc_page = NULL;
>  
>  			entry = shmem_swp_alloc(info, idx, sgp, gfp);
>  			if (IS_ERR(entry))
> @@ -1492,11 +1460,19 @@ repeat:
>  		SetPageUptodate(filepage);
>  		if (sgp == SGP_DIRTY)
>  			set_page_dirty(filepage);
> +	} else {
Looks info->lock unlock is missed here.
Otherwise looks good to me.

Thanks,
Shaohua

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-06-10  2:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-09 22:30 [PATCH 0/7] tmpfs: simplify by splice instead of readpage Hugh Dickins
2011-06-09 22:32 ` [PATCH 1/7] tmpfs: clone shmem_file_splice_read Hugh Dickins
2011-06-10  9:19   ` Jens Axboe
2011-06-10 20:01     ` Hugh Dickins
2011-06-09 22:33 ` [PATCH 2/7] tmpfs: refine shmem_file_splice_read Hugh Dickins
2011-06-09 22:34 ` [PATCH 3/7] tmpfs: pass gfp to shmem_getpage_gfp Hugh Dickins
2011-06-09 22:35 ` [PATCH 4/7] tmpfs: remove_shmem_readpage Hugh Dickins
2011-06-09 22:39 ` [PATCH 5/7] tmpfs: simplify prealloc_page Hugh Dickins
2011-06-10  2:02   ` Shaohua Li [this message]
2011-06-10  6:40     ` Hugh Dickins
2011-06-10  6:44     ` [PATCH v2 " Hugh Dickins
2011-06-09 22:40 ` [PATCH 6/7] tmpfs: simplify filepage/swappage Hugh Dickins
2011-06-10  6:46   ` [PATCH v2 " Hugh Dickins
2011-06-09 22:42 ` [PATCH 7/7] tmpfs: simplify unuse and writepage 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=1307671323.15392.76.camel@sli10-conroe \
    --to=shaohua.li@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=yanmin.zhang@intel.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).