Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1799496ybh; Sun, 15 Mar 2020 11:19:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvng7X0xZN4OOTMcPN8TwqxfgrEhqh3vltSuwqgikO6WtIiN6wcW7xZORqo/JaUkY2cQCLR X-Received: by 2002:a9d:3603:: with SMTP id w3mr19963758otb.94.1584296373816; Sun, 15 Mar 2020 11:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584296373; cv=none; d=google.com; s=arc-20160816; b=DpZvdfYQFLDncSLqsQ3MlzF7mZtCuvyB+Y8t8EMeSWEx8/5ZlIYlrrdA0LImYzuTVw J+tJE8NGu8O+rNFqRLKw831/jCRT47bElQ701jQCfBz/wC7Qq4EottxSy1rRHE5GXYtm 8S+HXMUCfgpVhV/TWexgW7//nxqpb1Gv8HUJwo84WS4CTxdRTbWUPntLudv2JDY7id7C fnW0Wvc9knN69oP7GfJrJovPKUezIWGrd7QfLVNllybCwVofbwsdiDU3DOOp5ifF1dnX cL8kdg0sFo2O34jdwovJsN1x5OmFltuYhYCpnaUmiLjWA1Ffo//OOLn2L9UTwwTLWNOK faEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kcieLQwgRPobTGTFCGVDjA15PZoxugef2NVvCh5oHyg=; b=OwA/rAnhRf/rwW+atyikYP29dPPl7mXRx9Smf7xZilCPkP/MWMq4Bk978BS+zOcAmP P5I76mbr1zvimWQumJPJWG7R2DvPyVjUdU7ZVvu/+VL53b3Gak+Fge8NlM9SyJ8vcT9T GFmLC6Va5N0H169oxVjn940dZrpXarJgSTojfRldaOFKkPJXT/yiFOddaXoSxhipZHTZ BXAd7hhRTMDoWjSd7Syn1suJvkmQl0Dfir5a7XYm/liXG6ZzkqxU6pTZ1yBPX2jwmFIq 2DoX/79qt3z18rQqCAZm2ZExL72i8YzFZuUyF8nNWnm0T+upVwHtbDbW5LyKeBnFzzDD zyZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F+wR7ORw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id o63si5367398oih.74.2020.03.15.11.19.22; Sun, 15 Mar 2020 11:19:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F+wR7ORw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728993AbgCOSSz (ORCPT + 99 others); Sun, 15 Mar 2020 14:18:55 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34356 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726444AbgCOSSy (ORCPT ); Sun, 15 Mar 2020 14:18:54 -0400 Received: by mail-lf1-f65.google.com with SMTP id f3so1805347lfc.1; Sun, 15 Mar 2020 11:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kcieLQwgRPobTGTFCGVDjA15PZoxugef2NVvCh5oHyg=; b=F+wR7ORw89SUUyhXdX3kXNqVbSugrhsLf+OLAwBGxbTvWNziZQknfYEQy0j4eRck/N jJXh20EOq/ZcxPGu2AuZBe/affKQMwK5tnmXHQSKbSWgjJOA4ayz0w5HECOfKdgCIImj F8b82w5AJTEwN3MJ8Gn8G4NRWz+UoOwQJfGYiHpGSowtr7cpK729NdTNG2IHo9suspQr qp7+DE+gmLnrSgb1s4P4ono4tlyonQYJP8IwWyS15e/hbkQ4N0d5pHQUbXF8AVD2c8kP bIknF4PtXbXnABGcFWqozBomWTZl+nrMum4eb2StAaRStkRkb1M8QZ1dxkvGhxWpRlj/ ke3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kcieLQwgRPobTGTFCGVDjA15PZoxugef2NVvCh5oHyg=; b=f3z/sFCOVGJLP67PN5B5kycK62P1MV7tuwarOekE/pj7yMIeoND7/soGawGMX8Gq0n 9PA0QIdZSCGQuIwP3IHDqRFh9Q6vl3M8wpSASW21+2s1bRKYCbcoEKM1aN5iuN/oDD9k bRwczm11ZpxSosyuPaJ/SYwWtxwFGfKkWBWYtSft5yMakh/fwGDaujQlyoHJY/jGSHvA pJf4M90zjk2H2My2REFMqm+FG8vqn59yPE98l7RsCMMuauOmpRc9I/y65fw3KUYgV5vY ESs5ua8ROSYft4BezKQqcCfVwy5jeQzRyLEJPucfj48of/g0CUacUaHqgbXkR/99sNNw bvVw== X-Gm-Message-State: ANhLgQ1NjFXAJgEZKsNV+5aluP8+njHPZgan09wZ8sybb0G9tCmGVG4E +wXDIvtT3l1a+p8TGmug5zeFkjGa6a+9mg== X-Received: by 2002:a19:f70d:: with SMTP id z13mr2253159lfe.58.1584296330653; Sun, 15 Mar 2020 11:18:50 -0700 (PDT) Received: from pc636.lan (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id o15sm3040629ljj.55.2020.03.15.11.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Mar 2020 11:18:50 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: LKML , "Paul E . McKenney" , Joel Fernandes Cc: RCU , Andrew Morton , Uladzislau Rezki , Steven Rostedt , Oleksiy Avramchenko Subject: [PATCH v1 2/6] rcu: introduce kvfree_rcu() interface Date: Sun, 15 Mar 2020 19:18:36 +0100 Message-Id: <20200315181840.6966-3-urezki@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200315181840.6966-1-urezki@gmail.com> References: <20200315181840.6966-1-urezki@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kvfree_rcu() can deal with an allocated memory that is obtained via kvmalloc(). It can return two types of allocated memory or "pointers", one can belong to regular SLAB allocator and another one can be vmalloc one. It depends on requested size and memory pressure. Based on that, two streams are split, thus if a pointer belongs to vmalloc allocator it is queued to the list, otherwise SLAB one is queued into "bulk array" for further processing. The main reason of such splitting is: a) to distinguish kmalloc()/vmalloc() ptrs; b) there is no vmalloc_bulk() interface. As of now we have list_lru.c user that needs such interface, also there will be new comers. Apart of that it is preparation to have a head-less variant later. Signed-off-by: Uladzislau Rezki (Sony) --- include/linux/rcupdate.h | 9 +++++++++ kernel/rcu/tiny.c | 3 ++- kernel/rcu/tree.c | 17 ++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 2be97a83f266..bb270221dbdc 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -845,6 +845,15 @@ do { \ __kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \ } while (0) +/** + * kvfree_rcu() - kvfree an object after a grace period. + * @ptr: pointer to kvfree + * @rhf: the name of the struct rcu_head within the type of @ptr. + * + * Same as kfree_rcu(), just simple alias. + */ +#define kvfree_rcu(ptr, rhf) kfree_rcu(ptr, rhf) + /* * Place this after a lock-acquisition primitive to guarantee that * an UNLOCK+LOCK pair acts as a full barrier. This guarantee applies diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c index dd572ce7c747..4b99f7b88bee 100644 --- a/kernel/rcu/tiny.c +++ b/kernel/rcu/tiny.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "rcu.h" @@ -86,7 +87,7 @@ static inline bool rcu_reclaim_tiny(struct rcu_head *head) rcu_lock_acquire(&rcu_callback_map); if (__is_kfree_rcu_offset(offset)) { trace_rcu_invoke_kfree_callback("", head, offset); - kfree((void *)head - offset); + kvfree((void *)head - offset); rcu_lock_release(&rcu_callback_map); return true; } diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 2f4c91a3713a..1c0a73616872 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2899,9 +2899,9 @@ static void kfree_rcu_work(struct work_struct *work) } /* - * Emergency case only. It can happen under low memory - * condition when an allocation gets failed, so the "bulk" - * path can not be temporary maintained. + * vmalloc() pointers end up here also emergency case. It can + * happen under low memory condition when an allocation gets + * failed, so the "bulk" path can not be temporary maintained. */ for (; head; head = next) { unsigned long offset = (unsigned long)head->func; @@ -2912,7 +2912,7 @@ static void kfree_rcu_work(struct work_struct *work) trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset); if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset))) - kfree((void *)head - offset); + kvfree((void *)head - offset); rcu_lock_release(&rcu_callback_map); cond_resched_tasks_rcu_qs(); @@ -3084,10 +3084,17 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func) } /* + * We do not queue vmalloc pointers into array, + * instead they are just queued to the list. We + * do it because of: + * a) to distinguish kmalloc()/vmalloc() ptrs; + * b) there is no vmalloc_bulk() interface. + * * Under high memory pressure GFP_NOWAIT can fail, * in that case the emergency path is maintained. */ - if (unlikely(!kfree_call_rcu_add_ptr_to_bulk(krcp, head, func))) { + if (is_vmalloc_addr((void *) head - (unsigned long) func) || + !kfree_call_rcu_add_ptr_to_bulk(krcp, head, func)) { head->func = func; head->next = krcp->head; krcp->head = head; -- 2.20.1