Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3946686ybz; Mon, 4 May 2020 12:41:50 -0700 (PDT) X-Google-Smtp-Source: APiQypLl/diWTidYulHGnijx6ilacklfc8pMSjnJLBf9Be9V9QoZbTv/+TPyPkBiMzWlf+w1mjD7 X-Received: by 2002:a17:906:a39a:: with SMTP id k26mr15542956ejz.172.1588621310276; Mon, 04 May 2020 12:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588621310; cv=none; d=google.com; s=arc-20160816; b=JZTSwevAP//hRA+QBt9EnpAFy8tO4cZUCJQt/eCdSYnRLrXnXLC/1lT938ZetfPwLq 1aCLcUNASI7wKrDsQ+LKm8dchy6NGlOUlmyvyVem/riWb+rkIm88TYn+hOmtvXjcBbzz Tc+XOPklpSCYa2hpJpzd9/EJ6+ElVr7umqMN/yal2ngoQBBBwUhGYo4XjTdBzSibM5tC CehkJJm8Qjtobdyf/uXQac1AvNqj9FB/b+Kdyqi9TZocayiKx4qEh1AtrXPY4b2qQOi5 qdZFoOC9mNbXhtT7GViu5aeqN9734sNsUKi/XNLOPY5sMQnbqQmgboDLB7wnvb5KfaMA +Cjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=AdWMO0GZMNFscZNybGWQG3ITswtupKPg+QTxQVbhP58=; b=RV/5ZPgRIr4egzw1iuZ987FKQIc7gzVvh10XX4s83YY0KBvxvC7EKBbTVCDld3hn+0 bNdCxcx/eRRoRvOvpMFXsR2iN0WaVSdTyRN8mGU0qJiXe4wlSsw5LLRpTOcMALfr1FgZ hUe3oBkimcQuuQxvAB5BpnCmaSp6AOzanUzmrSKT3NB93U+wlDNiqnAeS8MCdKf0kY8H Amv9Xi2k8kxojryBUlYMiR9KlXs3s5ZboyG5+2t63roMeIs0JaHV2R7tMoaBGhh8vfoL eC0zT7KZ+DeDNiqmYW2NkPvOIx7QKtP5+mQ+MhH73BIEbnCCnlEZi/ONu/PCEBwCJAWh NQVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=GObmazAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w20si7221954edu.522.2020.05.04.12.41.26; Mon, 04 May 2020 12:41:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=GObmazAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727092AbgEDThr (ORCPT + 99 others); Mon, 4 May 2020 15:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726550AbgEDThq (ORCPT ); Mon, 4 May 2020 15:37:46 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F05C061A0F for ; Mon, 4 May 2020 12:37:46 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id k18so13697305ion.0 for ; Mon, 04 May 2020 12:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AdWMO0GZMNFscZNybGWQG3ITswtupKPg+QTxQVbhP58=; b=GObmazAbydGljs6lUpNTgX82Yj9VICjxvJsXCRjiEN/IiUC4gN8U8xjGFwFx9O7ill ZFs+VP0q2tO0znb2WC0f2LJP3cMcp+e1Muf7XNyClzKjOuvajCxdLCIVo5W1RvjY4uOd sLQwXUEOzKPvuukgNeSceNmqwReuSA9lOcGCA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AdWMO0GZMNFscZNybGWQG3ITswtupKPg+QTxQVbhP58=; b=hJEnjMaILrkpr9vgcqypYEywr9n/jYgNj+k3kvimt1UbAMTgjcXwDGoAYP1Tx7uNih QR5Ma7NaUQ/jIvGUn61KXsJUCL/y0YeuEfTFiFpWDb3ltEGN3eEu4nZy7dN2n2J1E7jY a/8GSFi9BN9HtgMBoE8JMX+EZYX+4cNxgNOl+j8AczFDhEbugF1OwpXoD/L6UEYbWae1 nXs7ha4sh1pHkkPHM0kYOOp51//wJ19291rXPPeJ7+D4OGkXLbHAzsP5r5vtrrp4oyJT 695+WqHyHGT6d31YGiL8etTzLAeh+tYubyxvesd8puavNx5DVeGPoLOQG9u/I/G5GdTi jjiQ== X-Gm-Message-State: AGi0Pub4Jlc5qyNfPecwtZgMp8PuMfutg6L7ki4Rj80Mz7KuIlQetBQ1 /A/Q9G0VxRs30vvQzbpxwXMRYlMBAkcThg+X7ZA8ZelMVi4= X-Received: by 2002:a6b:bc85:: with SMTP id m127mr3389827iof.89.1588621065701; Mon, 04 May 2020 12:37:45 -0700 (PDT) MIME-Version: 1.0 References: <20200428205903.61704-1-urezki@gmail.com> <20200428205903.61704-10-urezki@gmail.com> <20200501212749.GD7560@paulmck-ThinkPad-P72> <20200504124323.GA17577@pc636> <20200504152437.GK2869@paulmck-ThinkPad-P72> <20200504174822.GA20446@pc636> <20200504180805.GA172409@google.com> <20200504190138.GU2869@paulmck-ThinkPad-P72> In-Reply-To: <20200504190138.GU2869@paulmck-ThinkPad-P72> From: Joel Fernandes Date: Mon, 4 May 2020 15:37:33 -0400 Message-ID: Subject: Re: [PATCH 09/24] rcu/tree: cache specified number of objects To: "Paul E. McKenney" Cc: Uladzislau Rezki , LKML , linux-mm , Andrew Morton , "Theodore Y . Ts'o" , Matthew Wilcox , RCU , Oleksiy Avramchenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, On Mon, May 4, 2020 at 3:01 PM Paul E. McKenney wrote: > > On Mon, May 04, 2020 at 02:08:05PM -0400, Joel Fernandes wrote: > > On Mon, May 04, 2020 at 07:48:22PM +0200, Uladzislau Rezki wrote: > > > On Mon, May 04, 2020 at 08:24:37AM -0700, Paul E. McKenney wrote: > > [..] > > > > > > Presumably the list can also be accessed without holding this lock, > > > > > > because otherwise we shouldn't need llist... > > > > > > > > > > > Hm... We increase the number of elements in cache, therefore it is not > > > > > lockless. From the other hand i used llist_head to maintain the cache > > > > > because it is single linked list, we do not need "*prev" link. Also > > > > > we do not need to init the list. > > > > > > > > > > But i can change it to list_head. Please let me know if i need :) > > > > > > > > Hmmm... Maybe it is time for a non-atomic singly linked list? In the RCU > > > > callback processing, the operations were open-coded, but they have been > > > > pushed into include/linux/rcu_segcblist.h and kernel/rcu/rcu_segcblist.*. > > > > > > > > Maybe some non-atomic/protected/whatever macros in the llist.h file? > > > > Or maybe just open-code the singly linked list? (Probably not the > > > > best choice, though.) Add comments stating that the atomic properties > > > > of the llist functions aren't neded? Something else? > > > > > > > In order to keep it simple i can replace llist_head by the list_head? > > > > Just to clarify for me, what is the disadvantage of using llist here? > > Are there some llist APIs that are not set up for concurrency? I am > not seeing any. llist deletion racing with another llist deletion will need locking. So strictly speaking, some locking is possible with llist usage? The locklessness as I understand comes when adding and deleting at the same time. For that no lock is needed. But in the current patch, it locks anyway to avoid the lost-update of the size of the list. > The overhead isn't that much of a concern, given that these are not on the > hotpath, but people reading the code and seeing the cmpxchg operations > might be forgiven for believing that there is some concurrency involved > somewhere. > > Or am I confused and there are now single-threaded add/delete operations > for llist? I do see some examples of llist usage with locking in the kernel code. One case is: do_init_module() calling llist_add to add to the init_free_list under module_mutex. > > Since we don't care about traversing backwards, isn't it better to use llist > > for this usecase? > > > > I think Vlad is using locking as we're also tracking the size of the llist to > > know when to free pages. This tracking could suffer from the lost-update > > problem without any locking, 2 lockless llist_add happened simulatenously. > > > > Also if list_head is used, it will take more space and still use locking. > > Indeed, it would be best to use a non-concurrent singly linked list. Ok cool :-) Is it safe to say something like the following is ruled out? ;-) :-D #define kfree_rcu_list_add llist_add Thanks, - Joel