From patchwork Tue Aug 10 09:48:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12428551 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 55AF3C4338F for ; Tue, 10 Aug 2021 09:48:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D7B34610A7 for ; Tue, 10 Aug 2021 09:48:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D7B34610A7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 6D3C56B0072; Tue, 10 Aug 2021 05:48:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6847D8D0001; Tue, 10 Aug 2021 05:48:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 573D16B0074; Tue, 10 Aug 2021 05:48:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 42F906B0072 for ; Tue, 10 Aug 2021 05:48:56 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D9F2D20308 for ; Tue, 10 Aug 2021 09:48:55 +0000 (UTC) X-FDA: 78458697030.05.6F1BEF1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 8B88B5043BE3 for ; Tue, 10 Aug 2021 09:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628588935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=gxvJrIXCAPVngRCoulL08SruZXEWluc1auUZjvsayVg=; b=GxD75sYNCVPA/WK/exF4zuj+ezrhgnbcVpztxPNu/4JJoerVeHku1ep07vtjC2rFQR3xl9 LZBKlQ8o4f5KAhVG2WdRCL7lsSfB/j/I49mh459TW6FD0twK6PA+nbZFXf2Ao9rieETxTh 8VAIJDP9P0HCmv1kzaMLUK17cywS4Ow= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-pm95iwqfM_qMasqi8y-IJg-1; Tue, 10 Aug 2021 05:48:51 -0400 X-MC-Unique: pm95iwqfM_qMasqi8y-IJg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 066D939384; Tue, 10 Aug 2021 09:48:50 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FA1610013C1; Tue, 10 Aug 2021 09:48:45 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de, robin.murphy@arm.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, m.szyprowski@samsung.com, rppt@linux.ibm.com, Baoquan He Subject: [RFC PATCH v2 1/5] docs: kernel-parameters: Update to reflect the current default size of atomic pool Date: Tue, 10 Aug 2021 17:48:31 +0800 Message-Id: <20210810094835.13402-2-bhe@redhat.com> In-Reply-To: <20210810094835.13402-1-bhe@redhat.com> References: <20210810094835.13402-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GxD75sYN; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf05.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=bhe@redhat.com X-Stat-Signature: pb5a1p3iak8e7fheyqxtu3bp3wzkt7ac X-Rspamd-Queue-Id: 8B88B5043BE3 X-Rspamd-Server: rspam01 X-HE-Tag: 1628588935-320041 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: Since commit 1d659236fb43("dma-pool: scale the default DMA coherent pool size with memory capacity"), the default size of atomic pool has been changed to take by scaling with system memory capacity. So update the document in kerenl-parameter.txt accordingly. Signed-off-by: Baoquan He --- Documentation/admin-guide/kernel-parameters.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index bdb22006f713..970ed65db89f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -653,7 +653,9 @@ coherent_pool=nn[KMG] [ARM,KNL] Sets the size of memory pool for coherent, atomic dma - allocations, by default set to 256K. + allocations. Otherwise the default size will be scaled + with memory capacity, while clamped between 128K and + 1 << (PAGE_SHIFT + MAX_ORDER-1). com20020= [HW,NET] ARCnet - COM20020 chipset Format: From patchwork Tue Aug 10 09:48:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12428553 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B02A3C4338F for ; Tue, 10 Aug 2021 09:49:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5602561051 for ; Tue, 10 Aug 2021 09:49:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5602561051 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D8C1F6B0073; Tue, 10 Aug 2021 05:48:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3B796B0074; Tue, 10 Aug 2021 05:48:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2A286B0075; Tue, 10 Aug 2021 05:48:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id AD0C86B0073 for ; Tue, 10 Aug 2021 05:48:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4914B180273DB for ; Tue, 10 Aug 2021 09:48:59 +0000 (UTC) X-FDA: 78458697198.12.05432F7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf05.hostedemail.com (Postfix) with ESMTP id DADB950432B6 for ; Tue, 10 Aug 2021 09:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628588938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=RdY91bgYW5z7h5YowPXujpqtlKk0AVHYp/0WWPiO348=; b=Pf94kZmEo69Dovpb/no51ZLBHOP8+sTMbAZXFiInM+iicjJtDJcDjhiR1tfPhjKuG2PSEf 3HEfWgKp4p1Mb3VPijQ3VuDF2x3NFl+CU2xJ2hqp1D6dtAcuMNA7DvRHwqf2qd0do6LNpy K2MHsK0MAXYBEjadj+qY3ZkOcwP/VGM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-95-Og_HG3m-OgSC2e-x0COdxQ-1; Tue, 10 Aug 2021 05:48:57 -0400 X-MC-Unique: Og_HG3m-OgSC2e-x0COdxQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25D53107ACF5; Tue, 10 Aug 2021 09:48:55 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A7181036D05; Tue, 10 Aug 2021 09:48:50 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de, robin.murphy@arm.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, m.szyprowski@samsung.com, rppt@linux.ibm.com, Baoquan He Subject: [RFC PATCH v2 2/5] dma-pool: allow user to disable atomic pool Date: Tue, 10 Aug 2021 17:48:32 +0800 Message-Id: <20210810094835.13402-3-bhe@redhat.com> In-Reply-To: <20210810094835.13402-1-bhe@redhat.com> References: <20210810094835.13402-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Pf94kZmE; spf=none (imf05.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DADB950432B6 X-Stat-Signature: rqgt8b6sppg1aiw7oio4hcq836urac1o X-HE-Tag: 1628588938-315102 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: In the current code, three atomic memory pools are always created, atomic_pool_kernel|dma|dma32, even though 'coherent_pool=0' is specified in kernel command line. In fact, atomic pool is only necessary when CONFIG_DMA_DIRECT_REMAP=y or mem_encrypt_active=y which are needed on few ARCHes. So change code to allow user to disable atomic pool by specifying 'coherent_pool=0'. Meanwhile, update the relevant document in kernel-parameter.txt. Signed-off-by: Baoquan He --- Documentation/admin-guide/kernel-parameters.txt | 3 ++- kernel/dma/pool.c | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 970ed65db89f..620d38b5ce2d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -653,7 +653,8 @@ coherent_pool=nn[KMG] [ARM,KNL] Sets the size of memory pool for coherent, atomic dma - allocations. Otherwise the default size will be scaled + allocations. A value of 0 disables the three atomic + memory pool. Otherwise the default size will be scaled with memory capacity, while clamped between 128K and 1 << (PAGE_SHIFT + MAX_ORDER-1). diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index 5f84e6cdb78e..5a85804b5beb 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -21,7 +21,7 @@ static struct gen_pool *atomic_pool_kernel __ro_after_init; static unsigned long pool_size_kernel; /* Size can be defined by the coherent_pool command line */ -static size_t atomic_pool_size; +static unsigned long atomic_pool_size = -1; /* Dynamic background expansion when the atomic pool is near capacity */ static struct work_struct atomic_pool_work; @@ -188,11 +188,14 @@ static int __init dma_atomic_pool_init(void) { int ret = 0; + if (!atomic_pool_size) + return 0; + /* * If coherent_pool was not used on the command line, default the pool * sizes to 128KB per 1GB of memory, min 128KB, max MAX_ORDER-1. */ - if (!atomic_pool_size) { + if (atomic_pool_size == -1) { unsigned long pages = totalram_pages() / (SZ_1G / SZ_128K); pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES); atomic_pool_size = max_t(size_t, pages << PAGE_SHIFT, SZ_128K); From patchwork Tue Aug 10 09:48:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12428555 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 41766C4338F for ; Tue, 10 Aug 2021 09:49:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E456861076 for ; Tue, 10 Aug 2021 09:49:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E456861076 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 685A36B0074; Tue, 10 Aug 2021 05:49:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6367B6B0075; Tue, 10 Aug 2021 05:49:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5250F6B0078; Tue, 10 Aug 2021 05:49:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 3DA4E6B0074 for ; Tue, 10 Aug 2021 05:49:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D7E581803A18F for ; Tue, 10 Aug 2021 09:49:03 +0000 (UTC) X-FDA: 78458697366.22.1A85584 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 7C11B1001BC1 for ; Tue, 10 Aug 2021 09:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628588943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=XzR6lWp82u27j51uOwaAZXbU9KDrDW0NXcWuJSzfma4=; b=hjjsd+jf9YaouztqHbrTTYipE/rEgI2GEmxM4CJvJlYCoY47uQUbmZu5yQPnykuzmHVyRe dPjviJajLpRP+68Ke+cjXGyLPUWA8nuMUuQcvvo0aDaKD6R/kN5zFALaY4jZu4RnZ2eMbX FV3Oooc33IkAi1HakB7AhoVnG5r1KjA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-GKyu86l7Mde9uXBLYsrEWw-1; Tue, 10 Aug 2021 05:49:02 -0400 X-MC-Unique: GKyu86l7Mde9uXBLYsrEWw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42EB6107ACF5; Tue, 10 Aug 2021 09:49:00 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2D8D10013C1; Tue, 10 Aug 2021 09:48:55 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de, robin.murphy@arm.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, m.szyprowski@samsung.com, rppt@linux.ibm.com, Baoquan He Subject: [RFC PATCH v2 3/5] mm_zone: add function to check if managed dma zone exists Date: Tue, 10 Aug 2021 17:48:33 +0800 Message-Id: <20210810094835.13402-4-bhe@redhat.com> In-Reply-To: <20210810094835.13402-1-bhe@redhat.com> References: <20210810094835.13402-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hjjsd+jf; spf=none (imf07.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7C11B1001BC1 X-Stat-Signature: zgoq4ycm17xeqm6saft1hztdgjwghtjd X-HE-Tag: 1628588943-437836 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: In some places of the current kernel, it assumes that dma zone must have managed pages if CONFIG_ZONE_DMA is enabled. While this is not always true. E.g in kdump kernel of x86_64, only low 1M is presented and locked down at very early stage of boot, so that there's no managed pages at all in DMA zone. This exception will always cause page allocation failure if page is requested from DMA zone. Here add function has_managed_dma() and the relevant helper functions to check if there's DMA zone with managed pages. It will be used in later patches. Signed-off-by: Baoquan He --- include/linux/mmzone.h | 21 +++++++++++++++++++++ mm/page_alloc.c | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index fcb535560028..e3cd23fc5f64 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -975,6 +975,18 @@ static inline bool zone_is_zone_device(struct zone *zone) } #endif +#ifdef CONFIG_ZONE_DMA +static inline bool zone_is_dma(struct zone *zone) +{ + return zone_idx(zone) == ZONE_DMA; +} +#else +static inline bool zone_is_dma(struct zone *zone) +{ + return false; +} +#endif + /* * Returns true if a zone has pages managed by the buddy allocator. * All the reclaim decisions have to use this function rather than @@ -1023,6 +1035,7 @@ static inline int is_highmem_idx(enum zone_type idx) #endif } +bool has_managed_dma(void); /** * is_highmem - helper function to quickly check if a struct zone is a * highmem zone or not. This is an attempt to keep references @@ -1108,6 +1121,14 @@ extern struct zone *next_zone(struct zone *zone); ; /* do nothing */ \ else +#define for_each_managed_zone(zone) \ + for (zone = (first_online_pgdat())->node_zones; \ + zone; \ + zone = next_zone(zone)) \ + if (!managed_zone(zone)) \ + ; /* do nothing */ \ + else + static inline struct zone *zonelist_zone(struct zoneref *zoneref) { return zoneref->zone; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3e97e68aef7a..45dd1295416a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -9441,4 +9441,15 @@ bool take_page_off_buddy(struct page *page) spin_unlock_irqrestore(&zone->lock, flags); return ret; } + +bool has_managed_dma(void) +{ + struct zone *zone; + + for_each_managed_zone(zone) { + if (zone_is_dma(zone)) + return true; + } + return false; +} #endif From patchwork Tue Aug 10 09:48:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12428557 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 36B0AC4338F for ; Tue, 10 Aug 2021 09:49:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C46B261075 for ; Tue, 10 Aug 2021 09:49:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C46B261075 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 4FEFA6B0075; Tue, 10 Aug 2021 05:49:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 461576B0078; Tue, 10 Aug 2021 05:49:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 302706B007B; Tue, 10 Aug 2021 05:49:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 1360B6B0075 for ; Tue, 10 Aug 2021 05:49:12 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B37CB1F35D for ; Tue, 10 Aug 2021 09:49:11 +0000 (UTC) X-FDA: 78458697702.10.F9C3175 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 75CCD9000731 for ; Tue, 10 Aug 2021 09:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628588950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=/aC5i+VtNgDwxqN/egwfoCAzlz9LaELVpAqdunfQbhM=; b=a7KHbsrDKuJ2xsFBsDrRnWWwRgyRO3fRX2m2/fjaRuIun3/GKc3+EDC0UsnHTXf8eA/yxU p/5nW9kC6tDQXNehd4Koqi9AZ/MjruSdf13FWDIPK4dNLo74nTqbYsAZ7l3myGD0WpAcJu AYQZeQT4/SYytKZRJLZs5+y6CC+6p5A= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-265-Bg5aFaClPqeApzLR3tQNPg-1; Tue, 10 Aug 2021 05:49:07 -0400 X-MC-Unique: Bg5aFaClPqeApzLR3tQNPg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89C53875048; Tue, 10 Aug 2021 09:49:05 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id D07AB1000186; Tue, 10 Aug 2021 09:49:00 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de, robin.murphy@arm.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, m.szyprowski@samsung.com, rppt@linux.ibm.com, Baoquan He , iommu@lists.linux-foundation.org Subject: [RFC PATCH v2 4/5] dma/pool: create dma atomic pool only if dma zone has mamaged pages Date: Tue, 10 Aug 2021 17:48:34 +0800 Message-Id: <20210810094835.13402-5-bhe@redhat.com> In-Reply-To: <20210810094835.13402-1-bhe@redhat.com> References: <20210810094835.13402-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a7KHbsrD; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf23.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=bhe@redhat.com X-Stat-Signature: 9kh1t96d8xj7zzbn7hs1qi7qo8yfyyt8 X-Rspamd-Queue-Id: 75CCD9000731 X-Rspamd-Server: rspam01 X-HE-Tag: 1628588951-734974 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: Currently three dma atomic pools are initialized as long as the relevant kernel codes are built in. While in kdump kernel of x86_64, this is not right when trying to create atomic_pool_dma, because there's no managed pages in DMA zone. In the case, DMA zone only has low 1M memory presented and locked down by memblock allocator. So no pages are added into buddy of DMA zone. Please check commit f1d4d47c5851 ("x86/setup: Always reserve the first 1M of RAM"). Then in kdump kernel of x86_64, it always prints below failure message: DMA: preallocated 128 KiB GFP_KERNEL pool for atomic allocations swapper/0: page allocation failure: order:5, mode:0xcc1(GFP_KERNEL|GFP_DMA), nodemask=(null),cpuset=/,mems_allowed=0 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.13.0-0.rc5.20210611git929d931f2b40.42.fc35.x86_64 #1 Hardware name: Dell Inc. PowerEdge R910/0P658H, BIOS 2.12.0 06/04/2018 Call Trace: dump_stack+0x7f/0xa1 warn_alloc.cold+0x72/0xd6 ? _raw_spin_unlock_irq+0x24/0x40 ? __alloc_pages_direct_compact+0x90/0x1b0 __alloc_pages_slowpath.constprop.0+0xf29/0xf50 ? __cond_resched+0x16/0x50 ? prepare_alloc_pages.constprop.0+0x19d/0x1b0 __alloc_pages+0x24d/0x2c0 ? __dma_atomic_pool_init+0x93/0x93 alloc_page_interleave+0x13/0xb0 atomic_pool_expand+0x118/0x210 ? __dma_atomic_pool_init+0x93/0x93 __dma_atomic_pool_init+0x45/0x93 dma_atomic_pool_init+0xdb/0x176 do_one_initcall+0x67/0x320 ? rcu_read_lock_sched_held+0x3f/0x80 kernel_init_freeable+0x290/0x2dc ? rest_init+0x24f/0x24f kernel_init+0xa/0x111 ret_from_fork+0x22/0x30 Mem-Info: ...... DMA: failed to allocate 128 KiB GFP_KERNEL|GFP_DMA pool for atomic allocation DMA: preallocated 128 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations Here, let's check if DMA zone has managed pages, then create atomic_pool_dma if yes. Otherwise just skip it. Signed-off-by: Baoquan He Cc: Christoph Hellwig Cc: Marek Szyprowski Cc: Robin Murphy Cc: iommu@lists.linux-foundation.org --- kernel/dma/pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index 5a85804b5beb..00df3edd6c5d 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -206,7 +206,7 @@ static int __init dma_atomic_pool_init(void) GFP_KERNEL); if (!atomic_pool_kernel) ret = -ENOMEM; - if (IS_ENABLED(CONFIG_ZONE_DMA)) { + if (has_managed_dma()) { atomic_pool_dma = __dma_atomic_pool_init(atomic_pool_size, GFP_KERNEL | GFP_DMA); if (!atomic_pool_dma) @@ -229,7 +229,7 @@ static inline struct gen_pool *dma_guess_pool(struct gen_pool *prev, gfp_t gfp) if (prev == NULL) { if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32)) return atomic_pool_dma32; - if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA)) + if (atomic_pool_dma && (gfp & GFP_DMA)) return atomic_pool_dma; return atomic_pool_kernel; } From patchwork Tue Aug 10 09:48:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12428559 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=-16.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 F17F5C4338F for ; Tue, 10 Aug 2021 09:49:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9C83B61076 for ; Tue, 10 Aug 2021 09:49:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9C83B61076 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D19616B007D; Tue, 10 Aug 2021 05:49:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C03C96B007B; Tue, 10 Aug 2021 05:49:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA3628D0001; Tue, 10 Aug 2021 05:49:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 8D9026B0078 for ; Tue, 10 Aug 2021 05:49:14 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 421EE8249980 for ; Tue, 10 Aug 2021 09:49:14 +0000 (UTC) X-FDA: 78458697828.36.AD5A38B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id F1CE4D0004AD for ; Tue, 10 Aug 2021 09:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628588953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=j/EQ6+OMl4MXWKt0VGOxH4vRyLnzoc9qFt3VsEGqLrU=; b=AUdptr7Fw8OiMsoX+Dj6LicXvOS9zs0TAggpiV+IuH4d87mS5JKSWm2raO3N/WTDOxJrPW +5BJtnRHhzhn3JZR9hq7CQqbL2k7k/wq8mi23J1hHPIpznxkKpV4a7sm7g1d4rSyj0/l/G 3YoHgEcWSLzSsfQwzY0NBxFhD+0SRAA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-68-v8RYn7x8Nh6PHDqNUKPg0g-1; Tue, 10 Aug 2021 05:49:12 -0400 X-MC-Unique: v8RYn7x8Nh6PHDqNUKPg0g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A988875049; Tue, 10 Aug 2021 09:49:10 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-79.pek2.redhat.com [10.72.12.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21D481036D33; Tue, 10 Aug 2021 09:49:05 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@lst.de, robin.murphy@arm.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, m.szyprowski@samsung.com, rppt@linux.ibm.com, Baoquan He Subject: [RFC PATCH v2 5/5] mm/slub: do not create dma-kmalloc if no managed pages in DMA zone Date: Tue, 10 Aug 2021 17:48:35 +0800 Message-Id: <20210810094835.13402-6-bhe@redhat.com> In-Reply-To: <20210810094835.13402-1-bhe@redhat.com> References: <20210810094835.13402-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F1CE4D0004AD Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AUdptr7F; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf15.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=bhe@redhat.com X-Stat-Signature: 7mtexrtqiipbpq6ywbiumpa9c14r69hq X-HE-Tag: 1628588953-224661 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: Dma-kmalloc will be created as long as CONFIG_ZONE_DMA is enabled. However, it will fail if DMA zone has no managed pages. The failure can be seen in kdump kernel of x86_64 as below: CPU: 0 PID: 65 Comm: kworker/u2:1 Not tainted 5.14.0-rc2+ #9 Hardware name: Intel Corporation SandyBridge Platform/To be filled by O.E.M., BIOS RMLSDP.86I.R2.28.D690.1306271008 06/27/2013 Workqueue: events_unbound async_run_entry_fn Call Trace: dump_stack_lvl+0x57/0x72 warn_alloc.cold+0x72/0xd6 __alloc_pages_slowpath.constprop.0+0xf56/0xf70 __alloc_pages+0x23b/0x2b0 allocate_slab+0x406/0x630 ___slab_alloc+0x4b1/0x7e0 ? sr_probe+0x200/0x600 ? lock_acquire+0xc4/0x2e0 ? fs_reclaim_acquire+0x4d/0xe0 ? lock_is_held_type+0xa7/0x120 ? sr_probe+0x200/0x600 ? __slab_alloc+0x67/0x90 __slab_alloc+0x67/0x90 ? sr_probe+0x200/0x600 ? sr_probe+0x200/0x600 kmem_cache_alloc_trace+0x259/0x270 sr_probe+0x200/0x600 ...... bus_probe_device+0x9f/0xb0 device_add+0x3d2/0x970 ...... __scsi_add_device+0xea/0x100 ata_scsi_scan_host+0x97/0x1d0 async_run_entry_fn+0x30/0x130 process_one_work+0x2b0/0x5c0 worker_thread+0x55/0x3c0 ? process_one_work+0x5c0/0x5c0 kthread+0x149/0x170 ? set_kthread_struct+0x40/0x40 ret_from_fork+0x22/0x30 Mem-Info: ...... The above failure happened when calling kmalloc() to allocate buffer with GFP_DMA. It requests to allocate slab page from DMA zone while no managed pages in there. sr_probe() --> get_capabilities() --> buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); The DMA zone should be checked if it has managed pages, then try to create dma-kmalloc. Signed-off-by: Baoquan He Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka --- mm/slab_common.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/slab_common.c b/mm/slab_common.c index 1c673c323baf..22350bef3bae 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -911,10 +911,16 @@ void __init create_kmalloc_caches(slab_flags_t flags) slab_state = UP; #ifdef CONFIG_ZONE_DMA + bool managed_dma = has_managed_dma(); + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i]; if (s) { + if (!managed_dma) { + kmalloc_caches[KMALLOC_DMA][i] = kmalloc_caches[KMALLOC_NORMAL][i]; + continue; + } kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache( kmalloc_info[i].name[KMALLOC_DMA], kmalloc_info[i].size,