From patchwork Mon May 25 21:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 11569493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E542290 for ; Mon, 25 May 2020 21:48:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B2F94206C3 for ; Mon, 25 May 2020 21:48:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q7gfBC+1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2F94206C3 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 695EA8006F; Mon, 25 May 2020 17:48:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 621E780061; Mon, 25 May 2020 17:48:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BDF98006F; Mon, 25 May 2020 17:48:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 2DCC980061 for ; Mon, 25 May 2020 17:48:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E318F181AC9CB for ; Mon, 25 May 2020 21:48:28 +0000 (UTC) X-FDA: 76856580696.25.bean91_2ce60ee53a43e X-Spam-Summary: 2,0,0,f0b8d0d5b50bad71,d41d8cd98f00b204,urezki@gmail.com,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4117:4321:4385:4390:4395:4605:5007:6119:6261:6653:7514:7875:7903:7904:9413:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13180:13229:13894:14181:14394:14687:14721:21080:21433:21444:21451:21627:21666:21939:30012:30029:30054,0,RBL:209.85.208.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: bean91_2ce60ee53a43e X-Filterd-Recvd-Size: 6138 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 May 2020 21:48:28 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id c11so20000280ljn.2 for ; Mon, 25 May 2020 14:48:28 -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=KLIimAxShdXUGKczejB46X3ypCcUUoC/Csjl4VU2E+4=; b=Q7gfBC+1ILDdxSUjjcuyqOmy66V+6pob1eITQV4EIxudn8SXWItz7+TmuY6po5UZEl R9G15d3+16vguqYMPAqL/D0TrWStNpcWsltrDX3JiI/R75EcLxe4B/CZQwRfSgkJF1TZ 8FV3Z7DTSed4DxB7lv4jurttunSqRoAyGXlI+7863ggIzhphlfvWC5zwrr5bYTMwc6Mb 7m0VukxsGCtGwz0fvIXXVYHTJRYfFLwWdKFVqdMnDJApvbKB4sWYyrHf8HkPx+0wZkeq CMaPbWCQZQT6iYkrKqtvBoGipUmdFiDKETIBfRuYxfQkdTZraS9q1ajI3A6vUwCHazz5 Z32g== 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=KLIimAxShdXUGKczejB46X3ypCcUUoC/Csjl4VU2E+4=; b=jDlK1xSoaBYt723FjXDDZc2tSYuR5Al/Z02tvCDPX9//PDnZFvLa8sOhprNhHmxDqw AVjfCYjUeA9p59wYTye57SxQctPqNzFNiHCfDFW3Ktl8JeS76whBk/2kstI6HPrLVwpp B5iHutZn1UTzVa5D5QME7hzM4nmnpqg8vMRPVfudhRA8GcNzo0OLJtSKbhazt0BUjZOT HU4Ydcuv01HNczpOjYbVng+SN6WHJ9TOBLAcO7E7hOKf0PwpbqoQx5V4TW0NhZ16TXUA M3PRs2HfrAlwW274drj8p8XpY2z4Yb7hoYK/IP2r9ZwJuZhKgarOSeVXeBzj+aHgdaYX LLbQ== X-Gm-Message-State: AOAM532b0qbcQSongderyBYi74KSw4JkAq6R1ImI9GoD5sSbjFBjzxPq 0h/Si4kEvfgdma/fM4AbhBRC7gU1Z9MFQw== X-Google-Smtp-Source: ABdhPJwCgQgMm4h3pLJ7oGEz9S8XTUYhEdVg429I3Qh6OkWK/z20EI55Qbu6gIqTJmV4Y79ZmOYkIA== X-Received: by 2002:a2e:9953:: with SMTP id r19mr13234097ljj.345.1590443307169; Mon, 25 May 2020 14:48:27 -0700 (PDT) Received: from pc638.lan (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id a6sm2280044lji.29.2020.05.25.14.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 14:48:26 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: LKML , linux-mm@kvack.org Cc: Andrew Morton , "Paul E . McKenney" , "Theodore Y . Ts'o" , Matthew Wilcox , Joel Fernandes , RCU , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH v2 15/16] rcu: Introduce single argument kvfree_rcu() interface Date: Mon, 25 May 2020 23:47:59 +0200 Message-Id: <20200525214800.93072-16-urezki@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525214800.93072-1-urezki@gmail.com> References: <20200525214800.93072-1-urezki@gmail.com> MIME-Version: 1.0 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: 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) --- 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 51b26ab02878..d15d46db61f7 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