Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2687248ybh; Mon, 5 Aug 2019 05:14:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnlyVUSotFZGnD2HB0ZsTF8TIosfIT6HNhEnxziA7gxXvaKRaH6dJcTIpfMsuyC/YyOF8K X-Received: by 2002:a17:902:f089:: with SMTP id go9mr2181513plb.81.1565007285558; Mon, 05 Aug 2019 05:14:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565007285; cv=none; d=google.com; s=arc-20160816; b=RQs+fxnwO+Pj2i0fAH4KB5lXUpR8TzMA0Sb1rvYmcdtLFPevHJFxChuw589sTgUSl+ u6oOWd8LZwvWuttzrZIrWvnsr8c290LmcEuZTC5LdW+gNt42AN6awYxJlAnc0NENGTo4 38i++lWzD5xqwprbtRw57vsm+7CvgVi3k/5/fKJbTQsPzmlnIUyg6DsUFu3VcTkzVR4e 7ZZ0RVtCQ4TWv5fH3j/HSUwBs7AWYI1+UQCZyPkQ25839/lD8CuSIxErFmvMWlEv0h1J bwILlbKppV4BSCEj6+oU1dVIg14WRU6RMjpYNpaB212yvvQ9lSLtQkMMwGhx4+cq/yrm HpHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8XS5yB5Zx1o5Y90VEpEwgXwP/p1rqI4qodw+/b/6dZo=; b=lMLRLLCX/5xRrSyz5OxQLHFJ565AcgkP+pRqocEkt0Hxorzp1EoZN2FK5XpC99mU7C l8y492A/McSjQDH6XcZdrFLroCGEn3ZQNAhRxOxR5BfB7iSEGqWRJZUmOYEdR30zDLRL TKl3t7p0vnOOAsAqk63M/38xbYx2qjRukmVN1cKCIc/zv/wcz3clNIjuloSDcj/9pnVu jycz5AXyAQF6vBCYA8wAmf1mFTX0aU2zsvSSnMOEGFRHnfyfkIMHusRsRCMxB99XnTz5 pci8dCFv/6Uo8tzQ7TMcAQ/oXCgo3UlURkRcj1vnIOnrq9WmFsCzCOUC1kkUfeKLGz7C g5ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si37236073pgg.442.2019.08.05.05.14.30; Mon, 05 Aug 2019 05:14:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728660AbfHEMNS (ORCPT + 99 others); Mon, 5 Aug 2019 08:13:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:44478 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727349AbfHEMNS (ORCPT ); Mon, 5 Aug 2019 08:13:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 86CCFB63C; Mon, 5 Aug 2019 12:13:17 +0000 (UTC) Date: Mon, 5 Aug 2019 14:13:14 +0200 From: Michal Hocko To: Fuqian Huang Cc: Linux Kernel Mailing List Subject: Re: Is it safe to kmalloc a large size of memory in interrupt handler? Message-ID: <20190805121314.GN7597@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 05-08-19 19:57:54, Fuqian Huang wrote: > In the implementation of kmalloc. > when the allocated size is larger than KMALLOC_MAX_CACHE_SIZE, > it will call kmalloc_large to allocate the memory. > kmalloc_large -> > kmalloc_order_trace->kmalloc_order->alloc_pages->alloc_pages_current->alloc_pages_nodemask->get_page_from_freelist->node_reclaim->__node_reclaim->shrink_node->shrink_node_memcg->get_scan_count You shouldn't really get there when using GFP_NOWAIT/GFP_ATOMIC. > get_scan_count will call spin_unlock_irq which enables local interrupt. > As the local interrupt should be disabled in the interrupt handler. > It is safe to use kmalloc to allocate a large size of memory in > interrupt handler? It will work very unreliably because larger physically contiguous memory is not generally available without doing compaction after a longer runtime. In general I would recommend to use pre allocated buffers or defer the actual handling to a less restricted context if possible. -- Michal Hocko SUSE Labs