Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp180726pxb; Thu, 21 Jan 2021 04:42:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpEorODS6GKVo9rAPUssTupMKkjcT6cT3zPOl9HPeW+mxNkaPCvoRC5ZxkHuRsZHdJSLjC X-Received: by 2002:a17:906:a848:: with SMTP id dx8mr9052189ejb.37.1611232925348; Thu, 21 Jan 2021 04:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611232925; cv=none; d=google.com; s=arc-20160816; b=Ua3CVnucthdFf3329SS0kocHrXqGFuoVdSp3wjg1dJqSNXTs8SduTdcz7ZDTV+8wu0 LVD7Gkzk3kUI4+DnqvGRNtZs03SNXihjt77d8pg8f1DUYQOfSGQ3OaoKcR9EtJfYQ1Cv GoHpS1eWaqiJRUj4x/1to6GrRY6CFLQFTVyS4BqUc+loK/PsbC9LA5IXnz60AKy0qdnn jBbVLX2LwyS96SqhHdbTa5vrHZuawNqX+pRsqCTXa2CE3teLUONSINmv+lo17qX0zRov kK8tqI9TVFarU9q/qvjRQdIUnupN06UblDNy6+2eWudosDaxGC/qD7SZFKpaL4coCGxW rEWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=Ateh8R/pigQiU3FBeBMITH3roUoBO98+fhC1CWQEaTY=; b=JZSzG64asrcDorK0fF7rKpe3cWZU5zRYRXyyAJ9GlNhaivAxGi7YT1cG9XQLrj5YqA blaCdOcr+GuP5dWoTstmXNOaY6t9npbSxiMIKzMKAWygjEP/QMQLK8zxTCScnkEmFUZ/ gXenW71XfvGNFTsmPKCrC82n9NNMRfuypqI3jD8bIRr8GbByKwa1QWRezrcZnTdUMfT6 m+JzuBkYyzaN/PdgtOkq4Aer4H7J1aYERFEpX3BVjV2bzrxMbAgg3AOieUueV4/A6CkT 7tQVnU8cUHYnExLiNe6bDX1vrHUVfD/GyDAP+PO0u+Ha/PxzAgLPotBHKecmO7XRKcBO OLSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aKMVUjW8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si1953909edv.524.2021.01.21.04.41.41; Thu, 21 Jan 2021 04:42:05 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=aKMVUjW8; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731181AbhAUMka (ORCPT + 99 others); Thu, 21 Jan 2021 07:40:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731344AbhAUMjT (ORCPT ); Thu, 21 Jan 2021 07:39:19 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD490C061575; Thu, 21 Jan 2021 04:38:38 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id b26so2272082lff.9; Thu, 21 Jan 2021 04:38:38 -0800 (PST) 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=Ateh8R/pigQiU3FBeBMITH3roUoBO98+fhC1CWQEaTY=; b=aKMVUjW8EDjPIK+/DGSt0Du4TAIPcuG/FMBZYBzgN0iQW2chArKQJKBOxJzXoT1vPh pqlBK+ypI+rAR98MrQs23bgNw3qNEJFMdGvcwYknlfvUikPFfYThH0yfLa70OUuoZ2ZV 0gfwSKvHv5iKkocYPYnavsHsEWnthtQomtuI0/H9u6hO18etYKC+84gu7afBXczgGfCe G6imBQPImIzB+NpUOqa/03EmV/hWZygWGfXS3d1oh5gUjzda0vlhQ7KQBSj5Vzj7GWDo 18d29CJTrDGrxfHmwJnUHtE1lAT1ZLjXzN/EKRzUA0SG7JgPkt8SiJFNquz8HLF8PKEc V6/w== 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=Ateh8R/pigQiU3FBeBMITH3roUoBO98+fhC1CWQEaTY=; b=RS9cpS1WyiNDTeWNRKiYjrKapovklhxnCJNkvGyuZWk32lh3P3xhle/o0NeYIiNPNd mBiCg715ckzu6xbCJW+8cTj7Dl6AEqIGWOi/LuJc3kGDhSl6hwKeePXynvQl86rV9u2O BeBlNSoHAMMhvPeFsD8wDgUZxBwg2wKZ4qig5u5ayR0rMpDZviFTpQHc/cMNDqVI/CUg SJ+mDDOtXRHJVKe7ITVEwUNMthpMsgYk5otWKuu/PmDPR3Oidb36q7N9BDhoTkxdYAfL scz2KQt7aM9Cn3aSsM1h3OHNfTX90EZUvhpwvapUtkdRbPmhdmLHw8OuCsbLulixBhJl WfEw== X-Gm-Message-State: AOAM530nCFC0bVusCCoFC27TX1/9V4W7UmlDjjcrWvaq3Z5Ht4MGJ3uK OyRnMRZiSFH9miW3+FnlY8M= X-Received: by 2002:a05:6512:b12:: with SMTP id w18mr6963453lfu.323.1611232717373; Thu, 21 Jan 2021 04:38:37 -0800 (PST) Received: from pc638.lan (h5ef52e3d.seluork.dyn.perspektivbredband.net. [94.245.46.61]) by smtp.gmail.com with ESMTPSA id b14sm516102lfi.164.2021.01.21.04.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 04:38:36 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 21 Jan 2021 13:38:34 +0100 To: Sebastian Andrzej Siewior Cc: "Uladzislau Rezki (Sony)" , LKML , RCU , "Paul E . McKenney" , Michael Ellerman , Andrew Morton , Daniel Axtens , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Peter Zijlstra , Michal Hocko , Thomas Gleixner , "Theodore Y . Ts'o" , Oleksiy Avramchenko Subject: Re: [PATCH 1/3] kvfree_rcu: Allocate a page for a single argument Message-ID: <20210121123834.GA1872@pc638.lan> References: <20210120162148.1973-1-urezki@gmail.com> <20210120195757.3lgjrpvmzjvb2nce@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210120195757.3lgjrpvmzjvb2nce@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 08:57:57PM +0100, Sebastian Andrzej Siewior wrote: > On 2021-01-20 17:21:46 [+0100], Uladzislau Rezki (Sony) wrote: > > For a single argument we can directly request a page from a caller > > context when a "carry page block" is run out of free spots. Instead > > of hitting a slow path we can request an extra page by demand and > > proceed with a fast path. > > > > A single-argument kvfree_rcu() must be invoked in sleepable contexts, > > and that its fallback is the relatively high latency synchronize_rcu(). > > Single-argument kvfree_rcu() therefore uses GFP_KERNEL|__GFP_RETRY_MAYFAIL > > to allow limited sleeping within the memory allocator. > > > > [ paulmck: Add add_ptr_to_bulk_krc_lock header comment per Michal Hocko. ] > > Signed-off-by: Uladzislau Rezki (Sony) > > Signed-off-by: Paul E. McKenney > > --- > > kernel/rcu/tree.c | 42 ++++++++++++++++++++++++++---------------- > > 1 file changed, 26 insertions(+), 16 deletions(-) > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index e04e336bee42..2014fb22644d 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -3465,37 +3465,50 @@ run_page_cache_worker(struct kfree_rcu_cpu *krcp) > > } > > } > > > > +// Record ptr in a page managed by krcp, with the pre-krc_this_cpu_lock() > > +// state specified by flags. If can_alloc is true, the caller must > > +// be schedulable and not be holding any locks or mutexes that might be > > +// acquired by the memory allocator or anything that it might invoke. > > +// Returns true if ptr was successfully recorded, else the caller must > > +// use a fallback. > > The whole RCU department is getting swamped by the // comments. Can't we > have proper kernel doc and /* */ style comments like the remaining part > of the kernel? > > > static inline bool > > -kvfree_call_rcu_add_ptr_to_bulk(struct kfree_rcu_cpu *krcp, void *ptr) > > +add_ptr_to_bulk_krc_lock(struct kfree_rcu_cpu **krcp, > > + unsigned long *flags, void *ptr, bool can_alloc) > > { > > struct kvfree_rcu_bulk_data *bnode; > > int idx; > > > > - if (unlikely(!krcp->initialized)) > > + *krcp = krc_this_cpu_lock(flags); > > + if (unlikely(!(*krcp)->initialized)) > > return false; > > > > - lockdep_assert_held(&krcp->lock); > > idx = !!is_vmalloc_addr(ptr); > > > > /* Check if a new block is required. */ > > - if (!krcp->bkvhead[idx] || > > - krcp->bkvhead[idx]->nr_records == KVFREE_BULK_MAX_ENTR) { > > - bnode = get_cached_bnode(krcp); > > - /* Switch to emergency path. */ > > + if (!(*krcp)->bkvhead[idx] || > > + (*krcp)->bkvhead[idx]->nr_records == KVFREE_BULK_MAX_ENTR) { > > + bnode = get_cached_bnode(*krcp); > > + if (!bnode && can_alloc) { > > + krc_this_cpu_unlock(*krcp, *flags); > > + bnode = (struct kvfree_rcu_bulk_data *) > > There is no need for this cast. > __get_free_page() returns "unsigned long" whereas a bnode is a pointer to kvfree_rcu_bulk_data struct, without a casting the compiler will emit a warning. > > + __get_free_page(GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN); > > + *krcp = krc_this_cpu_lock(flags); > > so if bnode is NULL you could retry get_cached_bnode() since it might > have been filled (given preemption or CPU migration changed something). > Judging from patch #3 you think that a CPU migration is a bad thing. But > why? > I see your point. Indeed we can retry but honestly i do not see that it makes a lot of sense. I prefer to keep the logic as simple as it can be. If we are run out of free pages(low memory condition), there is a fallback mechanism for such purpose, i.e it implies that a slow path can be hit. >> >> You think that a CPU migration is a bad thing. But why? >> It is not a bad thing. But if it happens we might queue a new bnode to a drain list of another CPU where a previous element of a new bnode may be just underutilized. So that is why i use migrate_disable()/enable() to prevent it. If there are some hidden issues with migrate_disable()/enable() or you think it is a bad idea to use it, it would be appreciated if you could describe your view in more detail. Thanks for the comments! -- Vlad Rezki