From patchwork Mon Jan 30 20:49:38 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: 13121824 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 26796C54EAA for ; Mon, 30 Jan 2023 20:52:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 909146B007E; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 841FC6B007B; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0C56B007E; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4E5856B007B for ; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 18C8E160BF3 for ; Mon, 30 Jan 2023 20:51:59 +0000 (UTC) X-FDA: 80412662358.09.DFCC362 Received: from out-121.mta0.migadu.com (out-121.mta0.migadu.com [91.218.175.121]) by imf13.hostedemail.com (Postfix) with ESMTP id 0FDD520015 for ; Mon, 30 Jan 2023 20:51:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.121 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=1675111917; 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=n2WDy/mEQLvnsHLslgORbsPKJysJoBtCH/6FUJBS3Gs=; b=fHr/KW/AnN1Ss902qSMTgnrDv8BG3dpz13fOMzTYP1oGSA8C19dCKCXj21HQ46U0/SJVuB 7I5pmKEEDlMFAoi/8xnLbstok8yMs6bzs/LyafCIAD9ReRtnzWksts600cdvv5nWCn/w+N hn4f8QzDT4xYW8uHm5ZUS5BPdgGodkQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.121 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=1675111917; a=rsa-sha256; cv=none; b=kCvQMjgYXl2TK7iEBxZllQzlERHNY07Hr274+ZYXlS2sXWxuYxxekrobwSi8+T+9s/W5Gr wTjZeDbPX7BBCF6wBQ4L9XuMg4ajeibQe+33Dl3RFgWSPhBT9qwF8Dy4YM0dXmP9YXJqfj 0MmJSVu94gPue7uMrAxRLBnP+K+Tpzg= 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=1675111915; 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=n2WDy/mEQLvnsHLslgORbsPKJysJoBtCH/6FUJBS3Gs=; b=g5/h01z3OWfSRlw1beHiwIL6fNUDX0iYu6MtlD/gLSgQhBt5T1xVKAwPQBKGTXJyigmSNM i1fbZwHKtli9NOUEtpO14qb9rNz2hYzP/sRDzf5riZ9Kbzr72tKm+GajdMspGquHMwwfM7 HWQDdIeZPBmj+w12/quHXidzO+Bki8s= 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 14/18] lib/stackdepot: annotate depot_init_slab and depot_alloc_stack Date: Mon, 30 Jan 2023 21:49:38 +0100 Message-Id: <3cf68a23da43cef0f8737f7a2c07f35ce6d841a7.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: bpkic8xq8gxctb1pgy6ncyr88ftebfy5 X-Rspam-User: X-Rspamd-Queue-Id: 0FDD520015 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111916-46548 X-HE-Meta: U2FsdGVkX18sfTf1sn/unpqKkLSBseYcB18Jd+9XHLTrbvOGWAZ1j6f72C40m29BmUGpoCsBezZzFP5E7ELmIvR6vlbt3Nl9zN8aoltbQR7EsVGSRTymB7MjOi/xh7lJ03o7jVS111i3EBcDuzYOcwto38lI3VdKQRfX7IqyFq1J0jEKM3Q+CHYfNMo1g89W6SN2ZJwFaLFYOi//nM84nMbkeV9h7nlX5i0ISt4kqU/KYc5ZO/6S3dmlbbG+7t4lUqrZovKXgz6nkG22SOv/CCQNGE1HZn+Ilvg2ZYj9PgQNkAc+wU0LmvyqWONruDCCCRMlCdXljHo2HT1FqEJJ4TLfqEj3Sb9UMTbO9rJqqTuV7vYWnEYkirhGVsi3y3fHw7OTHGO4mm3jkJ8kdxA2v9PUXwI5ezCBrIk/3oHT0PFVwva6hEvxLs4mWkPY8Qg5KRTQQIHrc0LIzYZ2g5GhCNri4v3H897UfbNyE3k+drercUADaPgm5MqRYav97txZfuowEses7q9Pt/JMODd+E800uXMEx+O9jETUL5WCMiwxOI2qsR1SA9wLzo4jdjxyTXuSF9lNNv0vT8UfLt5RlYy/kTqojx8BCNzedvsf0r2RPo5hG70zvmFf6dAocRyDL/HgbrzauU8h6I4tKAO84wnwAxggfd/I1RsbOHslVVTwiU52mUMUDQQREK3hN2ixhKwZeyJhktfRbuqicg//qoVsC4HKl831W3MhRpripJvTfpIIew0fUDrkDrE8CWzO0PGcl366R30aMykV+vcHv5v91WVqHNj/UMnOw+iJD77IxTjuf6iWsGA+6VUrJtVHi9P5F2GDbs406H+U/2RGDrSQ+0SzsyPklYYbbhYJtu8RvMXRNt8m49kEAsAXxFdEYwRjwHZ74AxFxq3o/uzPII4Dow8Rn162mKV2JP70wzQmlDLTZjFG8hJGhxju9X8R5Se3N+JnfQw4RwmCeSu MdLvzYB1 d3WWPmjcmRc7F6HN21Nt9Rt4vpPXrsAsdHmpnEQr/hu3nZS8zROY6hNC1dZcKVh17nJS7AjubgviPI/JLChwKvmuEfiZWuFR2o9A3zVwpOOSkZE74OJa7H6y04oKceF93WDZWkBj15rmYnVxN7AS+FJQyeA== 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 Clean up the exisiting comments and add new ones to depot_init_slab and depot_alloc_stack. As a part of the clean-up, remove mentions of which variable is accessed by smp_store_release and smp_load_acquire: it is clear as is from the code. Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index d6be82a5c223..7282565722f2 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -218,33 +218,41 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); +/* Uses preallocated memory to initialize a new stack depot slab. */ static void depot_init_slab(void **prealloc) { /* - * This smp_load_acquire() pairs with smp_store_release() to - * |next_slab_inited| below and in depot_alloc_stack(). + * If the next slab is already initialized, do not use the + * preallocated memory. + * smp_load_acquire() here pairs with smp_store_release() below and + * in depot_alloc_stack(). */ if (smp_load_acquire(&next_slab_inited)) return; + + /* Check if the current slab is not yet allocated. */ if (stack_slabs[slab_index] == NULL) { + /* Use the preallocated memory for the current slab. */ stack_slabs[slab_index] = *prealloc; *prealloc = NULL; } else { - /* If this is the last depot slab, do not touch the next one. */ + /* + * Otherwise, use the preallocated memory for the next slab + * as long as we do not exceed the maximum number of slabs. + */ if (slab_index + 1 < DEPOT_MAX_SLABS) { stack_slabs[slab_index + 1] = *prealloc; *prealloc = NULL; /* * This smp_store_release pairs with smp_load_acquire() - * from |next_slab_inited| above and in - * stack_depot_save(). + * above and in stack_depot_save(). */ smp_store_release(&next_slab_inited, 1); } } } -/* Allocation of a new stack in raw storage */ +/* Allocates a new stack in a stack depot slab. */ static struct stack_record * depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) { @@ -253,28 +261,35 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) required_size = ALIGN(required_size, 1 << DEPOT_STACK_ALIGN); + /* Check if there is not enough space in the current slab. */ if (unlikely(slab_offset + required_size > DEPOT_SLAB_SIZE)) { + /* Bail out if we reached the slab limit. */ if (unlikely(slab_index + 1 >= DEPOT_MAX_SLABS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } + + /* Move on to the next slab. */ slab_index++; slab_offset = 0; /* - * smp_store_release() here pairs with smp_load_acquire() from - * |next_slab_inited| in stack_depot_save() and - * depot_init_slab(). + * smp_store_release() here pairs with smp_load_acquire() in + * stack_depot_save() and depot_init_slab(). */ if (slab_index + 1 < DEPOT_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } + + /* Assign the preallocated memory to a slab if required. */ if (*prealloc) depot_init_slab(prealloc); + + /* Check if we have a slab to save the stack trace. */ if (stack_slabs[slab_index] == NULL) return NULL; + /* Save the stack trace. */ stack = stack_slabs[slab_index] + slab_offset; - stack->hash = hash; stack->size = size; stack->handle.slab_index = slab_index;