From patchwork Thu Jan 19 10:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D147AC00A5A for ; Thu, 19 Jan 2023 10:02:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AF386B007B; Thu, 19 Jan 2023 05:02:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 638326B007D; Thu, 19 Jan 2023 05:02:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2516B007E; Thu, 19 Jan 2023 05:02:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 38FCD6B007B for ; Thu, 19 Jan 2023 05:02:52 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0ED16A0D73 for ; Thu, 19 Jan 2023 10:02:52 +0000 (UTC) X-FDA: 80371109784.09.6DEFF1C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 926E51C0009 for ; Thu, 19 Jan 2023 10:02:50 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qrRTjUaY; spf=none (imf20.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674122570; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+SWYz7hAitAY6tJURkuPWfGlLqC5qa9HeAAlAfkW1oo=; b=lT2m81tTFHSbBO7xggZu5zmOPat7wqiuaaPkh1aPx1EvFkfeJ2gP03OHXVdf9Dnljrv83f Fo0ykkYbgp2HVsdnK1scERRiu9n0GCdkXsCGrAgGIhRopLGyLuDdtXCjR/caYR7OzgJEJG 105S50tEIWpdl8kDp5u+4O2UkHKfnsE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=qrRTjUaY; spf=none (imf20.hostedemail.com: domain of BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+d6c99cb0ec1a2cfa7d20+7088+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674122570; a=rsa-sha256; cv=none; b=tmivWtb5f1mYE7Yc5l8HxvWJYxwAcBOGsGlNoCxCcAtcqSlUVefrGqUoZ7UIzMvd/x94Z4 O4j3gnxJ/aow90uXompJ8jZ/c+pYzglPEVHpzpw1CMlOMSWbAAt0GG6TI5xsJGqbeB1q3k NUghJB5PH90NdPl1U7eu6InpKgb2+dQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+SWYz7hAitAY6tJURkuPWfGlLqC5qa9HeAAlAfkW1oo=; b=qrRTjUaYDJOmCjxy17FgDxWEgP 51+uM6Mfsapjtd/4ihiC3ANS3F7VKD9IWwZD6YcZVSjtxyiJI1j6utKXNPwtOG8PBim/BgmnfH90c oF7qPE/82eVpRek2eqn465b1yHMKUyCNvRFw+g1qFNmp6rrOh7MFHXomaUGrtIZCRSGgus1iLoQ+2 DyLp5CR10NKDD9p5TgM9fxwF2DMQBqFpWrtijghD0zLSKBXqaTzYouGA+SxOe/BZ9g2GSQImNnM1H LbWLum71fNWkQFfGV/9NGNjtFN2N7/vhW8Go0d8wo//8KS8w0kLwdD/ufq8XP5uP82xbG4N1NhKVe PcN8FAeA==; Received: from 089144197172.atnat0006.highway.a1.net ([89.144.197.172] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIRkr-004LY0-Um; Thu, 19 Jan 2023 10:02:48 +0000 From: Christoph Hellwig To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org Subject: [PATCH 03/10] mm: remove __vfree_deferred Date: Thu, 19 Jan 2023 11:02:19 +0100 Message-Id: <20230119100226.789506-4-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119100226.789506-1-hch@lst.de> References: <20230119100226.789506-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 926E51C0009 X-Stat-Signature: b5hqmtwhs4739pkf7d8y7y5xejm5zf1g X-HE-Tag: 1674122570-671675 X-HE-Meta: U2FsdGVkX18Ne5uCUfzy5mkDZ171JjsJTb/S/wJZ0XQQ9DLy5IYi1s0U4ZpOmVpDLPyUT0zwQsEy2c7/X2xIj2jz3ywojT3sAgIsCaNZxhDjClJEzJOiJToSXjTtzP/O7IIQUaElUmz24Rmdcq8J4W7CK0zHGYErtQqfmCXhP1GUPLT/6Wm6eMJZ9pffzF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, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fold __vfree_deferred into vfree_atomic, and call vfree_atomic early on from vfree if called from interrupt context so that the extra low-level helper can be avoided. Signed-off-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index b989828b45109a..fafb6227f4428f 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2769,20 +2769,6 @@ static void __vunmap(const void *addr, int deallocate_pages) kfree(area); } -static inline void __vfree_deferred(const void *addr) -{ - /* - * Use raw_cpu_ptr() because this can be called from preemptible - * context. Preemption is absolutely fine here, because the llist_add() - * implementation is lockless, so it works even if we are adding to - * another cpu's list. schedule_work() should be fine with this too. - */ - struct vfree_deferred *p = raw_cpu_ptr(&vfree_deferred); - - if (llist_add((struct llist_node *)addr, &p->list)) - schedule_work(&p->wq); -} - /** * vfree_atomic - release memory allocated by vmalloc() * @addr: memory base address @@ -2792,13 +2778,19 @@ static inline void __vfree_deferred(const void *addr) */ void vfree_atomic(const void *addr) { - BUG_ON(in_nmi()); + struct vfree_deferred *p = raw_cpu_ptr(&vfree_deferred); + BUG_ON(in_nmi()); kmemleak_free(addr); - if (!addr) - return; - __vfree_deferred(addr); + /* + * Use raw_cpu_ptr() because this can be called from preemptible + * context. Preemption is absolutely fine here, because the llist_add() + * implementation is lockless, so it works even if we are adding to + * another cpu's list. schedule_work() should be fine with this too. + */ + if (addr && llist_add((struct llist_node *)addr, &p->list)) + schedule_work(&p->wq); } /** @@ -2820,17 +2812,16 @@ void vfree_atomic(const void *addr) */ void vfree(const void *addr) { - BUG_ON(in_nmi()); + if (unlikely(in_interrupt())) { + vfree_atomic(addr); + return; + } + BUG_ON(in_nmi()); kmemleak_free(addr); + might_sleep(); - might_sleep_if(!in_interrupt()); - - if (!addr) - return; - if (unlikely(in_interrupt())) - __vfree_deferred(addr); - else + if (addr) __vunmap(addr, 1); } EXPORT_SYMBOL(vfree);