From patchwork Mon Jan 30 20:49:31 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: 13121818 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 04DD7C636CD for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E1796B0071; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 890BF6B0072; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 758916B0073; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 641706B0071 for ; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3C040140462 for ; Mon, 30 Jan 2023 20:50:55 +0000 (UTC) X-FDA: 80412659670.12.4C601C5 Received: from out-38.mta0.migadu.com (out-38.mta0.migadu.com [91.218.175.38]) by imf27.hostedemail.com (Postfix) with ESMTP id 7546640003 for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.38 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=1675111853; 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=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=z96PzhfQuuHd3qGWW4mlehSOaJKODtwqVjIwNtoVNAvSkRzWBJoxrr25EfPl+EV61bymj8 Q5DmwG2t+0y+5Ecswny5d7YnmAaAaUWIfejOYP47Zo+2Ovr7qhl4E9Jt2kCjyxC4DUnjC9 2uz5jt0fSVK37Jd8H46+wJCVFsg1NDE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.38 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=1675111853; a=rsa-sha256; cv=none; b=mbNnYfcoJtZf82YwBUc91c9jq2des30Uzs5KmFk/nQQrvmOLwBDhL2qqEwF8+hhTzUiadV NPZQibK4W3Chi8SyBrrW09u5yPB/o+CdBQPkQxe8HjD1uuIHtXZ+6M5arAQSl1Qurltl8q r1UIBGIhhSBQhk5CFCdvv0Rm2dF6zeY= 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=1675111851; 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=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=OaUFrjC9mmR+C+LBAr653ALAA4e7MQZabwuqvf4knolohngrfhCy2mosvw6gzcWCNRkTMN e4lFrKKKYsFoufKHKOU+htEFWJY05stO+hGZZ42o5pGje6WBWk41AYL8bVD4znF7k68LuE CXnkNDDkYwdEcPDPk+BQYLTO4g/oDug= 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 07/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Mon, 30 Jan 2023 21:49:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7546640003 X-Stat-Signature: aexwkmdhuk619rdtyey5hpqwk6yqi5kx X-Rspam-User: X-HE-Tag: 1675111853-263877 X-HE-Meta: U2FsdGVkX1/umiT4aO7Sku5Fl8RRjQVmsyj36kiBqM90xEPnr8jG2c4SgZhW05yJm1bSOujHjGB1mkZVQEBWKEznhSRlePKgEFamDSzDWDW5KmYva+ll3Xt0SlgEQmZiy/Fo/Epp3z8eaP77Je+PsSjlBeuYaFELAsnWsZD5WSQm0+SMDv0boiTF1aFx19rD8CbVg5dyVJM4X1diEinvOl6cO3LddlDctPtC2ECqmEVD9wwUFmuFg4UIwfZvGHJXcKJLlV4h7lG2i9cNJX1WOykJRh//9YGKKxucdJ4frH8M9/d1Urj0h9karJQQt5Pcjm0WJNXMv1o4RGBA7ufvfs3nR92GQZLV7kFkJCqW9nkMuQzj+t+Q8gS768pbd2hK4Rc4LH5aprTCnPnra7Z5fr26x5itSTXMCD0OHMy28PX0800P/r98CHKyncfBQYIxlrxYRI/QghP948+OXoGmSQuAVDDOZuQzQEuxsuR65Nk57otdGSm8IU7/SAP5B7d+pBOhLcup7ziRhycAF+NywbwBeYXP8+x8HtQXDpZ4EtV4FHESQcGjlod8mh5nziWALhBAW5r8E3rjx2Wa/8vcbaykTtBo+TKJosq21hgp3AJXpDiXN/01Gibkhmg8kW5tb0ZhlYpSoQUujMbsye0WF0wlA+LZn5ZPJ/a72lPNl5a8N6Ne5uWVrKdr724/Idmnabb1/rcHZQtPII72xziRPQm0HOyT6qnm3ePjeB0na4iCsQZ3nLZIJtNqGUt+YPpuCdEwzC3SzvJlfNEyqgm0iaGRm/aemeNjj51qNusEa0rEt79Ts8+RJA9uBmTTejzTLqV0AfTG4Ogd6nCAa2809brWE0J3WmopXAQb4TuSCDHrV+Aeb6SWnjYXJL3L2PuvRLCw/vhzB8NPEdl/Y9vD9Rly1pG22JB4jm4iz9LoCuJXaAix2sB8BjwiNKLi44HDkEr84D2sg+ssdifa0EG CdnFuswY Foa4VRxHYuMkn/klIcw79oDEqur0BTe8v9jtKY+pN13tc07m7MIdHjdvyecnYU49G3zjQFRPiufty2vQ/2Px7dFh4/PtSoAx0pZbz6PNtVc/0ACJiDWdiHCMaFzPn7P0kGd27p83pjp0V+7IHHNhJOrP3Jg== 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index b06f6a5caa83..cb098bc99286 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);