From patchwork Mon Apr 3 16:50:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9659983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2082160364 for ; Mon, 3 Apr 2017 16:52:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12FB728489 for ; Mon, 3 Apr 2017 16:52:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07E2128495; Mon, 3 Apr 2017 16:52:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E61628494 for ; Mon, 3 Apr 2017 16:52:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cv5Aq-0002oM-FR; Mon, 03 Apr 2017 16:49:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cv5Ap-0002mI-Bz for xen-devel@lists.xen.org; Mon, 03 Apr 2017 16:49:47 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 9C/9D-27545-B2D72E85; Mon, 03 Apr 2017 16:49:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsUyZ7p8oK5W7aM Ig+WXFCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owJC7+zFFwwq2i/Pou5gbFftYuRi0NIYAKT xPFNC9ggnF+MEu9Wr2OBcDYwSlyZ08gI4fQwSky4dZ61i5GTg03ASOLs0emMILaIgLTEtc+Xw YqYBRqYJJ6fOwjkcHAIC/hLvPhlDlLDIqAq0dG/F6yXV8BTYuWq90wgtoSAnMSO1U/AbE4BL4 nlzy6C2UJANauWvmGBqDGUOP1wG+MERr4FjAyrGDWKU4vKUot0jYz1kooy0zNKchMzc3QNDcz 0clOLixPTU3MSk4r1kvNzNzECg4UBCHYw/pkfeIhRkoNJSZT3g8KjCCG+pPyUyozE4oz4otKc 1OJDjDIcHEoSvMuqgXKCRanpqRVpmTnAsIVJS3DwKInwvgBJ8xYXJOYWZ6ZDpE4xKkqJ87aDJ ARAEhmleXBtsFi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWFejhqgKTyZeSVw018BLWYCWv zkzkOQxSWJCCmpBsZijV1riwJ/xrR+u/JqkTWviqxA42wLg5OKZ++/Om9w9V3Pkrj3U658PW+ 87odImZfMhG0tCU3vj2jOe7zKbtKM7lSuqZsXBJ7tSbippndJeHPq/KKvN5hmSNR/3BekYrL6 /HY2c3GThPRQPmHZeFuzbOPe+Xl7xEvUUq6vZFrl1FfowHrCLFSJpTgj0VCLuag4EQDOLIH1k AIAAA== X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1491238184!85859542!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 19878 invoked from network); 3 Apr 2017 16:49:46 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-13.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 3 Apr 2017 16:49:46 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v33GnbCm031470 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 3 Apr 2017 16:49:37 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v33GnaJB028073 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 3 Apr 2017 16:49:36 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v33GnadE010128; Mon, 3 Apr 2017 16:49:36 GMT Received: from ovs101.us.oracle.com (/10.149.76.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 03 Apr 2017 09:49:36 -0700 From: Boris Ostrovsky To: xen-devel@lists.xen.org Date: Mon, 3 Apr 2017 12:50:54 -0400 Message-Id: <1491238256-5517-8-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1491238256-5517-1-git-send-email-boris.ostrovsky@oracle.com> References: <1491238256-5517-1-git-send-email-boris.ostrovsky@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: sstabellini@kernel.org, wei.liu2@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com, Boris Ostrovsky Subject: [Xen-devel] [PATCH v2 7/9] mm: Keep pages available for allocation while scrubbing X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of scrubbing pages while holding heap lock we can mark buddy's head as being scrubbed and drop the lock temporarily. If someone (most likely alloc_heap_pages()) tries to access this chunk it will signal the scrubber to abort scrub by setting head's PAGE_SCRUB_ABORT bit. The scrubber checks this bit after processing each page and stops its work as soon as it sees it. Signed-off-by: Boris Ostrovsky --- xen/common/page_alloc.c | 76 ++++++++++++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/mm.h | 4 ++ xen/include/asm-x86/mm.h | 4 ++ 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 1c23991..666b79a 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -699,6 +699,18 @@ static void page_list_add_scrub(struct page_info *pg, unsigned int node, page_list_add(pg, &heap(node, zone, order)); } +static void check_and_stop_scrub(struct page_info *head) +{ + if ( head->u.free.scrub_state & PAGE_SCRUBBING ) + { + head->u.free.scrub_state |= PAGE_SCRUB_ABORT; + smp_mb(); + spin_lock_kick(); + while ( ACCESS_ONCE(head->u.free.scrub_state) & PAGE_SCRUB_ABORT ) + cpu_relax(); + } +} + /* Allocate 2^@order contiguous pages. */ static struct page_info *alloc_heap_pages( unsigned int zone_lo, unsigned int zone_hi, @@ -785,10 +797,15 @@ static struct page_info *alloc_heap_pages( { if ( (pg = page_list_remove_head(&heap(node, zone, j))) ) { - if ( (order == 0) || use_unscrubbed || - !test_bit(_PGC_need_scrub, &pg->count_info) ) + if ( !test_bit(_PGC_need_scrub, &pg[0].count_info) ) goto found; + if ( (order == 0) || use_unscrubbed ) + { + check_and_stop_scrub(pg); + goto found; + } + page_list_add_tail(pg, &heap(node, zone, j)); } } @@ -919,6 +936,8 @@ static int reserve_offlined_page(struct page_info *head) cur_head = head; + check_and_stop_scrub(head); + page_list_del(head, &heap(node, zone, head_order)); while ( cur_head < (head + (1 << head_order)) ) @@ -995,6 +1014,9 @@ static bool_t can_merge(struct page_info *buddy, unsigned int node, !!test_bit(_PGC_need_scrub, &buddy->count_info) ) return false; + if ( buddy->u.free.scrub_state & PAGE_SCRUBBING ) + return false; + return true; } @@ -1074,12 +1096,34 @@ static unsigned int node_to_scrub(bool_t get_node) } #define SCRUB_CHUNK_ORDER 8 + +struct scrub_wait_state { + struct page_info *pg; + bool_t drop; +}; + +static void scrub_continue(void *data) +{ + struct scrub_wait_state *st = (struct scrub_wait_state *)data; + + if ( st->drop ) + return; + + if ( st->pg->u.free.scrub_state & PAGE_SCRUB_ABORT ) + { + /* There is a waiter for this chunk. Release it. */ + st->drop = true; + st->pg->u.free.scrub_state = 0; + } +} + bool_t scrub_free_pages() { struct page_info *pg; unsigned int i, zone; unsigned int num_scrubbed, scrub_order, start, end; bool_t preempt, is_frag; + struct scrub_wait_state st; int order, cpu = smp_processor_id(); nodeid_t node; @@ -1100,7 +1144,10 @@ bool_t scrub_free_pages() if ( !test_bit(_PGC_need_scrub, &pg->count_info) ) break; - page_list_del(pg, &heap(node, zone, order)); + ASSERT(!pg->u.free.scrub_state); + pg->u.free.scrub_state = PAGE_SCRUBBING; + + spin_unlock(&heap_lock); scrub_order = MIN(order, SCRUB_CHUNK_ORDER); num_scrubbed = 0; @@ -1108,7 +1155,15 @@ bool_t scrub_free_pages() while ( num_scrubbed < (1 << order) ) { for ( i = 0; i < (1 << scrub_order); i++ ) + { scrub_one_page(&pg[num_scrubbed + i]); + if ( ACCESS_ONCE(pg->u.free.scrub_state) & PAGE_SCRUB_ABORT ) + { + /* Someone wants this chunk. Drop everything. */ + pg->u.free.scrub_state = 0; + goto out_nolock; + } + } num_scrubbed += (1 << scrub_order); if ( softirq_pending(cpu) ) @@ -1119,6 +1174,15 @@ bool_t scrub_free_pages() } } + st.pg = pg; + st.drop = false; + spin_lock_cb(&heap_lock, scrub_continue, &st); + + if ( st.drop ) + goto out; + + page_list_del(pg, &heap(node, zone, order)); + start = 0; end = num_scrubbed; @@ -1156,6 +1220,8 @@ bool_t scrub_free_pages() end += (1 << chunk_order); } + pg->u.free.scrub_state = 0; + if ( preempt ) goto out; } @@ -1164,6 +1230,8 @@ bool_t scrub_free_pages() out: spin_unlock(&heap_lock); + + out_nolock: node_clear(node, node_scrubbing); return softirq_pending(cpu) || (node_to_scrub(false) != NUMA_NO_NODE); } @@ -1203,6 +1271,8 @@ static void free_heap_pages( if ( page_state_is(&pg[i], offlined) ) tainted = 1; + pg[i].u.free.scrub_state=0; + /* If a page has no owner it will need no safety TLB flush. */ pg[i].u.free.need_tlbflush = (page_get_owner(&pg[i]) != NULL); if ( pg[i].u.free.need_tlbflush ) diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 149940b..b2d9dd3 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -35,6 +35,10 @@ struct page_info } inuse; /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */ struct { +#define PAGE_SCRUBBING (1<<1) +#define PAGE_SCRUB_ABORT (1<<2) + unsigned char scrub_state; + /* Do TLBs need flushing for safety before next page use? */ bool_t need_tlbflush; } free; diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index f3d4443..31e53e9 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -87,6 +87,10 @@ struct page_info /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */ struct { +#define PAGE_SCRUBBING (1<<1) +#define PAGE_SCRUB_ABORT (1<<2) + unsigned char scrub_state; + /* Do TLBs need flushing for safety before next page use? */ bool_t need_tlbflush; } free;