From patchwork Tue Jan 26 04:54:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 12045233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCE7BC433E6 for ; Tue, 26 Jan 2021 04:54:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 885F32256F for ; Tue, 26 Jan 2021 04:54:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 885F32256F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 251968D008D; Mon, 25 Jan 2021 23:54:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 203058D0076; Mon, 25 Jan 2021 23:54:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CA688D008D; Mon, 25 Jan 2021 23:54:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id ECC018D0076 for ; Mon, 25 Jan 2021 23:54:30 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A965B181AF5C3 for ; Tue, 26 Jan 2021 04:54:30 +0000 (UTC) X-FDA: 77746710300.02.sort51_4e1415d2758b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 8121B10097AA0 for ; Tue, 26 Jan 2021 04:54:30 +0000 (UTC) X-HE-Tag: sort51_4e1415d2758b X-Filterd-Recvd-Size: 6543 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Jan 2021 04:54:29 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id gx1so1522676pjb.1 for ; Mon, 25 Jan 2021 20:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zWzZEjtMI7dPvku+j5LOMBapAYYLqsSnngDI0xcSPtU=; b=mdZXnij8j2OhoSuz0AxfBhIxqiB+8yZ9jo3y8Eyh3ODyLDaCAyDWBPMrglhVBGkODv Crv1+LoHFbqcgWZZnnx6/1VH42DX6IXP0AbtgUKK9Hwhj8tjohWGrg0iNVALj8E40VLK z6I8tpUKtdoi+7EbBR7z/JUJLBMD3LUmZCurMjMSOZR8P46fh+ToDppHamydxYc8CWVv qQQ1O7kYy1617y4/KRAXlD3Dehj3QYGfjPvkDOZ6Slt4w9wxY1jLKpBsZbzzv/Ypq2Hv oIZDmQy5/Ze9lBQxTJ5oVqFmvxbJD35P165x33/BDl34KS+z/TIglWhWZ3uMMtmNbIwl XY8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zWzZEjtMI7dPvku+j5LOMBapAYYLqsSnngDI0xcSPtU=; b=udycvqTa4lpG5aGEAYaDEgpJWAxXkM67pRmSNvLQvTZdgmPQ2UuuWvqYmjOsHdWl7F lF5yENr4IGBUveE86dmA5AXS+0XP2bINGVfG1V2/Zgttkjbp9VKmp9FAubI3WBnH8PKv fIyXPpFPDeA4anbizag/Po5UKOLXhojvhvZTQ2cBBpvL74sYB/CR2ovQGxRFUWM+db5R FEJPEsfpr6amD+N6xb2TTdXpa6IKUPhEE3R/xt0dOn3WjCk3DXXKeSD9EGrygLEvJSBG tNMGkXKXq0GbdrYqvNTzmN+cKwUWRpLCCVTV6olPeNz51md6AGz417WIdZji39H0Glqk lFlQ== X-Gm-Message-State: AOAM532aYindlvFdxM1ZnIi7mJZ3H4R/h658123LHCG4UetkkHC4lcyH PESrCHC6iZXQ/OeshAgUcuIAe4dp5os= X-Google-Smtp-Source: ABdhPJywTkPitOcbrsL64q10OuxjK3xV19FLJoWY/kuHyIiloXjVdY125pYsW/JbsEdfQlC4T2Htig== X-Received: by 2002:a17:90a:4209:: with SMTP id o9mr4130449pjg.75.1611636869086; Mon, 25 Jan 2021 20:54:29 -0800 (PST) Received: from bobo.ozlabs.ibm.com (192.156.221.203.dial.dynamic.acc50-nort-cbr.comindico.com.au. [203.221.156.192]) by smtp.gmail.com with ESMTPSA id w184sm18803382pgb.71.2021.01.25.20.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 20:54:28 -0800 (PST) From: Nicholas Piggin To: linux-mm@kvack.org, Andrew Morton Cc: Nicholas Piggin , linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH 5/5] mm/vmalloc: improve allocation failure error messages Date: Tue, 26 Jan 2021 14:54:04 +1000 Message-Id: <20210126045404.2492588-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210126045404.2492588-1-npiggin@gmail.com> References: <20210126045404.2492588-1-npiggin@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There are several reasons why a vmalloc can fail, virtual space exhausted, page array allocation failure, page allocation failure, and kernel page table allocation failure. Add distinct warning messages for the main causes of failure, with some added information like page order or allocation size where applicable. Signed-off-by: Nicholas Piggin Reviewed-by: Christoph Hellwig --- mm/vmalloc.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 5ff190590fe4..4facf582a3be 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2790,6 +2790,10 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, if (!pages) { free_vm_area(area); + warn_alloc(gfp_mask, NULL, + "vmalloc size %lu allocation failure: " + "page array size %lu allocation failed", + area->nr_pages * PAGE_SIZE, array_size); return NULL; } @@ -2813,6 +2817,10 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, /* Successfully allocated i pages, free them in __vfree() */ area->nr_pages = i; atomic_long_add(area->nr_pages, &nr_vmalloc_pages); + warn_alloc(gfp_mask, NULL, + "vmalloc size %lu allocation failure: " + "page order %u allocation failed", + area->nr_pages * PAGE_SIZE, page_order); goto fail; } @@ -2824,15 +2832,17 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask, } atomic_long_add(area->nr_pages, &nr_vmalloc_pages); - if (vmap_pages_range(addr, addr + size, prot, pages, page_shift) < 0) + if (vmap_pages_range(addr, addr + size, prot, pages, page_shift) < 0) { + warn_alloc(gfp_mask, NULL, + "vmalloc size %lu allocation failure: " + "failed to map pages", + area->nr_pages * PAGE_SIZE); goto fail; + } return area->addr; fail: - warn_alloc(gfp_mask, NULL, - "vmalloc: allocation failure, allocated %ld of %ld bytes", - (area->nr_pages*PAGE_SIZE), size); __vfree(area->addr); return NULL; } @@ -2866,8 +2876,15 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, unsigned long real_align = align; unsigned int shift = PAGE_SHIFT; - if (!size || (size >> PAGE_SHIFT) > totalram_pages()) - goto fail; + if (WARN_ON_ONCE(!size)) + return NULL; + + if ((size >> PAGE_SHIFT) > totalram_pages()) { + warn_alloc(gfp_mask, NULL, + "vmalloc size %lu allocation failure: " + "exceeds total pages", real_size); + return NULL; + } if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP) && arch_vmap_pmd_supported(prot)) { @@ -2894,8 +2911,12 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, size = PAGE_ALIGN(size); area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | vm_flags, start, end, node, gfp_mask, caller); - if (!area) + if (!area) { + warn_alloc(gfp_mask, NULL, + "vmalloc size %lu allocation failure: " + "vm_struct allocation failed", real_size); goto fail; + } addr = __vmalloc_area_node(area, gfp_mask, prot, shift, node); if (!addr) @@ -2920,11 +2941,6 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, goto again; } - if (!area) { - /* Warn for area allocation, page allocations already warn */ - warn_alloc(gfp_mask, NULL, - "vmalloc: allocation failure: %lu bytes", real_size); - } return NULL; }