From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bob Liu Subject: [PATCH v2 14/16] tmem: refator function tmem_ensure_avail_pages() Date: Tue, 3 Dec 2013 10:19:15 +0800 Message-ID: <1386037157-27261-15-git-send-email-bob.liu@oracle.com> References: <1386037157-27261-1-git-send-email-bob.liu@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Vnfcz-0002g4-50 for xen-devel@lists.xenproject.org; Tue, 03 Dec 2013 02:22:21 +0000 Received: by mail-pa0-f42.google.com with SMTP id lj1so2263741pab.1 for ; Mon, 02 Dec 2013 18:22:17 -0800 (PST) In-Reply-To: <1386037157-27261-1-git-send-email-bob.liu@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: keir@xen.org, ian.campbell@citrix.com, JBeulich@suse.com List-Id: xen-devel@lists.xenproject.org tmem_ensure_avail_pages() doesn't return a value which is incorrect because the caller need to confirm whether there is enough memory. Signed-off-by: Bob Liu --- xen/common/tmem.c | 32 ++++++++++++++++++++------------ xen/include/xen/tmem_xen.h | 6 ------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/xen/common/tmem.c b/xen/common/tmem.c index bdadb6e..d3828e2 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -1292,22 +1292,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 ************************************/ @@ -2351,9 +2357,11 @@ 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); + else + rc = -ENOMEM; break; case TMEM_GET_PAGE: rc = do_tmem_get(pool, oidp, op.u.gen.index, op.u.gen.cmfn, diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h index 2379c43..eeaebc4 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