Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1781907rdb; Mon, 9 Oct 2023 02:46:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEY0m0vWyr705y1zLEG/lStQRUvYiH/2QGoybv4o2MqXnDGbhV1vMDFT1VTNZJpOmHASkHj X-Received: by 2002:a17:903:228f:b0:1c7:66a4:27ba with SMTP id b15-20020a170903228f00b001c766a427bamr17758479plh.48.1696844772183; Mon, 09 Oct 2023 02:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696844772; cv=none; d=google.com; s=arc-20160816; b=viMyKoLovRuZY1M8ASn/aT0OTj3Ylu/eE8wbxqP8Bl6k1BbmygPZdORGh30ezQO8j2 PByG1V1B67/CU6Vz/Q1Y8sSyQDzefbsNqxyc1udQcgfmrNDMZzBTgf4j1UQ9Ry0BW5qQ PsF3P+/E4CBRiy+QTzLSuBv1qiG+17gWKIAv8U3vfO3kvO7uVYWTnikT7b+0qLTV5AUB 2nqwFs4ww4D6IsrYVNropq8S2CGcZ6sDxq0EtBgeCkDB5BuBy/ZCXDtoIsRP9CKuE6zy dRYmZhk9roNcJO/r/c0vnV+M5jeCyewo9+NX7jqjkmdZavZ0Zg4IEdaTzxTRsgKZt2iJ UiJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Y350VwO6015lGO7ERBdBbOV3S2AzDXdRMs/XXWO/P3w=; fh=D7uhrQnmQG6xf11gbvfi3iQ1A4p/6GZN4OQA8frEvwo=; b=vUkDX4kOSNSeRm33e03aYmK4N3VO0zzOs0t6Z668SoxNAsr47SBtMvOAvfmeEWl4Nk p0hV1TMa52BcCxsOrd67MKGWWQS8U6Mm3XSX8FGgMDYGiTC+ZTtURwV1jgCD90GwYKQo bBkkG9H6cUt3B3xIk1FK7hKbqrRO5VTQqShayI3vwtTSWLWzQ9uYOItx1gWgsBFjDJon Q5Kf9t1HY8BRlbGQiBw3/ZIiKWYQ40tXB1L5j5VusL5XaZ1wEQG98PiXIQIAZL/+/Zpy zv7VWaIMQaFzRxMJ918bXwM38pctSgJHm4sn3FQ+pTelv9AX2+6Br+H5cSQRo/bhPXpp WsgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=16YWreNy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id n2-20020a170903404200b001c45cb1d770si8694958pla.280.2023.10.09.02.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 02:46:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=16YWreNy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3344F80A4162; Mon, 9 Oct 2023 02:46:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345860AbjJIJqB (ORCPT + 99 others); Mon, 9 Oct 2023 05:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345699AbjJIJp7 (ORCPT ); Mon, 9 Oct 2023 05:45:59 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4CD88F for ; Mon, 9 Oct 2023 02:45:56 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-65b08bbd8b1so29032226d6.2 for ; Mon, 09 Oct 2023 02:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696844756; x=1697449556; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Y350VwO6015lGO7ERBdBbOV3S2AzDXdRMs/XXWO/P3w=; b=16YWreNy9aMyICdnKhrSDp3Bdoi1fHnRskPmq54KhqtTuGzcrBjuoBPQ1aSGvjZbr7 9C27GNKq6SE9yXYmcGbhmSLAWTzO4BGl/hZs2No9vrfEPq+qWmU3Bl+AYKue+wmf7bcQ SkFW+6DPTofAbM6BCLD1+WfLRgBFI08tGDu5ZzqFKntWnTf6HnmvRPBpXvKBJ6UODygW H9GMWJca0TvNI5iyrWob43yXCdcQ2hTxqToGWjv+eacZYIaGSVckqE3/2ff7kuXMZPjE aCkNNf3iimyEu+2yh7GLGo6TkenDF+BOvq/5t7Fxr4tjE1PUCmn0r335LbMTxGpzo1m9 KTvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696844756; x=1697449556; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y350VwO6015lGO7ERBdBbOV3S2AzDXdRMs/XXWO/P3w=; b=mJw2L4oK+OI9DQXLe4ygLf+OYBqGmNqt6nRQXAVqlzE7Dgetf1+gZN3nELIbUvdVFb jMuw7rtfa1gxu/+uQgh1pLQd2VLO/LRtfMfoqB7nyItciShD5qxqEvEMprTwscZSCMq+ cg9vKtJ5gHpBplP+qTrkB3McT6JhU9Ek8XXC2nZ0CWcbAkmeHByMdt1Py3FPl+uO9GLp EsP/GYxcIBWyz+WuqiPeWGNfTtdCz75NZRgGDGMbXLMlO+pCoV5KTPMB3d6rY26cFyFl 9+b0udosU4td6Ljc7FA1U5ECUr5QaTlF+5bmpMssRzEbImgCpwTFjf1jItV/qPuh9nCH 3CmA== X-Gm-Message-State: AOJu0YwZ2Ru9hRj/jx0X4oEk1ymCOaqEKmRNPLm6S9Hj9ysi5Wd7qhIu 6PN6F3DrFPMmJAmq2H/QOFbMFpmSpxSijD2O+sIcyQ== X-Received: by 2002:a05:6214:3d0d:b0:651:69d7:3d6a with SMTP id ol13-20020a0562143d0d00b0065169d73d6amr16569724qvb.15.1696844755772; Mon, 09 Oct 2023 02:45:55 -0700 (PDT) MIME-Version: 1.0 References: <5c5eca8a53ea53352794de57c87440ec509c9bbc.1694625260.git.andreyknvl@google.com> In-Reply-To: <5c5eca8a53ea53352794de57c87440ec509c9bbc.1694625260.git.andreyknvl@google.com> From: Alexander Potapenko Date: Mon, 9 Oct 2023 11:45:19 +0200 Message-ID: Subject: Re: [PATCH v2 11/19] lib/stackdepot: use read/write lock To: andrey.konovalov@linux.dev Cc: Marco Elver , Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 02:46:09 -0700 (PDT) On Wed, Sep 13, 2023 at 7:16=E2=80=AFPM wrote: > > From: Andrey Konovalov > > Currently, stack depot uses the following locking scheme: > > 1. Lock-free accesses when looking up a stack record, which allows to > have multiple users to look up records in parallel; > 2. Spinlock for protecting the stack depot pools and the hash table > when adding a new record. > > For implementing the eviction of stack traces from stack depot, the > lock-free approach is not going to work anymore, as we will need to be > able to also remove records from the hash table. > > Convert the spinlock into a read/write lock, and drop the atomic accesses= , > as they are no longer required. > > Looking up stack traces is now protected by the read lock and adding new > records - by the write lock. One of the following patches will add a new > function for evicting stack records, which will be protected by the write > lock as well. > > With this change, multiple users can still look up records in parallel. > > This is preparatory patch for implementing the eviction of stack records > from the stack depot. > > Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko (but see the comment below) > static struct stack_record *depot_fetch_stack(depot_stack_handle_t handl= e) > { > union handle_parts parts =3D { .handle =3D handle }; > - /* > - * READ_ONCE pairs with potential concurrent write in > - * depot_init_pool. > - */ > - int pools_num_cached =3D READ_ONCE(pools_num); > void *pool; > size_t offset =3D parts.offset << DEPOT_STACK_ALIGN; > struct stack_record *stack; > > - if (parts.pool_index > pools_num_cached) { > + lockdep_assert_held(&pool_rwlock); Shouldn't it be lockdep_assert_held_read()?