From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EAF9C433DF for ; Thu, 18 Jun 2020 17:56:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 65EF3208C7 for ; Thu, 18 Jun 2020 17:56:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tlA7vQVv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65EF3208C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E6CCB8D004D; Thu, 18 Jun 2020 13:56:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1D208D0018; Thu, 18 Jun 2020 13:56:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D34538D004D; Thu, 18 Jun 2020 13:56:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id BA4C88D0018 for ; Thu, 18 Jun 2020 13:56:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 64D45FBD33 for ; Thu, 18 Jun 2020 17:56:28 +0000 (UTC) X-FDA: 76943087256.30.duck36_16149b426e12 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 34BA71801B77F for ; Thu, 18 Jun 2020 17:56:28 +0000 (UTC) X-HE-Tag: duck36_16149b426e12 X-Filterd-Recvd-Size: 5899 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 18 Jun 2020 17:56:27 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id x18so8352667lji.1 for ; Thu, 18 Jun 2020 10:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=hgEY9YL3J/pKkRYUMahi1oLwyNouWGOcWOKShQWynNc=; b=tlA7vQVv5Scg4QNwojArqYul7A5kJgYGKq7Ugf1JjNzSnocplvmiPT3lrh5xGGoLVW cezAzQfr3n03TQjr68p+ylDrMDuNvcv/HR886KOR5UsWYjdqt0ET42vdFeO43+Jgeipt ML5cDVbqEjhT8YRZBeY4QwnIqB8niUMq5orUASwBXgyCtdTSu3or48ugdRXh5Q1HTYWZ HOvFFM+nPzxzgw7DjcbbtO9aMKSDgRK1ZQe8OYJufsgC0ra8bClYTeiIC+4pC6Pgdgp5 NTBjzbRUiigbW3fpxIOug5nMhqD633zDq48kP35jGijTIp5inJmqaMivZ5y1Y7Cy7YH0 yhWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hgEY9YL3J/pKkRYUMahi1oLwyNouWGOcWOKShQWynNc=; b=aEGmUg8IAQ/AhJHmlqlFgdr6JHMSqUggIj+378XVv6Sa28F7I5j/W9tVs5FGxcVD5m 5y8v8iAQfkV0eL8UBbELWWsHgf5pGCbThaVRMCyeT1fcf8NcXoD6dygyQ2RrQAVAu1GP NJXR1gS4KTdAsBxnHQUP0lhPz+5QHxNXJF/gscdRixSI4XOYgqlEqPxcsa9zyif0HsXV OtikqR7G69+iGBXlqGNp3a1joTWNmzegVNA1SgakLhrCaySmwm4qpcl5yslxL36wZT9t KQsvKnca4gUzfFi5/vJJyGd9/8jet+qWz8W+xUeS55x2AEu2U0z2F5akKDFAPX3wZOhP 7RbA== X-Gm-Message-State: AOAM533Tf4gQtbtAF1RJ7dTFgq9dprhXB8OFl+QTg3jgL49mVm9IAY0R 6TV/Y39FcDTa8nJ1I0fQ18w= X-Google-Smtp-Source: ABdhPJxewL4d2SFKZDdYq8LkLi0kuEt4pcUh152NCFxOxhuEZQcUamPYu9xoSQwEEuFTX7Rlm5X1kA== X-Received: by 2002:a2e:6c07:: with SMTP id h7mr3097280ljc.125.1592502986338; Thu, 18 Jun 2020 10:56:26 -0700 (PDT) Received: from pc636 (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id v20sm269849lfe.46.2020.06.18.10.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 10:56:25 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 18 Jun 2020 19:56:23 +0200 To: "Paul E. McKenney" Cc: Uladzislau Rezki , LKML , linux-mm@kvack.org, Andrew Morton , "Theodore Y . Ts'o" , Matthew Wilcox , Joel Fernandes , RCU , Oleksiy Avramchenko Subject: Re: [PATCH v2 09/16] rcu/tree: Maintain separate array for vmalloc ptrs Message-ID: <20200618175623.GA14865@pc636> References: <20200525214800.93072-1-urezki@gmail.com> <20200525214800.93072-10-urezki@gmail.com> <20200617234609.GA10087@paulmck-ThinkPad-P72> <20200618172504.GA14613@pc636> <20200618173206.GS2723@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200618173206.GS2723@paulmck-ThinkPad-P72> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 34BA71801B77F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: On Thu, Jun 18, 2020 at 10:32:06AM -0700, Paul E. McKenney wrote: > On Thu, Jun 18, 2020 at 07:25:04PM +0200, Uladzislau Rezki wrote: > > > > + // Handle two first channels. > > > > + for (i = 0; i < FREE_N_CHANNELS; i++) { > > > > + for (; bkvhead[i]; bkvhead[i] = bnext) { > > > > + bnext = bkvhead[i]->next; > > > > + debug_rcu_bhead_unqueue(bkvhead[i]); > > > > + > > > > + rcu_lock_acquire(&rcu_callback_map); > > > > + if (i == 0) { // kmalloc() / kfree(). > > > > + trace_rcu_invoke_kfree_bulk_callback( > > > > + rcu_state.name, bkvhead[i]->nr_records, > > > > + bkvhead[i]->records); > > > > + > > > > + kfree_bulk(bkvhead[i]->nr_records, > > > > + bkvhead[i]->records); > > > > + } else { // vmalloc() / vfree(). > > > > + for (j = 0; j < bkvhead[i]->nr_records; j++) { > > > > + trace_rcu_invoke_kfree_callback( > > > > + rcu_state.name, > > > > + bkvhead[i]->records[j], 0); > > > > + > > > > + vfree(bkvhead[i]->records[j]); > > > > + } > > > > + } > > > > + rcu_lock_release(&rcu_callback_map); > > > > > > Not an emergency, but did you look into replacing this "if" statement > > > with an array of pointers to functions implementing the legs of the > > > "if" statement? If nothing else, this would greatly reduced indentation. > > > > > > > > > I am taking this as is, but if you have not already done so, could you > > > please look into this for a follow-up patch? > > > > > I do not think it makes sense, because it would require to check each > > pointer in the array, what can lead to many branching, i.e. "if-else" > > instructions. > > Mightn't the compiler simply unroll the outer loop? Then the first > unrolled iteration of that loop would contain the then-clause and > the second unrolled iteration would contain the else-clause. At that > point, there would be no checking, just direct calls. > > Or am I missing something? > If we mix pointers, then we can do free per pointer only. I mean in that case we will not be able to use kfree_bulk() interface for freeing SLAB memory and the code would converted to something like: while (nr_objects_in_array > 0) { if (is_vmalloc_addr(array[X])) vfree(array[X]); else kfree(array[X]); } > > Paul, thank you to take it in! > > Thank you for persisting! > Welcome :) -- Vlad Rezki