From patchwork Fri Feb 10 21:15:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13136455 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 7C152C05027 for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A3646B018A; Fri, 10 Feb 2023 16:17:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 153426B018C; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0432C6B018D; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E83526B018A for ; Fri, 10 Feb 2023 16:17:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BE233AB880 for ; Fri, 10 Feb 2023 21:17:17 +0000 (UTC) X-FDA: 80452642914.23.30E54D3 Received: from out-147.mta1.migadu.com (out-147.mta1.migadu.com [95.215.58.147]) by imf04.hostedemail.com (Postfix) with ESMTP id 0AA7B40003 for ; Fri, 10 Feb 2023 21:17:15 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oyhVeDaz; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.147 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063836; a=rsa-sha256; cv=none; b=I6uIhrg9JeUn/+rutcKviN1CDQd53Zjd72YN4sLaJN1V6caAFYfos8SjVcNjNXvEm3Q0WW daWRA8IYs5nNPZGg+027D5hJB7zzzefX5nyTdV0a72LDkLq+dijOnDZRIPMMh6Z8u92egf GuL9dN+YieRhSB/If3kmvAIHNmc96KM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oyhVeDaz; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.147 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676063836; 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=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=DkhZeSMbR2Ob2+QSVO/QsKUHOGJDyvkJSLf6uKQtRsXJhW0BASx8D5hNBKcjCRj5BlwWg+ l3D9vehzIfd2NUbKkJWb8AK19D5uo5NdFOXxw6naRWW2CXDADbGKUZSjZNmsn6el5JhUQN yYCTLzb6tko3dgsEYclvzS6wH0O0VOc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1676063833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=oyhVeDazZBut0ST4TNl1RQwS/DL0yrlLv1E7JYFnymtKhHMiB0u4WihfIpRSbWuByfnfY8 ZL4ITqwDVRl0DLjQnKz5Wxc8IJHpjd/MW8dfSTAoazs2uZDQVgNmsTC1x8YcK2CMWQLY8D suYeEvzU/sxSRp/4iLW7FSTp/J4Bl7s= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 06/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Fri, 10 Feb 2023 22:15:54 +0100 Message-Id: <8e382f1f0c352e4b2ad47326fec7782af961fe8e.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 0AA7B40003 X-Rspamd-Server: rspam01 X-Stat-Signature: ggu1oncpy31b6iw6c94jjx1tmaozwimn X-HE-Tag: 1676063835-586352 X-HE-Meta: U2FsdGVkX1/MA9eJwvxa04ik2f8mPPbxC/iKLt2vRiJ33sq+3n/Cm3MSKo5nLjtg2xmavxA7Z9sm9sHp8bkmsm5Ji073Pgku/ZowPEWrw/OG1kOFE2RQ2VAf8a7Imipv8IM/Y5TD7IfsXVSL3MGJ/HpPstK0tYxkwIrZgQd53xXaSRwc4uH9DiPDWFQBCvuxXq+b8u4jm353KxwK1EHEP8wS4fUFnAivBGhfQbGcWvlTV9Ktw01tnh0uR0YtmWcvKdb5yM7wQOok6YTkbqRMfeJZWst86+dc6ezFBiVNQPg2hGw180Fc9XyCbsOSBZYLWwvm+CvPZgrxbcW/J/06r7qttZXASlY+6vFhdHkjEMl6hNCSz+b5DG4FBkHp4fDu3Dv+XOnnjLa+OY27nZC4AmzpAB5SVEojVv2Ius1ApI4NoA3AhPMiuoZ87/Eo48EcpPxF9MbqKW/tcLgn9DuVGG1qsp790bKfiEjvLdD3Vh2bROA8SLxox3raQXTBLML3dk8BVTqJiKdM3dlyKY6oMfAAxSjRBQOjtyK2saqjfqg3iZi3R3ajUG0+YbfQWg1cpaPN1m99cVHUsutKekmFjy+rIaZD5k0qpxwUdHaLWbxpks5ny/7p/p5Znh7xEbMvX2OPXuoz5QsDLlAJgRpJsAhiVt4vy9v35phkT4G0NrEJH7L+BGcuFHgh4NKOS8I7VDvZotpulLrjLdRPbfAzCNNoA+h+Fcfx3QRN3NTEX98dKoUq3v6auQI4f7nJz+huqfz1AY4LqWywQ7xByq3OT54br3MmSS/0RwvkzhHhRM4mzNmgNLDaJypRmHmHZ+nNqGjVTZqAROb+5lP4gthSBn1ToZwFBH452V8WYqHLzXn557s5VfvsUUSAyRAOz03ESfPN9E8nRK1hUgl4n1UFLY7KJlMxr8EsXkpMaroRfjFfG554v14DMsYT0kpxeBHUnf5+yr3IhAVwmAxhiK+ fcWR7TXd Yfmh3mt8y/H0JCFenD2J9RrJq82xuAmi3wTAE+8WCz5rcMUqDWS4AwpLEnrSe2lqJgdAqB33RZo1A1BNCzOzRElOvLTWVY6YLwvet7FT2eCUoZNt0ynPKB+NQLwUikQsAOpSOqW9iD+wt2pbJmzrPifMBZw== 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: From: Andrey Konovalov stack_depot_init does most things inside an if check. Move them out and use a goto statement instead. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 9fab711e4826..3c713f70b0a3 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -165,46 +165,50 @@ int __init stack_depot_early_init(void) int stack_depot_init(void) { static DEFINE_MUTEX(stack_depot_init_mutex); + unsigned long entries; int ret = 0; mutex_lock(&stack_depot_init_mutex); - if (!stack_depot_disabled && !stack_table) { - unsigned long entries; - /* - * Similarly to stack_depot_early_init, use stack_hash_order - * if assigned, and rely on automatic scaling otherwise. - */ - if (stack_hash_order) { - entries = 1UL << stack_hash_order; - } else { - int scale = STACK_HASH_SCALE; - - entries = nr_free_buffer_pages(); - entries = roundup_pow_of_two(entries); - - if (scale > PAGE_SHIFT) - entries >>= (scale - PAGE_SHIFT); - else - entries <<= (PAGE_SHIFT - scale); - } + if (stack_depot_disabled || stack_table) + goto out_unlock; - if (entries < 1UL << STACK_HASH_ORDER_MIN) - entries = 1UL << STACK_HASH_ORDER_MIN; - if (entries > 1UL << STACK_HASH_ORDER_MAX) - entries = 1UL << STACK_HASH_ORDER_MAX; - - pr_info("allocating hash table of %lu entries via kvcalloc\n", - entries); - stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); - if (!stack_table) { - pr_err("hash table allocation failed, disabling\n"); - stack_depot_disabled = true; - ret = -ENOMEM; - } - stack_hash_mask = entries - 1; + /* + * Similarly to stack_depot_early_init, use stack_hash_order + * if assigned, and rely on automatic scaling otherwise. + */ + if (stack_hash_order) { + entries = 1UL << stack_hash_order; + } else { + int scale = STACK_HASH_SCALE; + + entries = nr_free_buffer_pages(); + entries = roundup_pow_of_two(entries); + + if (scale > PAGE_SHIFT) + entries >>= (scale - PAGE_SHIFT); + else + entries <<= (PAGE_SHIFT - scale); } + + if (entries < 1UL << STACK_HASH_ORDER_MIN) + entries = 1UL << STACK_HASH_ORDER_MIN; + if (entries > 1UL << STACK_HASH_ORDER_MAX) + entries = 1UL << STACK_HASH_ORDER_MAX; + + pr_info("allocating hash table of %lu entries via kvcalloc\n", entries); + stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); + if (!stack_table) { + pr_err("hash table allocation failed, disabling\n"); + stack_depot_disabled = true; + ret = -ENOMEM; + goto out_unlock; + } + stack_hash_mask = entries - 1; + +out_unlock: mutex_unlock(&stack_depot_init_mutex); + return ret; } EXPORT_SYMBOL_GPL(stack_depot_init);