From patchwork Mon Feb 27 00:37:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Ostrovsky X-Patchwork-Id: 9592527 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 2115D60574 for ; Mon, 27 Feb 2017 00:18:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 133B3283F6 for ; Mon, 27 Feb 2017 00:18:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0821A283FD; Mon, 27 Feb 2017 00:18:52 +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 A7E9728405 for ; Mon, 27 Feb 2017 00:18:50 +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 1ci8zG-0000fj-Fk; Mon, 27 Feb 2017 00:16:22 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ci8zF-0000ev-Ek for xen-devel@lists.xen.org; Mon, 27 Feb 2017 00:16:21 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 69/C0-01711-4DF63B85; Mon, 27 Feb 2017 00:16:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsUyZ7p8oO6V/M0 RBhfauS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyZqxexFKzQr9h45D9jA+M5+S5GLg4hgYlM EpsfPmfqYuQEcn4zSnQt14VIbGSUaH9ylh3C6WGUOHBmCVgVm4CRxNmj0xlBbBEBaYlrny8zg hQxCzQwSTw/dxDI4eAQFgiXuLVcB6SGRUBVYuP016wgNq+Ap8SuzedYQGwJATmJHaufgM3kFP CSODaxkQ3iCk+Jrgv7WSFqDCVOP9zGOIGRbwEjwypGjeLUorLUIl1DA72kosz0jJLcxMwcIM9 ULze1uDgxPTUnMalYLzk/dxMjMFQYgGAH45qpzocYJTmYlER5FxlvjBDiS8pPqcxILM6ILyrN SS0+xCjDwaEkwbsib3OEkGBRanpqRVpmDjBoYdISHDxKIrxMwMAV4i0uSMwtzkyHSJ1iVJQS5 90O0icAksgozYNrg0XKJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzsoCM58nMK4Gb/gpoMR PQ4tkgN/MWlyQipKQaGEW5uJsLdIzfbW2wvTQlfEn6tz2zX9ifZeV28dqWP/337GOfjyTpNBV NflRww61bx6F7yrx2bpVKz6ufOOT8NHfeLlRMnnw67Eq/M09IdnRg/K+4lQ99jXlmJO1aPTuI R+5f6sF8t4mHLEPnuSnulFZw4woy+Cqx8XHxrI9SWx8z/Da3z7DepcRSnJFoqMVcVJwIAHcPK iCPAgAA X-Env-Sender: boris.ostrovsky@oracle.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1488154578!47964064!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 47154 invoked from network); 27 Feb 2017 00:16:19 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Feb 2017 00:16:19 -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 v1R0GAkh026130 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Feb 2017 00:16:10 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v1R0G9Ui016244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Feb 2017 00:16:10 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v1R0G8eV028388; Mon, 27 Feb 2017 00:16:09 GMT Received: from ovs101.us.oracle.com (/10.149.76.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 26 Feb 2017 16:16:08 -0800 From: Boris Ostrovsky To: xen-devel@lists.xen.org Date: Sun, 26 Feb 2017 19:37:08 -0500 Message-Id: <1488155829-2956-8-git-send-email-boris.ostrovsky@oracle.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1488155829-2956-1-git-send-email-boris.ostrovsky@oracle.com> References: <1488155829-2956-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 RESEND RFC 7/8] 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 | 67 +++++++++++++++++++++++++++++++++++++++++---- xen/include/asm-x86/mm.h | 4 +++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 3469185..a39afd4 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -687,6 +687,18 @@ static void check_low_mem_virq(void) } } +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(); + spink_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, @@ -773,10 +785,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[0].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)); } } @@ -911,6 +928,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)) ) @@ -990,6 +1009,9 @@ static bool_t can_merge(struct page_info *head, unsigned int node, !!test_bit(_PGC_need_scrub, &head->count_info) ) return 0; + if ( head->u.free.scrub_state & PAGE_SCRUBBING ) + return 0; + return 1; } @@ -1033,6 +1055,14 @@ static void merge_chunks(struct page_info *pg, unsigned int node, } #define SCRUB_CHUNK_ORDER 8 + +static bool_t scrub_continue(void *data) +{ + struct page_info *head = (struct page_info *)data; + + return !(ACCESS_ONCE(head->u.free.scrub_state) & PAGE_SCRUB_ABORT); +} + bool_t scrub_free_pages(unsigned int node) { struct page_info *pg; @@ -1064,14 +1094,25 @@ bool_t scrub_free_pages(unsigned int node) if ( !test_bit(_PGC_need_scrub, &pg[0].count_info) ) break; - page_list_del(pg, &heap(node, zone, order)); + ASSERT(!pg[0].u.free.scrub_state); + pg[0].u.free.scrub_state = PAGE_SCRUBBING; + + spin_unlock(&heap_lock); scrub_order = (order > SCRUB_CHUNK_ORDER) ? SCRUB_CHUNK_ORDER : order; num_scrubbed = 0; - while ( num_scrubbed < (1 << order) ) + while ( scrub_continue(&pg[0]) && num_scrubbed < (1 << order) ) { for ( i = 0; i < (1 << scrub_order); i++ ) + { scrub_one_page(&pg[num_scrubbed + i]); + if ( !scrub_continue(&pg[0]) ) + { + /* Someone wants this chunk. Drop everything. */ + pg[0].u.free.scrub_state = 0; + goto out_nolock; + } + } num_scrubbed += (1 << scrub_order); if ( softirq_pending(cpu) ) @@ -1080,7 +1121,15 @@ bool_t scrub_free_pages(unsigned int node) break; } } - + + if ( !spin_lock_cond(&heap_lock, scrub_continue, &pg[0]) ) + { + pg[0].u.free.scrub_state = 0; + goto out_nolock; + } + + page_list_del(pg, &heap(node, zone, order)); + start = 0; end = num_scrubbed; @@ -1118,7 +1167,9 @@ bool_t scrub_free_pages(unsigned int node) merge_chunks(ppg, node, zone, chunk_order, 1); end += (1 << chunk_order); } - + + pg[0].u.free.scrub_state = 0; + if ( preempt ) goto out; } @@ -1127,6 +1178,8 @@ bool_t scrub_free_pages(unsigned int node) out: spin_unlock(&heap_lock); + + out_nolock: clear_bit(node, &node_scrubbing); return (node_need_scrub[node] != 0); } @@ -1165,6 +1218,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-x86/mm.h b/xen/include/asm-x86/mm.h index b11124f..dd84835 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;