From nobody Mon Feb 9 00:05:03 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66119C4332F for ; Tue, 12 Dec 2023 02:28:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345710AbjLLC2C (ORCPT ); Mon, 11 Dec 2023 21:28:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231416AbjLLC15 (ORCPT ); Mon, 11 Dec 2023 21:27:57 -0500 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B21D6 for ; Mon, 11 Dec 2023 18:28:02 -0800 (PST) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-5cbcfdeaff3so52269927b3.0 for ; Mon, 11 Dec 2023 18:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702348080; x=1702952880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EbntnK4HNa/CvcX2c9tw9yKQZtz2j41lTpG1pzcXcKI=; b=nl+nuKzExYNXseyTves7Xp5mnTvjWfv3Lv0vFI9pzpyDfHJlD9SOkItEvulJrISpI9 FkDCgIkQOR1iwNcGKMVFftVOABCvlQzXg9Nr7Fvhvs0qCLbFHQnaJPSZ8BmgOlSf64ZU K0CtuQ9rFPTeD2xi9XPGVQnmvSHm35RQ770x1F8Ux0DUHDuNjiSXsarRSwXippCaARIp /QBz3Q5DgLjeUA58ZQBxBrThHjlwjjgrvnTl3EOakdfDY6ymtHCll9CbvBt9kpCs9KHB 3kBzRytQ/0K6wtWZYQ3W/DhZUFyRI3jQkYNbrP4gSFivh0AjKoFP+/btFk9lOzYx4AGe zZZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702348080; x=1702952880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EbntnK4HNa/CvcX2c9tw9yKQZtz2j41lTpG1pzcXcKI=; b=PCJp4bWrbNajdrPVafOgqpB9wBcBT6lA8L47XLuiYD22+r7LeGUc+9iI8sgju6Rt4f 3PnniXt98TZ7w2XxCuczQMiIp4RbCvJJpb7BRmLKSSJC5IcIGrVuNeWgwJ+w46LUYkMB Lij7welcnBGi1EpPTyun8927mJVSZYtEZ2qQQFhSo3ZjaUJqdoq8cLbK/PQ9MtsaVLuQ kIZySNryV97o08a1/GdN7WM1CdfOxuzqfaUJv0TyFvf7cdjySsSFe7HF195EPAlxW9f2 LBHDA7WzHC4nMQNRuMnzCCdwU/qVolHzfC5C2lZHDU5kJfGACmbC0yP9a9wgRSBwQULN 9v7Q== X-Gm-Message-State: AOJu0Yy7py+KN5S40YfV11Epx+CqnRvuK5a7KHMtS3ykm/oAlOVaEWQR ntN6lStF4i2uWr10gM/hTafpz/k6nKIkwA== X-Google-Smtp-Source: AGHT+IGpj3yUfAKU2ZR8/Q6odSy7v61/Vu+5bnngA9VJC9jEx+CsGDkRdjxSllnhyTKJMTGXcBmQ+g== X-Received: by 2002:a81:4e4c:0:b0:5d7:9f0c:d36c with SMTP id c73-20020a814e4c000000b005d79f0cd36cmr4224321ywb.28.1702348079901; Mon, 11 Dec 2023 18:27:59 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:38aa:1c88:df05:9b73]) by smtp.gmail.com with ESMTPSA id p194-20020a0de6cb000000b005956b451fb8sm3402804ywe.100.2023.12.11.18.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:27:58 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Christian Brauner , David Howells , Siddh Raman Pant , Yury Norov , Dave Airlie , David Disseldorp , Philipp Stanner , Nick Alcock Cc: Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v3 04/35] watch_queue: optimize post_one_notification() by using find_and_clear_bit() Date: Mon, 11 Dec 2023 18:27:18 -0800 Message-Id: <20231212022749.625238-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212022749.625238-1-yury.norov@gmail.com> References: <20231212022749.625238-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" post_one_notification() searches for a set bit in wqueue->notes_bitmap, and after some housekeeping work clears it, firing a BUG() if someone else cleared the bit in-between. We can allocate the bit atomically with an atomic find_and_clear_bit(), and remove the BUG() possibility entirely. Signed-off-by: Yury Norov --- kernel/watch_queue.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 778b4056700f..07edd4a2b463 100644 --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -112,7 +112,7 @@ static bool post_one_notification(struct watch_queue *w= queue, if (pipe_full(head, tail, pipe->ring_size)) goto lost; =20 - note =3D find_first_bit(wqueue->notes_bitmap, wqueue->nr_notes); + note =3D find_and_clear_bit(wqueue->notes_bitmap, wqueue->nr_notes); if (note >=3D wqueue->nr_notes) goto lost; =20 @@ -133,10 +133,6 @@ static bool post_one_notification(struct watch_queue *= wqueue, buf->flags =3D PIPE_BUF_FLAG_WHOLE; smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */ =20 - if (!test_and_clear_bit(note, wqueue->notes_bitmap)) { - spin_unlock_irq(&pipe->rd_wait.lock); - BUG(); - } wake_up_interruptible_sync_poll_locked(&pipe->rd_wait, EPOLLIN | EPOLLRDN= ORM); done =3D true; =20 --=20 2.40.1