Received: by 10.213.65.68 with SMTP id h4csp3775136imn; Tue, 3 Apr 2018 10:25:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+d6RB0rGeMUft7dMG8lN6pUa2uhKORoJ/ussAI7o9ujX8HFecha604jQtCTNcr76Xh6dJA X-Received: by 10.99.119.2 with SMTP id s2mr3384282pgc.436.1522776305109; Tue, 03 Apr 2018 10:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522776305; cv=none; d=google.com; s=arc-20160816; b=ysSX8Gi01wPdU63lolSV4CqXoJn4mDw2iIRRqxRxWiv8n9LQfqblbvDJuKj21lgqm7 GsDbwNx9PVtzzivsIuS6X0W63lO5KE3w4fspJXBC4pQXCKeaLNfk07xS1yuCJFbZGwed pDEJub0gfoGUjb2+wQzTMPt2wndDdGeU73JuZNG7ZKjwcOUqhT1IBlWXm3T1v3JGfOIe 7J+Djv7asdvWoBCIuDjm7LZ6sKYhQao/uE1boWNEYrPdPtOYInPAxXgKiQdliCEpQu12 COOv+rzYkubJw0eNp4Bc1WGivH+zQcvNrW/r5Vyj8VelFWVi1GpWW7nPSXS//gVmzCvk laAQ== 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:arc-authentication-results; bh=CK78HPCQRjjDHHH4ULfE4a1VWqY+Ubc63gHqs9DR3oo=; b=WVJNJoSH9sLoOltiypSxKUeAI4p7eG4J8KY14rnV6ZAGpT0/YPlcA2kc8UJoe8YlrG rubk3TWdW5l+Gnx0y9MB/tOW873inlQJUG4qbIxuoRZ6Clqoy+OiSseQdOBWIK+/Xnfu 0/x7hgxPrJ2ypjuac1QTu4hYnHNjZbD0eEvprJx9D/gpCA5i74gOR+4jNX5Gajd/Z7au 2qi3pUHtSRxvkeEwgSowXH9WKbm4NBzPJX9DQIlcGcrd/BKXbe253zwnTInd+rTxQhgN ApqC2w4lCg7nmx7WRlF/h4gKL47cpKykKUrEhekQKErgr9hJDYfbINJ+exMTFNRz2Ss6 SXLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=g9W5wt0s; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3-v6si953847plo.479.2018.04.03.10.24.51; Tue, 03 Apr 2018 10:25:05 -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=@oracle.com header.s=corp-2017-10-26 header.b=g9W5wt0s; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752583AbeDCRXk (ORCPT + 99 others); Tue, 3 Apr 2018 13:23:40 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46230 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbeDCRXg (ORCPT ); Tue, 3 Apr 2018 13:23:36 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33HHNrs191539; Tue, 3 Apr 2018 17:23:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=CK78HPCQRjjDHHH4ULfE4a1VWqY+Ubc63gHqs9DR3oo=; b=g9W5wt0srPZIOEJg3bSivaf7J9VevXYJPiaok2k4LLIupmW4wEaieD22A53pUH62Ic5H L9nETaoqI4To68svXITQabcp4slEWZDtmG6zVXq6hhPtWfU8pySwXzCEKkrvuQBvFtyJ ceW50YErqlsawZY7y3IHmBaCxFJeC5bvT0CkuGkjW8RDoM0MYbbv+33Fpw5uzkjQ/lnv KxDlgpelembQKWNqtqSoKMbLqUV9eybmDPKq0v0uYwCj11yWApopMKn4sVKS1o8jzWfW 1SFz4QDuetLaQP4G/lpoGdi4ezUWpPqD0t9gZqM1lq15mkcktyNdbQq/4ig2YyJREo6l WA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2h4dvrg0wb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 17:23:11 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w33HNAKZ015681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 17:23:10 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33HN9I1026199; Tue, 3 Apr 2018 17:23:09 GMT Received: from oracle.com (/67.188.214.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 10:23:09 -0700 From: rao.shoaib@oracle.com To: linux-kernel@vger.kernel.org Cc: paulmck@linux.vnet.ibm.com, joe@perches.com, willy@infradead.org, brouer@redhat.com, linux-mm@kvack.org, Rao Shoaib Subject: [PATCH 1/2] Move kfree_call_rcu() to slab_common.c Date: Tue, 3 Apr 2018 10:22:52 -0700 Message-Id: <1522776173-7190-2-git-send-email-rao.shoaib@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522776173-7190-1-git-send-email-rao.shoaib@oracle.com> References: <1522776173-7190-1-git-send-email-rao.shoaib@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8852 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030176 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rao Shoaib kfree_call_rcu does not belong in linux/rcupdate.h and should be moved to slab_common.c Signed-off-by: Rao Shoaib --- include/linux/rcupdate.h | 43 +++---------------------------------------- include/linux/rcutree.h | 2 -- include/linux/slab.h | 42 ++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/tree.c | 24 ++++++++++-------------- mm/slab_common.c | 10 ++++++++++ 5 files changed, 65 insertions(+), 56 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 043d047..6338fb6 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -55,6 +55,9 @@ void call_rcu(struct rcu_head *head, rcu_callback_t func); #define call_rcu call_rcu_sched #endif /* #else #ifdef CONFIG_PREEMPT_RCU */ +/* only for use by kfree_call_rcu() */ +void call_rcu_lazy(struct rcu_head *head, rcu_callback_t func); + void call_rcu_bh(struct rcu_head *head, rcu_callback_t func); void call_rcu_sched(struct rcu_head *head, rcu_callback_t func); void synchronize_sched(void); @@ -837,45 +840,6 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) #define __is_kfree_rcu_offset(offset) ((offset) < 4096) /* - * Helper macro for kfree_rcu() to prevent argument-expansion eyestrain. - */ -#define __kfree_rcu(head, offset) \ - do { \ - BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \ - kfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \ - } while (0) - -/** - * kfree_rcu() - kfree an object after a grace period. - * @ptr: pointer to kfree - * @rcu_head: the name of the struct rcu_head within the type of @ptr. - * - * Many rcu callbacks functions just call kfree() on the base structure. - * These functions are trivial, but their size adds up, and furthermore - * when they are used in a kernel module, that module must invoke the - * high-latency rcu_barrier() function at module-unload time. - * - * The kfree_rcu() function handles this issue. Rather than encoding a - * function address in the embedded rcu_head structure, kfree_rcu() instead - * encodes the offset of the rcu_head structure within the base structure. - * Because the functions are not allowed in the low-order 4096 bytes of - * kernel virtual memory, offsets up to 4095 bytes can be accommodated. - * If the offset is larger than 4095 bytes, a compile-time error will - * be generated in __kfree_rcu(). If this error is triggered, you can - * either fall back to use of call_rcu() or rearrange the structure to - * position the rcu_head structure into the first 4096 bytes. - * - * Note that the allowable offset might decrease in the future, for example, - * to allow something like kmem_cache_free_rcu(). - * - * The BUILD_BUG_ON check must not involve any function calls, hence the - * checks are done in macros here. - */ -#define kfree_rcu(ptr, rcu_head) \ - __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) - - -/* * Place this after a lock-acquisition primitive to guarantee that * an UNLOCK+LOCK pair acts as a full barrier. This guarantee applies * if the UNLOCK and LOCK are executed by the same CPU or if the @@ -887,5 +851,4 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) #define smp_mb__after_unlock_lock() do { } while (0) #endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ - #endif /* __LINUX_RCUPDATE_H */ diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h index fd996cd..567ef58 100644 --- a/include/linux/rcutree.h +++ b/include/linux/rcutree.h @@ -48,8 +48,6 @@ void synchronize_rcu_bh(void); void synchronize_sched_expedited(void); void synchronize_rcu_expedited(void); -void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func); - /** * synchronize_rcu_bh_expedited - Brute-force RCU-bh grace period * diff --git a/include/linux/slab.h b/include/linux/slab.h index 231abc8..116e870 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -355,6 +355,48 @@ void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment __malloc; void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags) __assume_slab_alignment __malloc; void kmem_cache_free(struct kmem_cache *, void *); +void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func); + +/* Helper macro for kfree_rcu() to prevent argument-expansion eyestrain. */ +#define __kfree_rcu(head, offset) \ + do { \ + unsigned long __of = (unsigned long)offset; \ + BUILD_BUG_ON(!__is_kfree_rcu_offset(__of)); \ + kfree_call_rcu(head, (rcu_callback_t)(__of)); \ + } while (0) + +/** + * kfree_rcu() - kfree an object after a grace period. + * @ptr: pointer to kfree + * @rcu_name: the name of the struct rcu_head within the type of @ptr. + * + * Many rcu callbacks functions just call kfree() on the base structure. + * These functions are trivial, but their size adds up, and furthermore + * when they are used in a kernel module, that module must invoke the + * high-latency rcu_barrier() function at module-unload time. + * + * The kfree_rcu() function handles this issue. Rather than encoding a + * function address in the embedded rcu_head structure, kfree_rcu() instead + * encodes the offset of the rcu_head structure within the base structure. + * Because the functions are not allowed in the low-order 4096 bytes of + * kernel virtual memory, offsets up to 4095 bytes can be accommodated. + * If the offset is larger than 4095 bytes, a compile-time error will + * be generated in __kfree_rcu(). If this error is triggered, you can + * either fall back to use of call_rcu() or rearrange the structure to + * position the rcu_head structure into the first 4096 bytes. + * + * Note that the allowable offset might decrease in the future, for example, + * to allow something like kmem_cache_free_rcu(). + * + * The BUILD_BUG_ON check must not involve any function calls, hence the + * checks are done in macros here. + */ +#define kfree_rcu(ptr, rcu_name) \ + do { \ + unsigned long __off = offsetof(typeof(*(ptr)), rcu_name); \ + struct rcu_head *__rptr = (void *)ptr + __off; \ + __kfree_rcu(__rptr, __off); \ + } while (0) /* * Bulk allocation and freeing operations. These are accelerated in an * allocator specific way to avoid taking locks repeatedly or building diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 491bdf3..e40f014 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3101,6 +3101,16 @@ void call_rcu_sched(struct rcu_head *head, rcu_callback_t func) } EXPORT_SYMBOL_GPL(call_rcu_sched); +/* Queue an RCU callback for lazy invocation after a grace period. + * Currently there is no way of tagging the lazy RCU callbacks in the + * list of pending callbacks. Until then, this function may only be + * called from kfree_call_rcu(). + */ +void call_rcu_lazy(struct rcu_head *head, rcu_callback_t func) +{ + __call_rcu(head, func, rcu_state_p, -1, 1); +} + /** * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period. * @head: structure to be used for queueing the RCU updates. @@ -3130,20 +3140,6 @@ void call_rcu_bh(struct rcu_head *head, rcu_callback_t func) EXPORT_SYMBOL_GPL(call_rcu_bh); /* - * Queue an RCU callback for lazy invocation after a grace period. - * This will likely be later named something like "call_rcu_lazy()", - * but this change will require some way of tagging the lazy RCU - * callbacks in the list of pending callbacks. Until then, this - * function may only be called from __kfree_rcu(). - */ -void kfree_call_rcu(struct rcu_head *head, - rcu_callback_t func) -{ - __call_rcu(head, func, rcu_state_p, -1, 1); -} -EXPORT_SYMBOL_GPL(kfree_call_rcu); - -/* * Because a context switch is a grace period for RCU-sched and RCU-bh, * any blocking grace-period wait automatically implies a grace period * if there is only one CPU online at any point time during execution diff --git a/mm/slab_common.c b/mm/slab_common.c index 10f127b..2ea9866 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1525,6 +1525,16 @@ void kzfree(const void *p) } EXPORT_SYMBOL(kzfree); +/* + * Queue Memory to be freed by RCU after a grace period. + */ +void kfree_call_rcu(struct rcu_head *head, + rcu_callback_t func) +{ + call_rcu_lazy(head, func); +} +EXPORT_SYMBOL_GPL(kfree_call_rcu); + /* Tracepoints definitions. */ EXPORT_TRACEPOINT_SYMBOL(kmalloc); EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); -- 2.7.4