From patchwork Mon Jul 18 19:28:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12921673 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 E99FBC433EF for ; Mon, 18 Jul 2022 19:29:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1669B940011; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A11E94000D; Mon, 18 Jul 2022 15:29:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D739F940011; Mon, 18 Jul 2022 15:29:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id BE89C94000D for ; Mon, 18 Jul 2022 15:29:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9991B80BA2 for ; Mon, 18 Jul 2022 19:29:04 +0000 (UTC) X-FDA: 79701208608.17.0B190E7 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) by imf06.hostedemail.com (Postfix) with ESMTP id 4678018004E for ; Mon, 18 Jul 2022 19:29:04 +0000 (UTC) Received: by mail-qv1-f50.google.com with SMTP id cw12so9538915qvb.12 for ; Mon, 18 Jul 2022 12:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/K1YhC0xN+k7O2FGj/yOUKehgh1HnqMHevQj0FQmavI=; b=hncdckdd/8keGq0BbMkUSkVvo58eaSfk46icZhjcfux7VapB1d8lOZsIlqh8gYAlwO nsH6TNRxQKop1KFXKAjUK6jXGpI96ZhzGYzEb1l58Uuid0BejJtLScjUXd1FwD7d6d0I n6nBpJsBMCWPJZOY2isxybjgVNgOUtIwy5syFw6dhjVkH48EFPjJXnsXMjILmWWh6aNt 1XjXQ+KmT1tei8OVv0kOBxiaSSBAGf1jRYjjXWTW/jEj/bm8gP4G3KDncFs30f51O1n9 KoibE09XlnBMUE30LzuwHeutbdP4Gw0vPBuJAXfM44toJn9n4BYblu9g3pXR4SHa5Cz4 j6aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/K1YhC0xN+k7O2FGj/yOUKehgh1HnqMHevQj0FQmavI=; b=7PpjEf/fF1xG6r4lTMf7XKxUj5lLVPKmh3i0nPhtNViAfPQjazg2fYyla1YIa1Tsk7 ifd+n3UJmLjGZc5brBTufL1LVPQ3YDbNQu3npye7X/YZGAjc2Hra9+HmtDP0v8h+oAzE Nsx0xzA+jBub16YWyZPmT1HURLgdlptywHQIHIxT6youJcxxv1Bozw+okoP2zY8cHyS4 iTXQHra6EhcjXlYhY1v2nRnZ0r5qgqaRFZUuGau48uTPxsg8ksrg9auxUpYpIWMIUZjL HotcNyxEzeLpjEL7C673V70wVf6OR/BpxW0AmNbN8I9hV8JM1TEr1zsf+fRDIoB5iimd 0r2w== X-Gm-Message-State: AJIora/0049xjdwWwSlAcACFLpB8NYovrNUhq2HfwH1L7cr7voOl7K3/ PMmicmamGcxFtrgR4chzVKs= X-Google-Smtp-Source: AGRyM1uDAtG39PkyBUTwcaTq2/uDHYY4DcIItWFReB0uOGieqEEzLgaz94Wt8f3sFC0ByQPjoqZW6g== X-Received: by 2002:a05:6214:226d:b0:473:339e:3264 with SMTP id gs13-20020a056214226d00b00473339e3264mr22107594qvb.41.1658172543484; Mon, 18 Jul 2022 12:29:03 -0700 (PDT) Received: from localhost ([2601:4c1:c100:1230:ab01:d009:465a:5ab1]) by smtp.gmail.com with ESMTPSA id bb31-20020a05622a1b1f00b0031ef21aec36sm2216383qtb.32.2022.07.18.12.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 12:29:03 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Alexander Lobakin , Alexei Starovoitov , Alexey Klimov , Andrew Morton , Andrii Nakryiko , Andy Shevchenko , Ben Segall , Christoph Lameter , Dan Williams , Daniel Borkmann , Daniel Bristot de Oliveira , Dennis Zhou , Dietmar Eggemann , Eric Dumazet , Frederic Weisbecker , Guenter Roeck , Ingo Molnar , Isabella Basso , John Fastabend , Josh Poimboeuf , Juergen Gross , Juri Lelli , KP Singh , Kees Cook , Martin KaFai Lau , Mel Gorman , Miroslav Benes , Nathan Chancellor , "Paul E . McKenney" , Peter Zijlstra , Randy Dunlap , Rasmus Villemoes , Sebastian Andrzej Siewior , Song Liu , Steven Rostedt , Tejun Heo , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vlastimil Babka , Yonghong Song , Yury Norov , linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH 14/16] mm/percpu: optimize pcpu_alloc_area() Date: Mon, 18 Jul 2022 12:28:42 -0700 Message-Id: <20220718192844.1805158-15-yury.norov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220718192844.1805158-1-yury.norov@gmail.com> References: <20220718192844.1805158-1-yury.norov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658172544; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/K1YhC0xN+k7O2FGj/yOUKehgh1HnqMHevQj0FQmavI=; b=AADVuvkZVueMVqqPw8lOjWaXkuyyGcgtREIn87b3wkGnQqTQ9yqG/WGP4a3UktVguRJ4ET W8VlvfDNmOvpDjUeOo5Ug54Susaz4X/WMFVIhiMVdqqu/ooTSKUBPjhij/vb85uT5HCPCH yZU05okTd4HmfhumiP/0KDFvBG6LhMM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658172544; a=rsa-sha256; cv=none; b=2AuU0kpcoBNJnwMu5rUrFH5vhIlRLc+FAoCTjohW8yyny/Jnwe/6Ocv/MCJ06PwT6L82E5 xJrk+f7b4M9xpNqiP06WNkEL5fXCJ/HVXfxfd9pc1lNyWkhFxxrGBaEF/4VubNXzUntlWJ 5pHJDt0p+lgE6SQFCgJ2dXkWxUYsETQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hncdckdd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.50 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-Stat-Signature: t8cbzdda9kkrj5bdaweu68knc935i1fx X-Rspam-User: X-Rspamd-Queue-Id: 4678018004E X-Rspamd-Server: rspam10 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hncdckdd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.50 as permitted sender) smtp.mailfrom=yury.norov@gmail.com X-HE-Tag: 1658172544-698995 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: Don't call bitmap_clear() to clear 0 bits. bitmap_clear() can handle 0-length requests properly, but it's not covered with static optimizations, and falls to __bitmap_set(). So we are paying a function call + prologue work cost just for nothing. Caught with CONFIG_DEBUG_BITMAP: [ 45.571799] [ 45.571801] pcpu_alloc_area+0x194/0x340 [ 45.571806] pcpu_alloc+0x2fb/0x8b0 [ 45.571811] ? kmem_cache_alloc_trace+0x177/0x2a0 [ 45.571815] __percpu_counter_init+0x22/0xa0 [ 45.571819] fprop_local_init_percpu+0x14/0x30 [ 45.571823] wb_get_create+0x15d/0x5f0 [ 45.571828] cleanup_offline_cgwb+0x73/0x210 [ 45.571831] cleanup_offline_cgwbs_workfn+0xcf/0x200 [ 45.571835] process_one_work+0x1e5/0x3b0 [ 45.571839] worker_thread+0x50/0x3a0 [ 45.571843] ? rescuer_thread+0x390/0x390 [ 45.571846] kthread+0xe8/0x110 [ 45.571849] ? kthread_complete_and_exit+0x20/0x20 [ 45.571853] ret_from_fork+0x22/0x30 [ 45.571858] [ 45.571859] ---[ end trace 0000000000000000 ]--- [ 45.571860] b1: ffffa8d5002e1000 [ 45.571861] b2: 0 [ 45.571861] b3: 0 [ 45.571862] nbits: 44638 [ 45.571863] start: 44638 [ 45.571864] off: 0 [ 45.571864] percpu: Bitmap: parameters check failed [ 45.571865] percpu: include/linux/bitmap.h [538]: bitmap_clear Signed-off-by: Yury Norov Acked-by: Dennis Zhou --- mm/percpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index 3633eeefaa0d..f720f7c36b91 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1239,7 +1239,8 @@ static int pcpu_alloc_area(struct pcpu_chunk *chunk, int alloc_bits, /* update boundary map */ set_bit(bit_off, chunk->bound_map); - bitmap_clear(chunk->bound_map, bit_off + 1, alloc_bits - 1); + if (alloc_bits > 1) + bitmap_clear(chunk->bound_map, bit_off + 1, alloc_bits - 1); set_bit(bit_off + alloc_bits, chunk->bound_map); chunk->free_bytes -= alloc_bits * PCPU_MIN_ALLOC_SIZE;