Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp866669ybt; Wed, 24 Jun 2020 13:15:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1e0OjsCy+gyjgvPSVj5nbCyea5fCCBoTkMVP1mn6YGRY3e9T8yepXTEvzbyGYc8K/ve37 X-Received: by 2002:a50:934e:: with SMTP id n14mr28709763eda.88.1593029747616; Wed, 24 Jun 2020 13:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593029747; cv=none; d=google.com; s=arc-20160816; b=xgj/UNJp2kVYaGuHexZa45yKZwdnULfRc3cCt8CGZ7HE2bWEDaxxsHM7DNc7MJKiLF rvgXwnn2ok3mW+osKN8n2gikJaUmcBL7jh9thyP8aThApUllr9haC0m+flTG3CxaAJcm 4N6mOqQYh8EW7NeSIlbFDjG5EnVCOA4U73ZFmC4rU/Qmd7AnALO/NqVOfmW6/ca1l89l JPp7eH2NN7QTQwFczSDQMuVfUcH/L/pKeGc7WNMHQFamt12Y/0+R7onej67el2ZFm3pz TjOjY1BumUt4Nuz4VEhpKOb7vdSB0M/LOEcCGYCHIvK9kIY4xpa5EMwimy8Vw0fyJO6h nHxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=JdPvNLzi02sePfAUxK6eA2BLAKLBs2BLNr/uLIR9cf8=; b=nex2gLyl62aUJNGeI3U8G2mk4QNlRUEP18SmboXOm9XkP8PNcOCPt1k49E73f+/lZK bLNx5y+Jo86Q+Kh2kK4etcehA++7its5SzSs7ZKeDTKYeRICCgSUq1+GQ+c9l5zzNOcM jzBra1ryN2moImyvbZnKWMT9+G7j+uKxFwGl4VGUQxdiQ7EnIpbipyqK7qr2gWwa4UKp j/o00GiAeScRyrUTzt7/e6yc8zo7mCz2I8B/QwP3VuiCSw/LcHAv1b4zAu74QpmSnvDe 37SDtgW+7ehrJ6nFYZO8D0wJEznRvQmCox6sxlnDzsTIkfJFltfyhA0/rJhpMd7g0BzI nSvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=icLKrPaw; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k9si13520959ejp.499.2020.06.24.13.15.24; Wed, 24 Jun 2020 13:15:47 -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=@kernel.org header.s=default header.b=icLKrPaw; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406466AbgFXUNA (ORCPT + 99 others); Wed, 24 Jun 2020 16:13:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:52436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406398AbgFXUMc (ORCPT ); Wed, 24 Jun 2020 16:12:32 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 736F720857; Wed, 24 Jun 2020 20:12:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593029551; bh=TnQiolA6D8Fm8sLu96I73u+4PGM+rRJ0dDA/VI0CGrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icLKrPawcATtokb2umksIhSUxFECFh0BKx/yFZqtsXZvfMAqTE/uaeNWyCUF2hyqt oJQlOEtr9dfobKnUMsAmh1z7panEjTcgIqFFQkBkulZ1+HwdBoGDZwMS/yNht77+4S mAvANqIFzobfG4ieOFdNuX4XylwwNmtboiLlBskw= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, "Uladzislau Rezki (Sony)" , "Paul E . McKenney" Subject: [PATCH tip/core/rcu 16/17] rcu: Introduce single argument kvfree_rcu() interface Date: Wed, 24 Jun 2020 13:12:25 -0700 Message-Id: <20200624201226.21197-16-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200624201200.GA28901@paulmck-ThinkPad-P72> References: <20200624201200.GA28901@paulmck-ThinkPad-P72> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Uladzislau Rezki (Sony)" Make kvfree_rcu() capable of freeing objects that will not embed an rcu_head within it. This saves storage overhead in such objects. Reclaiming headless objects this way requires only a single argument (pointer to the object). After this patch, there are two ways to use kvfree_rcu(): a) kvfree_rcu(ptr, rhf); struct X { struct rcu_head rhf; unsigned char data[100]; }; void *ptr = kvmalloc(sizeof(struct X), GFP_KERNEL); if (ptr) kvfree_rcu(ptr, rhf); b) kvfree_rcu(ptr); void *ptr = kvmalloc(some_bytes, GFP_KERNEL); if (ptr) kvfree_rcu(ptr); Note that the headless usage (example b) can only be used in a code that can sleep. This is enforced by the CONFIG_DEBUG_ATOMIC_SLEEP option. Co-developed-by: Joel Fernandes (Google) Reviewed-by: Joel Fernandes (Google) Signed-off-by: Uladzislau Rezki (Sony) Signed-off-by: Paul E. McKenney --- include/linux/rcupdate.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 51b26ab..d15d46d 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -877,12 +877,42 @@ do { \ /** * 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. + * This macro consists of one or two arguments and it is + * based on whether an object is head-less or not. If it + * has a head then a semantic stays the same as it used + * to be before: + * + * kvfree_rcu(ptr, rhf); + * + * where @ptr is a pointer to kvfree(), @rhf is the name + * of the rcu_head structure within the type of @ptr. + * + * When it comes to head-less variant, only one argument + * is passed and that is just a pointer which has to be + * freed after a grace period. Therefore the semantic is + * + * kvfree_rcu(ptr); + * + * where @ptr is a pointer to kvfree(). + * + * Please note, head-less way of freeing is permitted to + * use from a context that has to follow might_sleep() + * annotation. Otherwise, please switch and embed the + * rcu_head structure within the type of @ptr. */ -#define kvfree_rcu(ptr, rhf) kfree_rcu(ptr, rhf) +#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \ + kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__) + +#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME +#define kvfree_rcu_arg_2(ptr, rhf) kfree_rcu(ptr, rhf) +#define kvfree_rcu_arg_1(ptr) \ +do { \ + typeof(ptr) ___p = (ptr); \ + \ + if (___p) \ + kvfree_call_rcu(NULL, (rcu_callback_t) (___p)); \ +} while (0) /* * Place this after a lock-acquisition primitive to guarantee that -- 2.9.5