From patchwork Fri Aug 5 17:35:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9265613 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 5824060754 for ; Fri, 5 Aug 2016 17:38:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E70E2842E for ; Fri, 5 Aug 2016 17:38:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 433F42845A; Fri, 5 Aug 2016 17:38: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 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 D79502842E for ; Fri, 5 Aug 2016 17:38:51 +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 1bVj2Z-0006aK-QG; Fri, 05 Aug 2016 17:36:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVj2Y-0006Wu-3w; Fri, 05 Aug 2016 17:36:10 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 20/2A-03271-88EC4A75; Fri, 05 Aug 2016 17:36:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKLMWRWlGSWpSXmKPExsVyuP0Ov27HuSX hBl+XSlm8/bqE2eL7lslMDkwehz9cYQlgjGLNzEvKr0hgzVi95Q5LwXG2iv1bMhoYH7N0MXJy SAgYSbyd+I+pi5GLQ0hgIaPEp55d7CAJNgFViQ3XT7GC2CICbhJfvs9iA7GZBSIk5nw4BdYsL BAusfjnTLB6FqD6ybPvAg3i4OAVsJdY9NoCYr6cxPWZ05lAbE4BB4mFq5eA2UJAJW8ONbNNYO RewMiwilGjOLWoLLVI19BYL6koMz2jJDcxM0fX0MBYLze1uDgxPTUnMalYLzk/dxMj0MsMQLC Dcdt2z0OMkhxMSqK8avuWhAvxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4NU9C5QTLEpNT61Iy8wB hhtMWoKDR0mE988ZoDRvcUFibnFmOkTqFKMux4Ift9cyCbHk5eelSonzWoPMEAApyijNgxsBC /1LjLJSwryMQEcJ8RSkFuVmlqDKv2IU52BUEua1BZnCk5lXArfpFdARTEBHfLQCO6IkESEl1c C46v0x8SMOXepSlYKq+RwydSs2r7siM9UzZMFrpV1x6r4862uT5xnN49U7ulRmbdkCpXROocT Ca3cefGJ4mZNZ9vL86bli93ecCcs4c/zkC77DLx9f5LfeWzZDgLtl0tkrZw4nm9q80/X3eV6v EHK4++nNLW/1JI+zb85Rd3lY9oi/lklVgIFViaU4I9FQi7moOBEAzvWTlHgCAAA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1470418568!53623896!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17027 invoked from network); 5 Aug 2016 17:36:08 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-13.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 5 Aug 2016 17:36:08 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1CC2FAD61; Fri, 5 Aug 2016 17:36:08 +0000 (UTC) From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Date: Fri, 5 Aug 2016 19:35:50 +0200 Message-Id: <1470418562-11234-7-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1470418562-11234-1-git-send-email-jgross@suse.com> References: <1470418562-11234-1-git-send-email-jgross@suse.com> Cc: Juergen Gross , samuel.thibault@ens-lyon.org, wei.liu2@citrix.com Subject: [Xen-devel] [PATCH v2 06/18] mini-os: let memory allocation fail if no free page available 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 panicing when no page can be allocated try to fail the memory allocation by returning NULL instead. Signed-off-by: Juergen Gross Reviewed-by: Wei Liu Acked-by: Samuel Thibault --- V2: fixed minor style issue --- mm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm.c b/mm.c index 263a356..8cf3210 100644 --- a/mm.c +++ b/mm.c @@ -335,6 +335,13 @@ void *sbrk(ptrdiff_t increment) if (new_brk > heap_mapped) { unsigned long n = (new_brk - heap_mapped + PAGE_SIZE - 1) / PAGE_SIZE; + + if ( n > nr_free_pages ) + { + printk("Memory exhausted: want %ld pages, but only %ld are left\n", + n, nr_free_pages); + return NULL; + } do_map_zero(heap_mapped, n); heap_mapped += n * PAGE_SIZE; }