xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Bob Liu <lliubbo@gmail.com>
Cc: xen-devel@lists.xenproject.org, keir@xen.org,
	ian.campbell@citrix.com, JBeulich@suse.com
Subject: Re: [PATCH 15/16] tmem: refator function tmem_ensure_avail_pages()
Date: Fri, 22 Nov 2013 13:22:10 -0500	[thread overview]
Message-ID: <20131122182210.GI8120@phenom.dumpdata.com> (raw)
In-Reply-To: <1384937185-24749-15-git-send-email-bob.liu@oracle.com>

On Wed, Nov 20, 2013 at 04:46:24PM +0800, Bob Liu wrote:
> tmem_ensure_avail_pages() doesn't return a value which is incorrect because
> the caller need to confirm there is enough memory.

Which it was not doing until now. Ouch.
> 
> Signed-off-by: Bob Liu <bob.liu@oracle.com>
> ---
>  xen/common/tmem.c          |   43 +++++++++++++++++++------------------------
>  xen/include/xen/tmem_xen.h |    6 ------
>  2 files changed, 19 insertions(+), 30 deletions(-)
> 
> diff --git a/xen/common/tmem.c b/xen/common/tmem.c
> index 2e807d4..0bc33ee 100644
> --- a/xen/common/tmem.c
> +++ b/xen/common/tmem.c
> @@ -1296,22 +1296,28 @@ static unsigned long tmem_relinquish_npages(unsigned long n)
>      return avail_pages;
>  }
>  
> -/* Under certain conditions (e.g. if each client is putting pages for exactly
> +/*
> + * Under certain conditions (e.g. if each client is putting pages for exactly
>   * one object), once locks are held, freeing up memory may
>   * result in livelocks and very long "put" times, so we try to ensure there
>   * is a minimum amount of memory (1MB) available BEFORE any data structure
> - * locks are held */
> -static inline void tmem_ensure_avail_pages(void)
> + * locks are held.
> + */
> +static inline bool_t tmem_ensure_avail_pages(void)
>  {
>      int failed_evict = 10;
> +    unsigned long free_mem;
>  
> -    while ( !tmem_free_mb() )
> -    {
> -        if ( tmem_evict() )
> -            continue;
> -        else if ( failed_evict-- <= 0 )
> -            break;
> -    }
> +    do {
> +        free_mem = (tmem_page_list_pages + total_free_pages())
> +                        >> (20 - PAGE_SHIFT);
> +        if ( free_mem )
> +            return 1;
> +        if ( !tmem_evict() )
> +            failed_evict--;
> +    } while ( failed_evict > 0 );
> +
> +    return 0;
>  }
>  
>  /************ TMEM CORE OPERATIONS ************************************/
> @@ -2282,9 +2288,6 @@ long do_tmem_op(tmem_cli_op_t uops)
>      struct tmem_pool *pool = NULL;
>      struct oid *oidp;
>      int rc = 0;
> -    bool_t succ_get = 0, succ_put = 0;
> -    bool_t non_succ_get = 0, non_succ_put = 0;
> -    bool_t flush = 0, flush_obj = 0;

Um, OK, they seem to belong to a different patch?

>      bool_t write_lock_set = 0, read_lock_set = 0;
>  
>      if ( !tmem_initialized )
> @@ -2299,8 +2302,7 @@ long do_tmem_op(tmem_cli_op_t uops)
>      if ( unlikely(tmem_get_tmemop_from_client(&op, uops) != 0) )
>      {
>          tmem_client_err("tmem: can't get tmem struct from %s\n", tmem_client_str);
> -        rc = -EFAULT;
> -	return rc;
> +        return -EFAULT;

This too.
>      }
>  
>      if ( op.cmd == TMEM_CONTROL )
> @@ -2369,28 +2371,21 @@ long do_tmem_op(tmem_cli_op_t uops)
>                                op.u.creat.uuid[0], op.u.creat.uuid[1]);
>          break;
>      case TMEM_PUT_PAGE:
> -        tmem_ensure_avail_pages();
> -        rc = do_tmem_put(pool, oidp, op.u.gen.index, op.u.gen.cmfn,
> +        if ( tmem_ensure_avail_pages() )
> +            rc = do_tmem_put(pool, oidp, op.u.gen.index, op.u.gen.cmfn,
>                          tmem_cli_buf_null);
> -        if (rc == 1) succ_put = 1;
> -        else non_succ_put = 1;

which we ignore..
>          break;
>      case TMEM_GET_PAGE:
>          rc = do_tmem_get(pool, oidp, op.u.gen.index, op.u.gen.cmfn,
>                          tmem_cli_buf_null);
> -        if (rc == 1) succ_get = 1;
> -        else non_succ_get = 1;

ugh.
>          break;
>      case TMEM_FLUSH_PAGE:
> -        flush = 1;
>          rc = do_tmem_flush_page(pool, oidp, op.u.gen.index);
>          break;
>      case TMEM_FLUSH_OBJECT:
>          rc = do_tmem_flush_object(pool, oidp);
> -        flush_obj = 1;
>          break;
>      case TMEM_DESTROY_POOL:
> -        flush = 1;

Those really belong to a seperate cleanup patch.

>          rc = do_tmem_destroy_pool(op.pool_id);
>          break;
>      default:
> diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h
> index bf3be62..258e8e7 100644
> --- a/xen/include/xen/tmem_xen.h
> +++ b/xen/include/xen/tmem_xen.h
> @@ -164,13 +164,7 @@ static inline void __tmem_free_page(struct page_info *pi)
>      atomic_dec(&freeable_page_count);
>  }
>  
> -static inline unsigned long tmem_free_mb(void)
> -{
> -    return (tmem_page_list_pages + total_free_pages()) >> (20 - PAGE_SHIFT);
> -}
> -
>  /*  "Client" (==domain) abstraction */
> -
>  struct client;
>  static inline struct client *tmem_client_from_cli_id(domid_t cli_id)
>  {
> -- 
> 1.7.10.4
> 

  reply	other threads:[~2013-11-22 18:22 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20  8:46 [PATCH 01/16] tmem: cleanup: drop some debug code Bob Liu
2013-11-20  8:46 ` [PATCH 02/16] tmem: cleanup: drop useless function 'tmem_copy_page' Bob Liu
2013-11-20  8:46 ` [PATCH 03/16] tmem: cleanup: rm unused tmem_op Bob Liu
2013-11-22 17:38   ` Konrad Rzeszutek Wilk
2013-11-25  9:43     ` Jan Beulich
2013-11-25  9:52       ` Ian Campbell
2013-11-25  9:58         ` Jan Beulich
2013-11-25 16:37         ` Konrad Rzeszutek Wilk
2013-11-25 16:40           ` Ian Campbell
2013-11-25 17:09             ` Konrad Rzeszutek Wilk
2013-11-25 17:12               ` Ian Campbell
2013-11-25 19:56                 ` Konrad Rzeszutek Wilk
2013-11-26  8:56                   ` Bob Liu
2013-11-20  8:46 ` [PATCH 04/16] tmem: cleanup: rm unneeded parameters from put path Bob Liu
2013-11-22 17:54   ` Konrad Rzeszutek Wilk
2013-11-26  8:22     ` Bob Liu
2013-11-20  8:46 ` [PATCH 05/16] tmem: cleanup: rm unneeded parameters from get path Bob Liu
2013-11-22 17:55   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 06/16] tmem: cleanup: reorg do_tmem_put() Bob Liu
2013-11-22 18:04   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 07/16] tmem: drop unneeded is_ephemeral() and is_private() Bob Liu
2013-11-20  8:46 ` [PATCH 08/16] tmem: cleanup: rm useless EXPORT/FORWARD define Bob Liu
2013-11-22 18:05   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 09/16] tmem: cleanup: drop tmemc_list() temporary Bob Liu
2013-11-22 18:07   ` Konrad Rzeszutek Wilk
2013-11-26  8:28     ` Bob Liu
2013-11-22 21:00   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 10/16] tmem: cleanup: drop runtime statistics Bob Liu
2013-11-22 18:08   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 11/16] tmem: cleanup: drop tmem_lock_all Bob Liu
2013-11-20  8:46 ` [PATCH 12/16] tmem: cleanup: refactor the alloc/free path Bob Liu
2013-11-20  8:46 ` [PATCH 13/16] tmem: cleanup: __tmem_alloc_page: drop unneed parameters Bob Liu
2013-11-22 18:17   ` Konrad Rzeszutek Wilk
2013-11-26  8:41     ` Bob Liu
2013-11-26 17:38       ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 14/16] tmem: cleanup: drop useless functions from head file Bob Liu
2013-11-27 14:38   ` Andrew Cooper
2013-11-27 14:52     ` Konrad Rzeszutek Wilk
2013-11-27 14:59       ` Andrew Cooper
2013-11-27 15:55         ` Jan Beulich
2013-11-20  8:46 ` [PATCH 15/16] tmem: refator function tmem_ensure_avail_pages() Bob Liu
2013-11-22 18:22   ` Konrad Rzeszutek Wilk [this message]
2013-11-20  8:46 ` [PATCH 16/16] tmem: cleanup: rename tmem_relinquish_npages() Bob Liu
2013-11-20  9:08 ` [PATCH 01/16] tmem: cleanup: drop some debug code Jan Beulich
2013-11-20  9:19   ` Bob Liu
2013-11-20  9:25     ` Jan Beulich
2013-11-20 13:51       ` Konrad Rzeszutek Wilk
2013-11-20 14:21         ` Jan Beulich
2013-11-20 18:46           ` Konrad Rzeszutek Wilk

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=20131122182210.GI8120@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=keir@xen.org \
    --cc=lliubbo@gmail.com \
    --cc=xen-devel@lists.xenproject.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).