rdmacg: IB/core: rdma controller support
Subsystems (3)
v6 cover rdmacg: IB/core: rdma controller support
Overview:
Currently user space applications can easily take away all the rdma device specific resources such as AH, CQ, QP, MR etc. Due to which other applications in other cgroup or kernel space ULPs may not even get chance to allocate any rdma resources. This results into service unavailibility.
RDMA cgroup addresses this issue by allowing resource accounting, limit enforcement on per cgroup, per rdma device basis.
Resources are not defined by the RDMA cgroup. Resources are defined by RDMA/IB stack. This allows rdma cgroup to remain constant while RDMA/IB stack can evolve without the need of rdma cgroup update. A new resource can be easily added by the RDMA/IB stack without touching rdma cgroup.
RDMA uverbs layer will enforce limits on well defined RDMA verb resources without any HCA vendor device driver involvement.
RDMA uverbs layer will not do accounting of hw vendor specific resources. Instead rdma cgroup provides set of APIs through which vendor specific drivers can do resource accounting by making use of rdma cgroup.
Resource limit enforcement is hierarchical.
When process is migrated with active RDMA resources, rdma cgroup continues to uncharge original cgroup for allocated resource. New resource is charged to current process's cgroup, which means if the process is migrated with active resources, for new resources it will be charged to new cgroup and old resources will be correctly uncharged from old cgroup.
Changes from v5:
* (To address comments from Tejun)
1. Removed two type of resource pool, made is single type (as Tejun described in past comment)
2. Removed match tokens and have array definition like "qp", "mr",
"cq" etc.
3. Wrote small parser and avoided match_token API as that won't work due to different array definitions
4. Removed one-off remove API to unconfigure cgroup, instead all resource should be set to max.
5. Removed resource pool type (user/default), instead having max_num_cnt, when ref_cnt drops to zero and
max_num_cnt = total_rescource_cnt, pool is freed.
6. Resource definition ownership is now only with IB stack at single header file, no longer in each low level driver.
This goes through IB maintainer and other reviewers eyes. This continue to give flexibility to not force kernel upgrade for few enums additions for new resource type.
7. Wherever possible pool lock is pushed out, except for hierarchical charging/unchanging points, as it not possible to do so, due to iterative process involves blocking allocations of rpool. Coming up more levels up to release locks doesn't make any sense either. This is anyway slow path where rpool is not allocated. Except for typical first resource allocation, this is less travelled path.
8. Avoided %d manipulation due to removal of match_token and replaced with seq_putc etc friend functions.
* Other minor cleanups.
* Fixed rdmacg_register_device to return error in case of IB stack tries to register for than 64 resources.
* Fixed not allowing negative value on resource setting.
* Fixed cleaning up resource pools during device removal.
* Simplfied and rename table length field to use ARRAY_SIZE macro.
* Updated documentation to reflect single resource pool and shorter file names.
Changes from v4:
* Fixed compilation errors for lockdep_assert_held reported by kbuild test robot
* Fixed compilation warning reported by coccinelle for extra semicolon.
* Fixed compilation error for inclusion of linux/parser.h which cannot be included in any header file, as that triggers multiple inclusion error. parser.h is included in C files which intent to use it.
* Removed unused header file inclusion in cgroup_rdma.c
Changes from v3:
* (To address comments from Tejun)
1. Renamed cg_resource to rdmacg_resource
2. Merged dealloc_cg_rpool and _dealloc_cg_rpool to single function
3. Renamed _find_cg_rpool to find_cg_rpool_locked()
5. Removed RDMACG_MAX_RESOURCE_INDEX limitation
6. Fixed few alignments.
7. Improved description for RDMA cgroup configuration menu
8. Renamed cg_list_lock to rpool_list_lock to reflect the lock is for rpools.
9. Renamed _get_cg_rpool to find_cg_rpool.
10. Made creator as int variable, instead of atomic as its not required to be atomic.
* Fixed freeing right rpool during query_limit error path
* Added copywrite for cgroup.c
* Removed including parser.h from cgroup.c as its included by cgroup_rdma.h
* Reduced try_charge functions to single function and removed duplicate comments.
Changes from v2:
* Fixed compilation error reported by 0-DAY kernel test infrastructure for m68k architecture where CONFIG_CGROUP is also not defined.
* Fixed comment in patch to refer to legacy mode of cgroup, changed to refer to v1 and v2 version.
* Added more information in commit log for rdma controller patch.
Changes from v1:
* (To address comments from Tejun)
a. reduces 3 patches to single patch
b. removed resource word from the cgroup configuration files c. changed cgroup configuration file names to match other cgroups d. removed .list file and merged functionality with .max file
* Based on comment to merge to single patch for rdma controller; IB/core patches are reduced to single patch.
* Removed pid cgroup map and simplified design - Charge/Uncharge caller stack keeps track of the rdmacg for given resource. This removes the need to maintain and perform hash lookup. This also allows little more accurate resource charging/uncharging when process moved from one to other cgroup with active resources and continue to allocate more.
* Critical fix: Removed rdma cgroup's dependency on the kernel module header files to avoid crashes when modules are upgraded without kernel upgrade, which is very common due to high amount of changes in IB stack and it is also shipped as individual kernel modules.
* uboject extended to keep track of the owner rdma cgroup, so that same rdmacg can be used while uncharging.
* Added support functions to hide details of rdmacg device in uverbs modules for cases of cgroup enabled/disabled at compile time. This avoids multiple ifdefs for every API in uverbs layer.
* Removed failure counters in first patch, which will be added once initial feature is merged.
* Fixed stale rpool access which is getting freed, while doing configuration to rdma.verb.max file.
* Fixed rpool resource leak while querying max, current values.
Changes from v0:
(To address comments from Haggai, Doug, Liran, Tejun, Sean, Jason)
* Redesigned to support per device per cgroup limit settings by bringing concept of resource pool.
* Redesigned to let IB stack define the resources instead of rdma controller using resource template.
* Redesigned to support hw vendor specific limits setting (optional to drivers).
* Created new rdma controller instead of piggyback on device cgroup.
* Fixed race conditions for multiple tasks sharing rdma resources.
* Removed dependency on the task_struct.
Patch 2/3 fails to merge with Doug's tree as it has different code. It requires manual merge.
I will generate separate patch for Doug's tree for linux-rdma for just patch 2/3 to avoid merge conflict once we complete overall review.
Parav Pandit (3):
rdmacg: Added rdma cgroup controller IB/core: added support to use rdma cgroup controller
rdmacg: Added documentation for rdmacg
Documentation/cgroup-v1/rdma.txt | 106 +++++ Documentation/cgroup-v2.txt | 33 ++ drivers/infiniband/core/Makefile | 1 + drivers/infiniband/core/cgroup.c | 114 +++++ drivers/infiniband/core/core_priv.h | 36 ++ drivers/infiniband/core/device.c | 16 + drivers/infiniband/core/uverbs_cmd.c | 164 +++++++- drivers/infiniband/core/uverbs_main.c | 19 + include/linux/cgroup_rdma.h | 53 +++ include/linux/cgroup_subsys.h | 4 + include/rdma/ib_verbs.h | 30 +- init/Kconfig | 10 + kernel/Makefile | 1 + kernel/cgroup_rdma.c | 753 ++++++++++++++++++++++++++++++++++ 14 files changed, 1324 insertions(+), 16 deletions(-) create mode 100644 Documentation/cgroup-v1/rdma.txt create mode 100644 drivers/infiniband/core/cgroup.c create mode 100644 include/linux/cgroup_rdma.h create mode 100644 kernel/cgroup_rdma.c
Signature · 1 line
1.8.3.1
PATCH v6 1/3 rdmacg: Added rdma cgroup controller
Added rdma cgroup controller that does accounting, limit enforcement on rdma/IB verbs and hw resources.
Added rdma cgroup header file which defines its APIs to perform charing/uncharing functionality and device registration which will participate in controller functions of accounting and limit enforcements. It also define rdmacg_device structure to bind IB stack and RDMA cgroup controller.
RDMA resources are tracked using resource pool. Resource pool is per device, per cgroup entity which allows setting up accounting limits on per device basis.
Resources are not defined by the RDMA cgroup, instead they are defined by the external module IB stack. This allows extending IB stack without changing kernel, as IB stack is going through changes and enhancements.
Resource pool is created/destroyed dynamically whenever charging/uncharging occurs respectively and whenever user configuration is done. Its a tradeoff of memory vs little more code space that creates resource pool whenever necessary,
instead of creating them during cgroup creation and device registration time.
--- include/linux/cgroup_rdma.h | 53 +++ include/linux/cgroup_subsys.h | 4 + init/Kconfig | 10 + kernel/Makefile | 1 + kernel/cgroup_rdma.c | 753 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 821 insertions(+) create mode 100644 include/linux/cgroup_rdma.h create mode 100644 kernel/cgroup_rdma.c
include/linux/cgroup_rdma.h new file +53 -0
@@ -0,0 +1,53 @@ +#ifndef _CGROUP_RDMA_H +#define _CGROUP_RDMA_H + +#include <linux/cgroup.h> + +struct rdma_cgroup { +#ifdef CONFIG_CGROUP_RDMA +struct cgroup_subsys_state css; + +spinlock_t rpool_list_lock;/* protects resource pool list */ +struct list_head rpool_head;/* head to keep track of all resource +* pools that belongs to this cgroup. +*/ +#endif +}; + +#ifdef CONFIG_CGROUP_RDMA + +struct rdmacg_device ; + +struct rdmacg_pool_info { +const char **resource_name_table; +int table_len; +}; + +struct rdmacg_device { +struct rdmacg_pool_info pool_info; +struct list_head rdmacg_list; +struct list_head rpool_head; +spinlock_t rpool_lock;/* protects rsource pool list */ +char *name; +}; + +/* APIs for RDMA/IB stack to publish when a device wants to +* participate in resource accounting +*/ +int rdmacg_register_device (struct rdmacg_device *device); +void rdmacg_unregister_device (struct rdmacg_device *device); + +/* APIs for RDMA/IB stack to charge/uncharge pool specific resources */ +int rdmacg_try_charge (struct rdma_cgroup **rdmacg, +struct rdmacg_device *device, +int resource_index, +int num); +void rdmacg_uncharge (struct rdma_cgroup *cg, +struct rdmacg_device *device, +int resource_index, +int num); +void rdmacg_query_limit (struct rdmacg_device *device, +int *limits,int max_count); + +#endif /* CONFIG_CGROUP_RDMA */ +#endif /* _CGROUP_RDMA_H */
include/linux/cgroup_subsys.h +4 -0
@@ -56,6 +56,10 @@ SUBSYS(hugetlb) SUBSYS(pids)#endif +#if IS_ENABLED (CONFIG_CGROUP_RDMA ) +SUBSYS(rdma) +#endif +/* * The following subsystems are not supported on the default hierarchy. */
init/Kconfig +10 -0
@@ -1054,6 +1054,16 @@ config CGROUP_PIDS since the PIDs limit only affects a process's ability to fork, not to attach to a cgroup. +config CGROUP_RDMA + bool "RDMA controller" + help + Provides enforcement of RDMA resources defined by IB stack. + It is fairly easy for consumers to exhaust RDMA resources, which + can result into resource unavailibility to other consumers. + RDMA controller is designed to stop this from happening. + Attaching processes with active RDMA resources to the cgroup + hierarchy is allowed even if can cross the hierarchy's limit. + config CGROUP_FREEZER bool "Freezer controller" help
kernel/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup.o obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o obj-$(CONFIG_CGROUP_PIDS) += cgroup_pids.o +obj-$(CONFIG_CGROUP_RDMA) += cgroup_rdma.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_UTS_NS) += utsname.o obj-$(CONFIG_USER_NS) += user_namespace.o
kernel/cgroup_rdma.c new file +753 -0
753 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 2/3 IB/core: added support to use rdma cgroup controller
In reply to Parav PanditAdded support APIs for IB core to register/unregister every RDMA device with rdma cgroup for tracking verbs and hw resources.
IB core registers with rdma cgroup controller and also defines resources that can be accounted.
Added support APIs for uverbs layer to make use of rdma controller. Added uverbs layer to perform resource charge/uncharge functionality.
--- drivers/infiniband/core/Makefile | 1 + drivers/infiniband/core/cgroup.c | 114 +++++++++++++++++++++++ drivers/infiniband/core/core_priv.h | 36 ++++++++ drivers/infiniband/core/device.c | 16 ++++ drivers/infiniband/core/uverbs_cmd.c | 164 ++++++++++++++++++++++++++++++---- drivers/infiniband/core/uverbs_main.c | 19 ++++ include/rdma/ib_verbs.h | 30 ++++++- 7 files changed, 364 insertions(+), 16 deletions(-) create mode 100644 drivers/infiniband/core/cgroup.c
drivers/infiniband/core/Makefile +1 -0
@@ -13,6 +13,7 @@ ib_core-y := packer.o ud_header.o verbs.o sysfs.o \ roce_gid_mgmt.o ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o umem_rbtree.o +ib_core-$(CONFIG_CGROUP_RDMA) += cgroup.o ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
drivers/infiniband/core/cgroup.c new file +114 -0
114 lines not on this page · raw message
drivers/infiniband/core/core_priv.h +36 -0
@@ -92,4 +92,40 @@ int ib_cache_setup_one(struct ib_device *device);void ib_cache_cleanup_one (struct ib_device *device);void ib_cache_release_one (struct ib_device *device); +#ifdef CONFIG_CGROUP_RDMA + +int ib_device_register_rdmacg (struct ib_device *device); +void ib_device_unregister_rdmacg (struct ib_device *device); + +int ib_rdmacg_try_charge (struct ib_rdmacg_object *cg_obj, +struct ib_device *device, +int resource_index,int num); + +void ib_rdmacg_uncharge (struct ib_rdmacg_object *cg_obj, +struct ib_device *device, +int resource_index,int num); + +void ib_rdmacg_query_limit (struct ib_device *device, +int *limits,int max_count); +#else +static inline int ib_rdmacg_try_charge (struct ib_rdmacg_object *cg_obj, +struct ib_device *device, +int resource_index,int num) +{return 0 ; } + +static inline void ib_rdmacg_uncharge (struct ib_rdmacg_object *cg_obj, +struct ib_device *device, +int resource_index,int num) +{ } + +static inline void ib_rdmacg_query_limit (struct ib_device *device, +int *limits,int max_count) +{ +int i; + +for (i =0 ; i < max_count; i++) + limits[i] =S32_MAX ; +} +#endif +#endif /* _CORE_PRIV_H */
drivers/infiniband/core/device.c +16 -0
@@ -352,10 +352,22 @@ int ib_register_device(struct ib_device *device, goto out; } +#ifdef CONFIG_CGROUP_RDMA + ret =ib_device_register_rdmacg (device); +if (ret) { +printk (KERN_WARNING "Couldn't set up InfiniBand P_Key/GID cache\n" ); +ib_cache_cleanup_one (device); + goto out; + } +#endif + ret =ib_device_register_sysfs (device, port_callback);if (ret) {printk (KERN_WARNING "Couldn't register device %s with driver model\n" , device->name); +#ifdef CONFIG_CGROUP_RDMA +ib_device_unregister_rdmacg (device); +#endif ib_cache_cleanup_one (device); goto out; }
@@ -405,6 +417,10 @@ void ib_unregister_device(struct ib_device *device)mutex_unlock (&device_mutex); +#ifdef CONFIG_CGROUP_RDMA +ib_device_unregister_rdmacg (device); +#endif +ib_device_unregister_sysfs (device);ib_cache_cleanup_one (device);
drivers/infiniband/core/uverbs_cmd.c +149 -15
488 lines not on this page · raw message
drivers/infiniband/core/uverbs_main.c +19 -0
@@ -49,6 +49,7 @@#include <asm/uaccess.h> #include "uverbs.h" +#include "core_priv.h" MODULE_AUTHOR ("Roland Dreier" );MODULE_DESCRIPTION ("InfiniBand userspace verbs access" );
@@ -214,6 +215,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,list_for_each_entry_safe (uobj, tmp, &context->ah_list, list) {struct ib_ah *ah = uobj->object; +ib_rdmacg_uncharge (&uobj->cg_obj, ah->pd->device, +RDMA_VERB_RESOURCE_AH ,1 );idr_remove_uobj (&ib_uverbs_ah_idr, uobj);ib_destroy_ah (ah);kfree (uobj);
@@ -223,6 +226,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,list_for_each_entry_safe (uobj, tmp, &context->mw_list, list) {struct ib_mw *mw = uobj->object; +ib_rdmacg_uncharge (&uobj->cg_obj, mw->pd->device, +RDMA_VERB_RESOURCE_MW ,1 );idr_remove_uobj (&ib_uverbs_mw_idr, uobj);ib_dealloc_mw (mw);kfree (uobj);
@@ -231,6 +236,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,list_for_each_entry_safe (uobj, tmp, &context->rule_list, list) {struct ib_flow *flow_id = uobj->object; +ib_rdmacg_uncharge (&uobj->cg_obj, flow_id->qp->pd->device, +RDMA_VERB_RESOURCE_FLOW ,1 );idr_remove_uobj (&ib_uverbs_rule_idr, uobj);ib_destroy_flow (flow_id);kfree (uobj);
@@ -245,6 +252,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,if (qp != qp->real_qp) {ib_close_qp (qp); }else { +ib_rdmacg_uncharge (&uobj->cg_obj, qp->pd->device, +RDMA_VERB_RESOURCE_QP ,1 );ib_uverbs_detach_umcast (qp, uqp);ib_destroy_qp (qp); }
@@ -257,6 +266,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,struct ib_uevent_object *uevent = container_of(uobj, struct ib_uevent_object, uobject); +ib_rdmacg_uncharge (&uobj->cg_obj, srq->pd->device, +RDMA_VERB_RESOURCE_SRQ ,1 );idr_remove_uobj (&ib_uverbs_srq_idr, uobj);ib_destroy_srq (srq);ib_uverbs_release_uevent (file, uevent);
@@ -269,6 +280,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,struct ib_ucq_object *ucq = container_of(uobj, struct ib_ucq_object, uobject); +ib_rdmacg_uncharge (&uobj->cg_obj, cq->device, +RDMA_VERB_RESOURCE_CQ ,1 );idr_remove_uobj (&ib_uverbs_cq_idr, uobj);ib_destroy_cq (cq);ib_uverbs_release_ucq (file, ev_file, ucq);
@@ -278,6 +291,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,list_for_each_entry_safe (uobj, tmp, &context->mr_list, list) {struct ib_mr *mr = uobj->object; +ib_rdmacg_uncharge (&uobj->cg_obj, mr->pd->device, +RDMA_VERB_RESOURCE_MR ,1 );idr_remove_uobj (&ib_uverbs_mr_idr, uobj);ib_dereg_mr (mr);kfree (uobj);
@@ -298,11 +313,15 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,list_for_each_entry_safe (uobj, tmp, &context->pd_list, list) {struct ib_pd *pd = uobj->object; +ib_rdmacg_uncharge (&uobj->cg_obj, pd->device, +RDMA_VERB_RESOURCE_PD ,1 );idr_remove_uobj (&ib_uverbs_pd_idr, uobj);ib_dealloc_pd (pd);kfree (uobj); } +ib_rdmacg_uncharge (&context->cg_obj, context->device, +RDMA_VERB_RESOURCE_UCTX ,1 );put_pid (context->tgid);return context->device->dealloc_ucontext (context);
include/rdma/ib_verbs.h +29 -1
@@ -55,6 +55,8 @@#include <linux/mmu_notifier.h> #include <asm/uaccess.h> +#include <linux/cgroup_rdma.h> +extern struct workqueue_struct *ib_wq;union ib_gid {
@@ -95,6 +97,22 @@ enum rdma_protocol_type {RDMA_PROTOCOL_USNIC_UDP }; +enum rdma_resource_type { +RDMA_VERB_RESOURCE_UCTX , +RDMA_VERB_RESOURCE_AH , +RDMA_VERB_RESOURCE_PD , +RDMA_VERB_RESOURCE_CQ , +RDMA_VERB_RESOURCE_MR , +RDMA_VERB_RESOURCE_MW , +RDMA_VERB_RESOURCE_SRQ , +RDMA_VERB_RESOURCE_QP , +RDMA_VERB_RESOURCE_FLOW , +/* +* add any hw specific resource here as RDMA_HW_RESOURCE_NAME +*/ +RDMA_RESOURCE_MAX , +}; + __attribute_const__ enum rdma_transport_typerdma_node_get_transport (enum rdma_node_type node_type);
@@ -1231,6 +1249,12 @@ struct ib_fmr_attr {struct ib_umem ; +struct ib_rdmacg_object { +#ifdef CONFIG_CGROUP_RDMA +struct rdma_cgroup *cg;/* owner rdma cgroup */ +#endif +}; +struct ib_ucontext {struct ib_device *device;struct list_head pd_list;
@@ -1261,12 +1285,14 @@ struct ib_ucontext {struct list_head no_private_counters;int odp_mrs_count;#endif +struct ib_rdmacg_object cg_obj; };struct ib_uobject {u64 user_handle;/* handle given to us by userspace */ struct ib_ucontext *context;/* associated user context */ void *object;/* containing object */ +struct ib_rdmacg_object cg_obj;struct list_head list;/* link to context's list */ int id;/* index into kernel idr */ struct kref ref;
@@ -1823,7 +1849,9 @@ struct ib_device { u16 is_switch:1;u8 node_type;u8 phys_port_cnt; - +#ifdef CONFIG_CGROUP_RDMA +struct rdmacg_device cg_device; +#endif /** * The following mandatory functions are used only at device * registration. Keep functions such as these at the end of this
Signature · 1 line
1.8.3.1
PATCH v6 3/3 rdmacg: Added documentation for rdmacg
In reply to Parav PanditAdded documentation for v1 and v2 version describing high level design and usage examples on using rdma controller.
--- Documentation/cgroup-v1/rdma.txt | 106 +++++++++++++++++++++++++++++++++++++++ Documentation/cgroup-v2.txt | 33 ++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 Documentation/cgroup-v1/rdma.txt
Documentation/cgroup-v1/rdma.txt new file +106 -0
@@ -0,0 +1,106 @@ + RDMA Controller + ---------------- + +Contents +-------- + +1. Overview + 1-1. What is RDMA controller? + 1-2. Why RDMA controller needed? + 1-3. How is RDMA controller implemented? +2. Usage Examples + +1. Overview + +1-1. What is RDMA controller? +----------------------------- + +RDMA controller allows user to limit RDMA/IB specific resources +that a given set of processes can use. These processes are grouped using +RDMA controller. + +RDMA controller allows operating on resources defined by the IB stack +which are mainly IB verb resources and in future hardware specific +well defined resources. + +1-2. Why RDMA controller needed? +-------------------------------- + +Currently user space applications can easily take away all the rdma device +specific resources such as AH, CQ, QP, MR etc. Due to which other applications +in other cgroup or kernel space ULPs may not even get chance to allocate any +rdma resources. This leads to service unavailability. + +Therefore RDMA controller is needed through which resource consumption +of processes can be limited. Through this controller various different rdma +resources described by IB stack can be accounted. + +1-3. How is RDMA controller implemented? +---------------------------------------- + +RDMA cgroup allows limit configuration of resources. These resources are not +defined by the rdma controller. Instead they are defined by the IB stack. +This provides great flexibility to allow IB stack to define new resources, +without any changes to rdma cgroup. +Rdma cgroup maintains resource accounting per cgroup, per device using +resource pool structure. Each such resource pool is limited up to +64 resources in given resource pool by rdma cgroup, which can be extended +later if required. + +This resource pool object is linked to the cgroup css. Typically there +are 0 to 4 resource pool instances per cgroup, per device in most use cases. +But nothing limits to have it more. At present hundreds of RDMA devices per +single cgroup may not be handled optimally, however there is no +known use case for such configuration either. + +Since RDMA resources can be allocated from any process and can be freed by any +of the child processes which shares the address space, rdma resources are +always owned by the creator cgroup css. This allows process migration from one +to other cgroup without major complexity of transferring resource ownership; +because such ownership is not really present due to shared nature of +rdma resources. Linking resources around css also ensures that cgroups can be +deleted after processes migrated. This allow progress migration as well with +active resources, even though that’s not the primary use case. + +Whenever RDMA resource charing occurs, owner rdma cgroup is returned to +the caller. Same rdma cgroup should be passed while uncharging the resource. +This also allows process migrated with active RDMA resource to charge +to new owner cgroup for new resource. It also allows to uncharge resource of +a process from previously charged cgroup which is migrated to new cgroup, +even though that is not a primary use case. + +Resource pool object is created in following situations. +(a) User sets the limit and no previous resource pool exist for the device +of interest for the cgroup. +(b) No resource limits were configured, but IB/RDMA stack tries to +charge the resource. So that it correctly uncharge them when applications are +running without limits and later on when limits are enforced during uncharging, +otherwise usage count will drop to negative. + +Resource pool is destroyed if it all the resource limits are set to max +and it is the last resource getting deallocated. + +User should set all the limit to max value if it intents to remove/unconfigure +the resource pool for a particular device. + +2. Usage Examples +----------------- + +(a) Configure resource limit: +echo mlx4_0 mr=100 qp=10 ah=2 > /sys/fs/cgroup/rdma/1/rdma.max +echo ocrdma1 mr=120 qp=20 cq=10 > /sys/fs/cgroup/rdma/2/rdma.max + +(b) Query resource limit: +cat /sys/fs/cgroup/rdma/2/rdma.max +#Output: +mlx4_0 mr=100 qp=10 ah=2 pd=max +ocrdma1 mr=120 qp=20 cq=10 pd=max ah=max + +(c) Query current usage: +cat /sys/fs/cgroup/rdma/2/rdma.current +#Output: +mlx4_0 mr=95 qp=8 ah=2 +ocrdma1 mr=0 qp=20 cq=10 + +(d) Delete resource limit: +echo mlx4_0 mr=max qp=max ah=max > /sys/fs/cgroup/rdma/1/rdma.max
Documentation/cgroup-v2.txt +33 -0
@@ -47,6 +47,8 @@ CONTENTS 5-3. IO 5-3-1. IO Interface Files 5-3-2. Writeback + 5-4. RDMA + 5-4-1. RDMA Interface Files P. Information on Kernel Programming P-1. Filesystem Support for Writeback D. Deprecated v1 Core Features
@@ -1090,6 +1092,37 @@ writeback as follows. total available memory and applied the same way as vm.dirty[_background]_ratio. +5-4. RDMA + +The "rdma" controller regulates the distribution of RDMA resources. +This controller implements resource accounting of resources defined +by IB stack. + +5-4-1. RDMA Interface Files + + rdma.max + A readwrite file that exists for all the cgroups except root that + describes current configured resource limit for a RDMA/IB device. + + Lines are keyed by device name and are not ordered. + Each line contains space separated resource name and its configured + limit that can be distributed. + + An example for mlx4 and ocrdma device follows. + + mlx4_0 ah=2 mr=1000 qp=104 + ocrdma1 cq=10 mr=900 qp=89 + mlx4_1 uctx=max ah=max pd=max cq=max qp=max + + rdma.current + A read-only file that describes current resource usage. + It exists for all the cgroup except root. + + An example for mlx4 and ocrdma device follows. + + mlx4_0 mr=1000 qp=102 ah=2 flow=10 srq=0 + ocrdma1 mr=900 qp=79 cq=10 flow=0 srq=0 + mlx4_1 uctx=max ah=max pd=max cq=max qp=max P. Information on Kernel Programming
Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
In reply to Parav PanditQuoted 49 lines · Parav Pandit
Added rdma cgroup controller that does accounting, limit enforcement on rdma/IB verbs and hw resources.
Added rdma cgroup header file which defines its APIs to perform charing/uncharing functionality and device registration which will participate in controller functions of accounting and limit enforcements. It also define
rdmacg_devicestructure to bind IB stack and RDMA cgroup controller.RDMA resources are tracked using resource pool. Resource pool is per device, per cgroup entity which allows setting up accounting limits on per device basis.
Resources are not defined by the RDMA cgroup, instead they are defined by the external module IB stack. This allows extending IB stack without changing kernel, as IB stack is going through changes and enhancements.
Resource pool is created/destroyed dynamically whenever charging/uncharging occurs respectively and whenever user configuration is done. Its a tradeoff of memory vs little more code space that creates resource pool whenever necessary,
instead of creating them during cgroup creation and device registration time.Signed-off-by Parav Pandit <[email protected]>--- include/linux/cgroup_rdma.h | 53 +++ include/linux/cgroup_subsys.h | 4 + init/Kconfig | 10 + kernel/Makefile | 1 + kernel/cgroup_rdma.c | 753 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 821 insertions(+) create mode 100644 include/linux/cgroup_rdma.h create mode 100644 kernel/cgroup_rdma.cinclude/linux/cgroup_rdma.h new file +7
-0@@ -0,0 +1,53 @@ +#ifndef _CGROUP_RDMA_H +#define _CGROUP_RDMA_H + +#include <linux/cgroup.h> + +struct rdma_cgroup { +#ifdef CONFIG_CGROUP_RDMA
include/linux/cgroup_rdma.h line 17
Quoted 10 lines
include/linux/cgroup_rdma.h new file +10
-0+struct cgroup_subsys_state css; + +spinlock_t rpool_list_lock;/* protects resource pool list */ +struct list_head rpool_head;/* head to keep track of all resource +* pools that belongs to this cgroup. +*/ +#endif +}; + +#ifdef CONFIG_CGROUP_RDMA
I'm sure that you already asked about that, but why do you need ifdef embedded in struct rdma_cgroup and right after that the same one? Can you place this ifdef before declaring struct rdma_cgroup?
include/linux/cgroup_rdma.h line 20
Quoted 3 lines
include/linux/cgroup_rdma.h new file +3
-0+ +struct rdmacg_device ; +
Thanks
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 2 lines · Leon Romanovsky
On Sat, Feb 20, 2016 at 04:30:04PM +0530, Parav Pandit wrote:
Can you place this ifdef before declaring structrdma_cgroup?
Yes. I missed out this cleanup. Done locally now.
Quoted 1 line
Thanks
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 4 lines · Parav Pandit
Quoted 2 lines · Leon Romanovsky
On Sat, Feb 20, 2016 at 04:30:04PM +0530, Parav Pandit wrote:
Can you place this ifdef before declaring structrdma_cgroup?Yes. I missed out this cleanup. Done locally now.
Great, additional thing which spotted my attention was related to declaring and using the new cgroups functions. There are number of places where you protected the calls by specific ifdefs in the IB/core c-files and not in h-files as it is usually done.
Quoted 2 lines
Quoted 2 lines
Thanks
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
CONFIG_CGROUP_RDMA
Quoted 11 lines · Leon Romanovsky
Quoted 4 lines · Parav Pandit
Quoted 2 lines · Leon Romanovsky
On Sat, Feb 20, 2016 at 04:30:04PM +0530, Parav Pandit wrote:
Can you place this ifdef before declaring structrdma_cgroup?Yes. I missed out this cleanup. Done locally now.
Great, additional thing which spotted my attention was related to declaring and using the new cgroups functions. There are number of places where you protected the calls by specific ifdefs in the IB/core c-files and not in h-files as it is usually done.
ib_device_register_rdmacg, ib_device_unregister_rdmacg are the only two functions called from IB/core as its tied to functionality. They can also be implemented as NULL call when CONFIG_CGROUP_RDMA is undefined. (Similar to ib_rdmacg_try_charge and others).
I didn't do because occurrence of call of register and unregister is limited to single file and only twice compare to charge/uncharge functions.
Either way is fine with me, I can make the changes which you described. Let me know.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Thanks
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 14 lines · Parav Pandit
CONFIG_CGROUP_RDMAQuoted 11 lines · Leon Romanovsky
Quoted 4 lines · Parav Pandit
Quoted 2 lines · Leon Romanovsky
On Sat, Feb 20, 2016 at 04:30:04PM +0530, Parav Pandit wrote:
Can you place this ifdef before declaring structrdma_cgroup?Yes. I missed out this cleanup. Done locally now.
Great, additional thing which spotted my attention was related to declaring and using the new cgroups functions. There are number of places where you protected the calls by specific ifdefs in the IB/core c-files and not in h-files as it is usually done.
Quoted 9 lines
ib_device_register_rdmacg,ib_device_unregister_rdmacgare the only two functions called from IB/core as its tied to functionality. They can also be implemented as NULL call whenCONFIG_CGROUP_RDMAis undefined. (Similar toib_rdmacg_try_chargeand others).
I didn't do because occurrence of call of register and unregister is limited to single file and only twice compare to charge/uncharge functions.
Either way is fine with me, I can make the changes which you described. Let me know.
Please do,
IMHO, it is better to have one place which handles all relevant ifdefs and functions. IB/core doesn't need to know about cgroups implementation.
Thanks
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 25 lines · Leon Romanovsky
Quoted 14 lines · Parav Pandit
CONFIG_CGROUP_RDMAQuoted 11 lines · Leon Romanovsky
Quoted 4 lines · Parav Pandit
Quoted 2 lines · Leon Romanovsky
On Sat, Feb 20, 2016 at 04:30:04PM +0530, Parav Pandit wrote:
Can you place this ifdef before declaring structrdma_cgroup?Yes. I missed out this cleanup. Done locally now.
Great, additional thing which spotted my attention was related to declaring and using the new cgroups functions. There are number of places where you protected the calls by specific ifdefs in the IB/core c-files and not in h-files as it is usually done.
Quoted 9 lines
ib_device_register_rdmacg,ib_device_unregister_rdmacgare the only two functions called from IB/core as its tied to functionality. They can also be implemented as NULL call whenCONFIG_CGROUP_RDMAis undefined. (Similar toib_rdmacg_try_chargeand others).
I didn't do because occurrence of call of register and unregister is limited to single file and only twice compare to charge/uncharge functions.
Either way is fine with me, I can make the changes which you described. Let me know.
Quoted 4 lines
Please do,
IMHO, it is better to have one place which handles all relevant ifdefs and functions. IB/core doesn't need to know about cgroups implementation.
ok. Done. Thanks for the review. I will accumulate more comments from Tejun and others before spinning v7.
Hi Tejun, Doug,
I would like to know direction from you on how do we intent to merge this code. So that I generate next patch v7 against right tree.
Few options that comes to me are:
1. Shall we merge this code from Doug's linux-rdma tree, where there are no merge conflicts in cgroup?
Or
2. Shall we merge this as two separate patches one from cgroup side from Tejun's cgroups tree as kernel support and 2nd from linux-rdma for IB core changes to make use of those features?
Or
3. Some other options that you have in mind.
I was thinking of (1) as that has the least churn in development, test and merge efforts.
Regards,
Parav Pandit
Quoted 178 lines · Parav Pandit
Overview:
Currently user space applications can easily take away all the rdma device specific resources such as AH, CQ, QP, MR etc. Due to which other applications in other cgroup or kernel space ULPs may not even get chance to allocate any rdma resources. This results into service unavailibility.RDMA cgroup addresses this issue by allowing resource accounting, limit enforcement on per cgroup, per rdma device basis.
Resources are not defined by the RDMA cgroup. Resources are defined by RDMA/IB stack. This allows rdma cgroup to remain constant while RDMA/IB stack can evolve without the need of rdma cgroup update. A new resource can be easily added by the RDMA/IB stack without touching rdma cgroup.
RDMA uverbs layer will enforce limits on well defined RDMA verb resources without any HCA vendor device driver involvement.
RDMA uverbs layer will not do accounting of hw vendor specific resources. Instead rdma cgroup provides set of APIs through which vendor specific drivers can do resource accounting by making use of rdma cgroup.
Resource limit enforcement is hierarchical.
When process is migrated with active RDMA resources, rdma cgroup continues to uncharge original cgroup for allocated resource. New resource is charged to current process's cgroup, which means if the process is migrated with active resources, for new resources it will be charged to new cgroup and old resources will be correctly uncharged from old cgroup.
Changes from v5:
* (To address comments from Tejun)
1. Removed two type of resource pool, made is single type (as Tejun described in past comment)
2. Removed match tokens and have array definition like "qp", "mr","cq" etc.3. Wrote small parser and avoided
match_tokenAPI as that won't work due to different array definitions
4. Removed one-off remove API to unconfigure cgroup, instead all resource should be set to max.
5. Removed resource pool type (user/default), instead havingmax_num_cnt, whenref_cntdrops to zero and
max_num_cnt=total_rescource_cnt, pool is freed.
6. Resource definition ownership is now only with IB stack at single header file, no longer in each low level driver.
This goes through IB maintainer and other reviewers eyes. This continue to give flexibility to not force kernel upgrade for few enums additions for new resource type.
7. Wherever possible pool lock is pushed out, except for hierarchical charging/unchanging points, as it not possible to do so, due to iterative process involves blocking allocations of rpool. Coming up more levels up to release locks doesn't make any sense either. This is anyway slow path where rpool is not allocated. Except for typical first resource allocation, this is less travelled path.
8. Avoided %d manipulation due to removal ofmatch_tokenand replaced withseq_putcetc friend functions.
* Other minor cleanups.
* Fixedrdmacg_register_deviceto return error in case of IB stack tries to register for than 64 resources.
* Fixed not allowing negative value on resource setting.
* Fixed cleaning up resource pools during device removal.
* Simplfied and rename table length field to useARRAY_SIZEmacro.
* Updated documentation to reflect single resource pool and shorter file names.Changes from v4:
* Fixed compilation errors forlockdep_assert_heldreported by kbuild test robot
* Fixed compilation warning reported by coccinelle for extra semicolon.
* Fixed compilation error for inclusion oflinux/parser.hwhich cannot be included in any header file, as that triggers multiple inclusion error.parser.his included in C files which intent to use it.
* Removed unused header file inclusion incgroup_rdma.cChanges from v3:
* (To address comments from Tejun)
1. Renamedcg_resourcetordmacg_resource
2. Mergeddealloc_cg_rpooland_dealloc_cg_rpoolto single function
3. Renamed_find_cg_rpooltofind_cg_rpool_locked()
5. RemovedRDMACG_MAX_RESOURCE_INDEXlimitation
6. Fixed few alignments.
7. Improved description for RDMA cgroup configuration menu
8. Renamedcg_list_locktorpool_list_lockto reflect the lock is for rpools.
9. Renamed_get_cg_rpooltofind_cg_rpool.
10. Made creator as int variable, instead of atomic as its not required to be atomic.
* Fixed freeing right rpool duringquery_limiterror path
* Added copywrite forcgroup.c
* Removed includingparser.hfromcgroup.cas its included bycgroup_rdma.h
* Reducedtry_chargefunctions to single function and removed duplicate comments.Changes from v2:
* Fixed compilation error reported by 0-DAY kernel test infrastructure for m68k architecture whereCONFIG_CGROUPis also not defined.
* Fixed comment in patch to refer to legacy mode of cgroup, changed to refer to v1 and v2 version.
* Added more information in commit log for rdma controller patch.Changes from v1:
* (To address comments from Tejun)
a. reduces 3 patches to single patch
b. removed resource word from the cgroup configuration files c. changed cgroup configuration file names to match other cgroups d. removed .list file and merged functionality with .max file
* Based on comment to merge to single patch for rdma controller; IB/core patches are reduced to single patch.
* Removed pid cgroup map and simplified design - Charge/Uncharge caller stack keeps track of the rdmacg for given resource. This removes the need to maintain and perform hash lookup. This also allows little more accurate resource charging/uncharging when process moved from one to other cgroup with active resources and continue to allocate more.
* Critical fix: Removed rdma cgroup's dependency on the kernel module header files to avoid crashes when modules are upgraded without kernel upgrade, which is very common due to high amount of changes in IB stack and it is also shipped as individual kernel modules.
* uboject extended to keep track of the owner rdma cgroup, so that same rdmacg can be used while uncharging.
* Added support functions to hide details of rdmacg device in uverbs modules for cases of cgroup enabled/disabled at compile time. This avoids multiple ifdefs for every API in uverbs layer.
* Removed failure counters in first patch, which will be added once initial feature is merged.
* Fixed stale rpool access which is getting freed, while doing configuration to rdma.verb.max file.
* Fixed rpool resource leak while querying max, current values.Changes from v0:
(To address comments from Haggai, Doug, Liran, Tejun, Sean, Jason)
* Redesigned to support per device per cgroup limit settings by bringing concept of resource pool.
* Redesigned to let IB stack define the resources instead of rdma controller using resource template.
* Redesigned to support hw vendor specific limits setting (optional to drivers).
* Created new rdma controller instead of piggyback on device cgroup.
* Fixed race conditions for multiple tasks sharing rdma resources.
* Removed dependency on thetask_struct.Patch 2/3 fails to merge with Doug's tree as it has different code. It requires manual merge.
I will generate separate patch for Doug's tree for linux-rdma for just patch 2/3 to avoid merge conflict once we complete overall review.Parav Pandit (3):
rdmacg: Added rdma cgroup controller IB/core: added support to use rdma cgroup controller
rdmacg: Added documentation for rdmacgDocumentation/cgroup-v1/rdma.txt | 106 +++++ Documentation/cgroup-v2.txt | 33 ++ drivers/infiniband/core/Makefile | 1 + drivers/infiniband/core/cgroup.c | 114 +++++ drivers/infiniband/core/core_priv.h | 36 ++ drivers/infiniband/core/device.c | 16 + drivers/infiniband/core/uverbs_cmd.c | 164 +++++++- drivers/infiniband/core/uverbs_main.c | 19 + include/linux/cgroup_rdma.h | 53 +++ include/linux/cgroup_subsys.h | 4 + include/rdma/ib_verbs.h | 30 +- init/Kconfig | 10 + kernel/Makefile | 1 + kernel/cgroup_rdma.c | 753 ++++++++++++++++++++++++++++++++++ 14 files changed, 1324 insertions(+), 16 deletions(-) create mode 100644 Documentation/cgroup-v1/rdma.txt create mode 100644 drivers/infiniband/core/cgroup.c create mode 100644 include/linux/cgroup_rdma.h create mode 100644 kernel/cgroup_rdma.c--
1.8.3.1
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
In reply to Parav PanditHi,
Overall I the patch looks good to me. I have a few comments below.
Quoted 3 lines · Parav Pandit
Resource pool is created/destroyed dynamically whenever charging/uncharging occurs respectively and whenever user configuration is done. Its a tradeoff of memory vs little more code
Its -> It's
Quoted 11 lines
space that creates resource pool whenever necessary,
instead of creating them during cgroup creation and device registration time.Signed-off-by Parav Pandit <[email protected]>include/linux/cgroup_rdma.h new file +0
-0
include/linux/cgroup_rdma.h line 30
Quoted 6 lines
include/linux/cgroup_rdma.h new file +5
-0+struct rdmacg_device { +struct rdmacg_pool_info pool_info; +struct list_head rdmacg_list; +struct list_head rpool_head; +spinlock_t rpool_lock;/* protects rsource pool list */
rsource -> resource
Quoted 10 lines
include/linux/cgroup_rdma.h new file +10
-0+char *name; +}; + +/* APIs for RDMA/IB stack to publish when a device wants to +* participate in resource accounting +*/ +int rdmacg_register_device (struct rdmacg_device *device); +void rdmacg_unregister_device (struct rdmacg_device *device); + +/* APIs for RDMA/IB stack to charge/uncharge pool specific resources */
include/linux/cgroup_rdma.h line 50
Quoted 10 lines
include/linux/cgroup_rdma.h new file +10
-0+int rdmacg_try_charge (struct rdma_cgroup **rdmacg, +struct rdmacg_device *device, +int resource_index, +int num); +void rdmacg_uncharge (struct rdma_cgroup *cg, +struct rdmacg_device *device, +int resource_index, +int num); +void rdmacg_query_limit (struct rdmacg_device *device, +int *limits,int max_count);
You can drop the max_count parameter, and require the caller to always provide pool_info->table_len items, couldn't you?
Quoted 23 lines
include/linux/cgroup_rdma.h new file +3
-0+ +#endif /* CONFIG_CGROUP_RDMA */ +#endif /* _CGROUP_RDMA_H */ include/linux/cgroup_subsys.h +4
-0@@ -56,6 +56,10 @@ SUBSYS(hugetlb) SUBSYS(pids)#endif +#if IS_ENABLED (CONFIG_CGROUP_RDMA ) +SUBSYS(rdma) +#endif +/* * The following subsystems are not supported on the default hierarchy. */ init/Kconfig +0
-0
init/Kconfig config CGROUP_PIDS · line 1062
Quoted 9 lines
init/Kconfig +6
-0@@ -1054,6 +1054,16 @@ config CGROUP_PIDS since the PIDs limit only affects a process's ability to fork, not to attach to a cgroup. +config CGROUP_RDMA + bool "RDMA controller" + help + Provides enforcement of RDMA resources defined by IB stack. + It is fairly easy for consumers to exhaust RDMA resources, which + can result into resource unavailibility to other consumers.
unavailibility -> unavailability
kernel/Makefile
Quoted 13 lines
init/Kconfig +4
-0+ RDMA controller is designed to stop this from happening. + Attaching processes with active RDMA resources to the cgroup + hierarchy is allowed even if can cross the hierarchy's limit. + config CGROUP_FREEZER bool "Freezer controller" helpkernel/Makefile +3
-0+/** + * uncharge_cg_resource - uncharge resource for rdma cgroup + * @cg: pointer to cg to uncharge and all parents in hierarchy
It only uncharges a single cg, right?
Quoted 6 lines
+ * @device: pointer to ib device
+ * @index: index of the resource to uncharge in cg (resource pool)
+ * @num: the number of rdma resource to uncharge
+ *
+ * It also frees the resource pool in the hierarchy for the resource pool
+ * which was created as part of charing operation.
charing -> charging
kernel/Makefile
Quoted 10 lines
+ */
kernel/Makefile +9
-0+static void uncharge_cg_resource(struct rdma_cgroup *cg, + struct rdmacg_device *device, + int index, int num) +{ + struct rdmacg_resource_pool *rpool; + struct rdmacg_pool_info *pool_info = &device->pool_info; + + spin_lock(&cg->rpool_list_lock); + rpool = find_cg_rpool_locked(cg, device);
Is it possible for rpool to be NULL?
Quoted 38 lines
kernel/Makefile +37
-0+ + /* + * A negative count (or overflow) is invalid, + * it indicates a bug in the rdma controller. + */ + rpool->resources[index].usage -= num; + + WARN_ON_ONCE(rpool->resources[index].usage < 0); + rpool->refcnt--; + if (rpool->refcnt == 0 && rpool->num_max_cnt == pool_info->table_len) { + /* + * No user of the rpool and all entries are set to max, so + * safe to delete this rpool. + */ + list_del(&rpool->cg_list); + spin_unlock(&cg->rpool_list_lock); + + free_cg_rpool(rpool); + return; + } + spin_unlock(&cg->rpool_list_lock); +} +/** + * charge_cg_resource - charge resource for rdma cgroup + * @cg: pointer to cg to charge + * @device: pointer to rdmacg device + * @index: index of the resource to charge in cg (resource pool) + * @num: the number of rdma resource to charge + */ +static int charge_cg_resource(struct rdma_cgroup *cg, + struct rdmacg_device *device, + int index, int num) +{ + struct rdmacg_resource_pool *rpool; + s64 new; + int ret = 0; +
kernel/Makefile
Quoted 10 lines
kernel/Makefile +10
-0+retry: + spin_lock(&cg->rpool_list_lock); + rpool = find_cg_rpool_locked(cg, device); + if (!rpool) { + spin_unlock(&cg->rpool_list_lock); + ret = alloc_cg_rpool(cg, device); + if (ret) + goto err; + else + goto retry;
Instead of retrying after allocation of a new rpool, why not just return the newly allocated rpool (or the existing one) from alloc_cg_rpool?
Quoted 13 lines
kernel/Makefile +12
-0+ } + new = num + rpool->resources[index].usage; + if (new > rpool->resources[index].max) { + ret = -EAGAIN; + } else { + rpool->refcnt++; + rpool->resources[index].usage = new; + } + spin_unlock(&cg->rpool_list_lock); +err: + return ret; +}
kernel/Makefile
Quoted 10 lines
kernel/Makefile +10
-0+static ssize_t rdmacg_resource_set_max(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct rdma_cgroup *cg = css_rdmacg(of_css(of)); + const char *dev_name; + struct rdmacg_resource_pool *rpool; + struct rdmacg_device *device; + char *options = strstrip(buf); + struct rdmacg_pool_info *pool_info; + u64 enables = 0;
This limits the number of resources to 64. Sounds fine to me, but I think there should be a check somewhere (maybe in rdmacg_register_device()?) to make sure someone doesn't pass too many resources.
Quoted 31 lines
kernel/Makefile +31
-0+ int *new_limits; + int i = 0, ret = 0; + + /* extract the device name first */ + dev_name = strsep(&options, " "); + if (!dev_name) { + ret = -EINVAL; + goto err; + } + + /* acquire lock to synchronize with hot plug devices */ + mutex_lock(&dev_mutex); + + device = rdmacg_get_device_locked(dev_name); + if (!device) { + ret = -ENODEV; + goto parse_err; + } + + pool_info = &device->pool_info; + + new_limits = kcalloc(pool_info->table_len, sizeof(int), GFP_KERNEL); + if (!new_limits) { + ret = -ENOMEM; + goto parse_err; + } + + ret = rdmacg_parse_limits(options, pool_info, new_limits, &enables); + if (ret) + goto opt_err; +
kernel/Makefile
Quoted 10 lines
kernel/Makefile +10
-0+retry: + spin_lock(&cg->rpool_list_lock); + rpool = find_cg_rpool_locked(cg, device); + if (!rpool) { + spin_unlock(&cg->rpool_list_lock); + ret = alloc_cg_rpool(cg, device); + if (ret) + goto opt_err; + else + goto retry;
You can avoid the retry here too. Perhaps this can go into a function.
Quoted 13 lines
kernel/Makefile +13
-0+ } + + /* now set the new limits of the rpool */ + while (enables) { + /* if user set the limit, enables bit is set */ + if (enables & BIT(i)) { + enables &= ~BIT(i); + set_resource_limit(rpool, i, new_limits[i]); + } + i++; + } + if (rpool->refcnt == 0 && + rpool->num_max_cnt == pool_info->table_len) {
kernel/Makefile
Quoted 10 lines
kernel/Makefile +10
-0+ /* + * No user of the rpool and all entries are + * set to max, so safe to delete this rpool. + */ + list_del(&rpool->cg_list); + spin_unlock(&cg->rpool_list_lock); + free_cg_rpool(rpool); + } else { + spin_unlock(&cg->rpool_list_lock); + }
You should consider putting this piece of code in a function (the check of the reference counts and release of the rpool).
kernel/Makefile
Quoted 12 lines
kernel/Makefile +11
-0+ +opt_err: + kfree(new_limits); +parse_err: + mutex_unlock(&dev_mutex); +err: + return ret ?: nbytes; +} + + +static int print_rpool_values(struct seq_file *sf,
This can return void.
Quoted 7 lines
kernel/Makefile +7
-0+ struct rdmacg_pool_info *pool_info, + u32 *value_tbl) +{ + int i; + + for (i = 0; i < pool_info->table_len; i++) { + seq_puts(sf, pool_info->resource_name_table[i]);
kernel/Makefile
Quoted 10 lines
kernel/Makefile +10
-0+ seq_putc(sf, '='); + if (value_tbl[i] == S32_MAX) + seq_puts(sf, RDMACG_MAX_STR); + else + seq_printf(sf, "%d", value_tbl[i]); + seq_putc(sf, ' '); + } + return 0; +} +
Thanks,
Haggai
Re: [PATCHv6 2/3] IB/core: added support to use rdma cgroup controller
In reply to Parav PanditQuoted 10 lines · Parav Pandit
+/**
+ *ib_device_unregister_rdmacg- unregister with rdma cgroup.
+ * @device: device to unregister.
+ *
+ * Unregister with the rdma cgroup. Should be called after
+ * all the resources are deallocated, and after a stage when any
+ * other resource allocation of user application cannot be done
+ * for this device to avoid any leak in accounting.
+ * HCA drivers should clear resource pool ops after ib stack
+ * unregisters with rdma cgroup.
HCA drivers don't supply their own ops in this version, right? If so, you can update the comment.
Quoted 11 lines
+ */
drivers/infiniband/core/cgroup.c new file +4
-0+void ib_device_unregister_rdmacg (struct ib_device *device) +{ +rdmacg_unregister_device (&device->cg_device); +}drivers/infiniband/core/device.c +0
-0
drivers/infiniband/core/device.c int ib_register_device(struct ib_device *device, · line 358
Quoted 7 lines
drivers/infiniband/core/device.c +4
-0@@ -352,10 +352,22 @@ int ib_register_device(struct ib_device *device, goto out; } +#ifdef CONFIG_CGROUP_RDMA + ret =ib_device_register_rdmacg (device); +if (ret) { +printk (KERN_WARNING "Couldn't set up InfiniBand P_Key/GID cache\n" );
You should update the error string, and I think checkpatch recommends using pr_warn().
Quoted 32 lines
drivers/infiniband/core/device.c +12
-0+ib_cache_cleanup_one (device); + goto out; + } +#endif + ret =ib_device_register_sysfs (device, port_callback);if (ret) {printk (KERN_WARNING "Couldn't register device %s with driver model\n" , device->name); +#ifdef CONFIG_CGROUP_RDMA +ib_device_unregister_rdmacg (device); +#endif ib_cache_cleanup_one (device); goto out; }@@ -405,6 +417,10 @@ void ib_unregister_device(struct ib_device *device)mutex_unlock (&device_mutex); +#ifdef CONFIG_CGROUP_RDMA +ib_device_unregister_rdmacg (device); +#endif +ib_device_unregister_sysfs (device);ib_cache_cleanup_one (device);drivers/infiniband/core/uverbs_cmd.c +0
-0
drivers/infiniband/core/uverbs_cmd.c static int create_qp(struct ib_uverbs_file *file, · line 1859
Quoted 9 lines
drivers/infiniband/core/uverbs_cmd.c +6
-0@@ -1777,6 +1851,12 @@ static int create_qp(struct ib_uverbs_file *file, &qp_lock_class);down_write (&obj->uevent.uobject.mutex); + pd =idr_read_pd (cmd->pd_handle, file->ucontext); +if (!pd) { + ret = -EINVAL ; + goto err_put; + } +
I'm not sure I understand why you need to keep the PD here. Why don't you use the same ib_device that is used to create the QP? The same applies comment also applies to other uverbs commands.
Quoted 47 lines
drivers/infiniband/core/uverbs_cmd.c +11
-3if (cmd->qp_type ==IB_QPT_XRC_TGT ) { xrcd =idr_read_xrcd (cmd->pd_handle, file->ucontext, &xrcd_uobj);@@ -1811,8 +1891,7 @@ static int create_qp(struct ib_uverbs_file *file, scq =idr_read_cq (cmd->send_cq_handle, file->ucontext, !!rcq); rcq = rcq ?: scq; - pd =idr_read_pd (cmd->pd_handle, file->ucontext); -if (!pd || !scq) { +if (!scq) { ret = -EINVAL ; goto err_put; }@@ -1858,6 +1937,11 @@ static int create_qp(struct ib_uverbs_file *file, goto err_put; } + ret =ib_rdmacg_try_charge (&obj->uevent.uobject.cg_obj, pd->device, +RDMA_VERB_RESOURCE_QP ,1 ); +if (ret) + goto err_put; +if (cmd->qp_type ==IB_QPT_XRC_TGT ) qp =ib_create_qp (pd, &attr);else @@ -1865,7 +1949,7 @@ static int create_qp(struct ib_uverbs_file *file,if (IS_ERR (qp)) { ret =PTR_ERR (qp); - goto err_put; + goto err_create; }if (cmd->qp_type !=IB_QPT_XRC_TGT ) {@@ -1940,6 +2024,10 @@ err_cb: err_destroy:ib_destroy_qp (qp); +err_create: +ib_rdmacg_uncharge (&obj->uevent.uobject.cg_obj, device, +RDMA_VERB_RESOURCE_QP ,1 ); + err_put:if (xrcd)put_xrcd_read (xrcd_uobj);
drivers/infiniband/core/uverbs_cmd.c static int __uverbs_create_xsrq(struct ib_uverbs_file *file, · line 3448
Quoted 8 lines
drivers/infiniband/core/uverbs_cmd.c +5
-0@@ -3323,6 +3441,11 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, obj->uevent.events_reported =0 ;INIT_LIST_HEAD (&obj->uevent.event_list); + ret =ib_rdmacg_try_charge (&obj->uevent.uobject.cg_obj, pd->device, +RDMA_VERB_RESOURCE_SRQ ,1 ); +if (ret) + goto err_put_cq; +
I think you need a new error label to release the PD IDR but not uncharge.
drivers/infiniband/core/uverbs_cmd.c err_destroy: · line 3517
Quoted 12 lines
drivers/infiniband/core/uverbs_cmd.c +2
-0srq = pd->device->create_srq (pd, &attr, udata);if (IS_ERR (srq)) { ret =PTR_ERR (srq);@@ -3387,6 +3510,8 @@ err_destroy:ib_destroy_srq (srq); err_put: +ib_rdmacg_uncharge (&obj->uevent.uobject.cg_obj, pd->device, +RDMA_VERB_RESOURCE_SRQ ,1 );put_pd_read (pd); err_put_cq:
Regards,
Haggai
Re: [PATCHv6 3/3] rdmacg: Added documentation for rdmacg
In reply to Parav PanditQuoted 4 lines · Parav Pandit
Added documentation for v1 and v2 version describing high level design and usage examples on using rdma controller.
Signed-off-by Parav Pandit <[email protected]>
I think you might want to mention that resource limits are reflected in the results returned from ib_uverbs_query_device/ibv_query_device or printed from "ibv_devinfo -v".
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 3/3] rdmacg: Added documentation for rdmacg
Quoted 10 lines · Haggai Eran
Quoted 4 lines · Parav Pandit
Added documentation for v1 and v2 version describing high level design and usage examples on using rdma controller.
Signed-off-by Parav Pandit <[email protected]>I think you might want to mention that resource limits are reflected in the results returned from ib_uverbs_query_device/ibv_query_device or printed from "
ibv_devinfo-v".
Its valid point.
Since this documentation is for rdma controller, I was wondering should I have it this documentation or should I add the uverbs_cmds.c?
Re: [PATCHv6 2/3] IB/core: added support to use rdma cgroup controller
In reply to Haggai EranQuoted 7 lines · Haggai Eran
Quoted 5 lines
+ * all the resources are deallocated, and after a stage when any
+ * other resource allocation of user application cannot be done
+ * for this device to avoid any leak in accounting.
+ * HCA drivers should clear resource pool ops after ib stack
+ * unregisters with rdma cgroup.HCA drivers don't supply their own ops in this version, right? If so, you can update the comment.
Yes. I will update.
Quoted 4 lines
Quoted 1 line
+
I'm not sure I understand why you need to keep the PD here. Why don't you use the same
ib_devicethat is used to create the QP? The same applies comment also applies to other uverbs commands.
My bad. Left out of previous implementation. I have changed it now.
Quoted 51 lines
Quoted 51 lines
if (cmd->qp_type == IB_QPT_XRC_TGT) { xrcd = idr_read_xrcd(cmd->pd_handle, file->ucontext, &xrcd_uobj);drivers/infiniband/core/uverbs_cmd.c +11
-3@@ -1811,8 +1891,7 @@ static int create_qp(struct ib_uverbs_file *file, scq =idr_read_cq (cmd->send_cq_handle, file->ucontext, !!rcq); rcq = rcq ?: scq; - pd =idr_read_pd (cmd->pd_handle, file->ucontext); -if (!pd || !scq) { +if (!scq) { ret = -EINVAL ; goto err_put; }@@ -1858,6 +1937,11 @@ static int create_qp(struct ib_uverbs_file *file, goto err_put; } + ret =ib_rdmacg_try_charge (&obj->uevent.uobject.cg_obj, pd->device, +RDMA_VERB_RESOURCE_QP ,1 ); +if (ret) + goto err_put; +if (cmd->qp_type ==IB_QPT_XRC_TGT ) qp =ib_create_qp (pd, &attr);else @@ -1865,7 +1949,7 @@ static int create_qp(struct ib_uverbs_file *file,if (IS_ERR (qp)) { ret =PTR_ERR (qp); - goto err_put; + goto err_create; }if (cmd->qp_type !=IB_QPT_XRC_TGT ) {@@ -1940,6 +2024,10 @@ err_cb: err_destroy:ib_destroy_qp (qp); +err_create: +ib_rdmacg_uncharge (&obj->uevent.uobject.cg_obj, device, +RDMA_VERB_RESOURCE_QP ,1 ); + err_put:if (xrcd)put_xrcd_read (xrcd_uobj);@@ -3323,6 +3441,11 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, obj->uevent.events_reported =0 ;INIT_LIST_HEAD (&obj->uevent.event_list);
Quoted 7 lines
drivers/infiniband/core/uverbs_cmd.c static int __uverbs_create_xsrq(struct ib_uverbs_file *file, · line 3448
Quoted 5 lines
drivers/infiniband/core/uverbs_cmd.c +5
-0+ ret =ib_rdmacg_try_charge (&obj->uevent.uobject.cg_obj, pd->device, +RDMA_VERB_RESOURCE_SRQ ,1 ); +if (ret) + goto err_put_cq; +I think you need a new error label to release the PD IDR but not uncharge.
Yes. Changed.
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
In reply to Haggai EranQuoted 4 lines · Haggai Eran
Hi,
Overall I the patch looks good to me. I have a few comments below.
Thanks for the review. Addressing most comments one. Some comments inline.
Quoted 1 line
Its -> It's
Ok.
Quoted 5 lines
include/linux/cgroup_rdma.h line 50
Quoted 2 lines
include/linux/cgroup_rdma.h new file +2
-0+void rdmacg_query_limit (struct rdmacg_device *device, +int *limits,int max_count);You can drop the
max_countparameter, and require the caller to always providepool_info->table_lenitems, couldn't you?
Done.
Quoted 2 lines
Quoted 1 line
+ can result into resource unavailibility to other consumers.
unavailibility -> unavailability
Done.
Quoted 7 lines
kernel/cgroup_rdma.c line 194
Quoted 5 lines
kernel/cgroup_rdma.c new file +5
-0+struct rdmacg_resource_pool *rpool; +struct rdmacg_pool_info *pool_info = &device->pool_info; + +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device);Is it possible for rpool to be NULL?
Unlikely, unless we have but in cgroup implementation.
It may be worth to add WARN_ON and return from here to avoid kernel crash.
Quoted 12 lines
Quoted 12 lines
kernel/cgroup_rdma.c new file +12
-0+static int charge_cg_resource (struct rdma_cgroup *cg, +struct rdmacg_device *device, +int index,int num) +{ +struct rdmacg_resource_pool *rpool; +s64 new; +int ret =0 ; + +retry: +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) {
Quoted 8 lines
kernel/cgroup_rdma.c line 262
Quoted 6 lines
kernel/cgroup_rdma.c new file +6
-0+spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto err; +else + goto retry;Instead of retrying after allocation of a new rpool, why not just return the newly allocated rpool (or the existing one) from
alloc_cg_rpool?
It can be done, but locking semantics just becomes difficult to review/maintain with that where alloc_cg_rpool will unlock and lock conditionally later on.
This path will be hit anyway on first allocation typically. Once application is warm up, it will be unlikely to enter here. I should change if(!rpool) to if (unlikely(!rpool)).
Quoted 14 lines
Quoted 13 lines
kernel/cgroup_rdma.c new file +12
-0+ } + new = num + rpool->resources[index].usage; +if (new > rpool->resources[index].max) { + ret = -EAGAIN ; + }else { + rpool->refcnt++; + rpool->resources[index].usage = new; + } +spin_unlock (&cg->rpool_list_lock); +err: +return ret; +}
Quoted 13 lines
kernel/cgroup_rdma.c line 521
Quoted 10 lines
kernel/cgroup_rdma.c new file +10
-0+static ssize_t rdmacg_resource_set_max (struct kernfs_open_file *of, +char *buf,size_t nbytes,loff_t off) +{ +struct rdma_cgroup *cg =css_rdmacg (of_css (of)); +const char *dev_name; +struct rdmacg_resource_pool *rpool; +struct rdmacg_device *device; +char *options =strstrip (buf); +struct rdmacg_pool_info *pool_info; +u64 enables =0 ;This limits the number of resources to 64. Sounds fine to me, but I think there should be a check somewhere (maybe in
rdmacg_register_device()?) to make sure someone doesn't pass too many resources.
Right. Such check is in place in rdmacg_register_device which return EINVAL when more than 64 resources are requested.
Quoted 11 lines
kernel/cgroup_rdma.c line 562
Quoted 9 lines
kernel/cgroup_rdma.c new file +9
-0+spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) { +spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto opt_err; +else + goto retry;You can avoid the retry here too. Perhaps this can go into a function.
In v5 I had wrapper around code which used to similar hiding using get_cg_rpool and put_cg_rpool helper functions.
But Tejun was of opinion that I should have locks outside of all those functions. With that approach, this is done.
So I think its ok. to have it this way.
Quoted 23 lines
Quoted 13 lines
kernel/cgroup_rdma.c new file +13
-0+ } + +/* now set the new limits of the rpool */ +while (enables) { +/* if user set the limit, enables bit is set */ +if (enables &BIT (i)) { + enables &= ~BIT (i); +set_resource_limit (rpool, i, new_limits[i]); + } + i++; + } +if (rpool->refcnt ==0 && + rpool->num_max_cnt == pool_info->table_len) {kernel/cgroup_rdma.c line 585
Quoted 10 lines
kernel/cgroup_rdma.c new file +10
-0+/* +* No user of the rpool and all entries are +* set to max, so safe to delete this rpool. +*/ +list_del (&rpool->cg_list); +spin_unlock (&cg->rpool_list_lock); +free_cg_rpool (rpool); + }else { +spin_unlock (&cg->rpool_list_lock); + }
Quoted 3 lines
You should consider putting this piece of code in a function (the check of the reference counts and release of the rpool).
Yes. I did. Same as above comment. Also this function will have to unlock. Its usually better to lock/unlock from same function level, instead of locking at one level and unlocking from inside the function.
Or
I should havecg_rpool_cond_free_unlock() for above code (check of the reference counts and release of the rpool)?
Quoted 2 lines
Quoted 1 line
+static int print_rpool_values(struct
seq_file*sf,This can return void.
Done.
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 9 lines · Parav Pandit
Quoted 7 lines
kernel/cgroup_rdma.c line 194
Quoted 5 lines
kernel/cgroup_rdma.c new file +5
-0+struct rdmacg_resource_pool *rpool; +struct rdmacg_pool_info *pool_info = &device->pool_info; + +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device);Is it possible for rpool to be NULL?
Unlikely, unless we have but in cgroup implementation.
It may be worth to addWARN_ONand return from here to avoid kernel crash.
Sounds good.
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
kernel/cgroup_rdma.c new file +12
-0+static int charge_cg_resource (struct rdma_cgroup *cg, +struct rdmacg_device *device, +int index,int num) +{ +struct rdmacg_resource_pool *rpool; +s64 new; +int ret =0 ; + +retry: +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) {Quoted 8 lines
kernel/cgroup_rdma.c line 262
Quoted 6 lines
kernel/cgroup_rdma.c new file +6
-0+spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto err; +else + goto retry;Instead of retrying after allocation of a new rpool, why not just return the newly allocated rpool (or the existing one) from
alloc_cg_rpool?
Quoted 3 lines
It can be done, but locking semantics just becomes difficult to review/maintain with that where
alloc_cg_rpoolwill unlock and lock conditionally later on.
Maybe I'm missing something, but couldn't you simply lock rpool_list_lock inside alloc_cg_rpool()? It already does that around its call to find_cg_rpool_locked() and the insertion to cg_list.
Quoted 3 lines
This path will be hit anyway on first allocation typically. Once application is warm up, it will be unlikely to enter here. I should change if(!rpool) to if (unlikely(!rpool)).
Theoretically the new allocated rpool can be released again by the time you get to the second call to find_cg_rpool_locked().
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
kernel/cgroup_rdma.c new file +9
-0+spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) { +spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto opt_err; +else + goto retry;
Quoted 7 lines
Quoted 2 lines
You can avoid the retry here too. Perhaps this can go into a function.
In v5 I had wrapper around code which used to similar hiding using
get_cg_rpoolandput_cg_rpoolhelper functions.
But Tejun was of opinion that I should have locks outside of all those functions. With that approach, this is done.
So I think its ok. to have it this way.
I thought that was about functions that only locked the lock, called the find function, and released the lock. What I'm suggesting is to have one function that does "lock + find + allocate if needed + unlock", and another function that does (under caller's lock) "check ref count + check max count + release rpool".
Quoted 26 lines
Quoted 23 lines
Quoted 13 lines
kernel/cgroup_rdma.c new file +13
-0+ } + +/* now set the new limits of the rpool */ +while (enables) { +/* if user set the limit, enables bit is set */ +if (enables &BIT (i)) { + enables &= ~BIT (i); +set_resource_limit (rpool, i, new_limits[i]); + } + i++; + } +if (rpool->refcnt ==0 && + rpool->num_max_cnt == pool_info->table_len) {kernel/cgroup_rdma.c line 585
Quoted 10 lines
kernel/cgroup_rdma.c new file +10
-0+/* +* No user of the rpool and all entries are +* set to max, so safe to delete this rpool. +*/ +list_del (&rpool->cg_list); +spin_unlock (&cg->rpool_list_lock); +free_cg_rpool (rpool); + }else { +spin_unlock (&cg->rpool_list_lock); + }Quoted 3 lines
You should consider putting this piece of code in a function (the check of the reference counts and release of the rpool).
Quoted 8 lines
Yes. I did. Same as above comment. Also this function will have to unlock. Its usually better to lock/unlock from same function level, instead of locking at one level and unlocking from inside the function.
Or
I should havecg_rpool_cond_free_unlock()for above code (check of the reference counts and release of the rpool)?
It is confusing to lock and unlock in different contexts. Why not lock in the caller context? free_cg_rpool() can be called under rpool_list_lock, couldn't it? It locks device->rpool_lock, but uncharge_cg_resource() also locks both in the same order.
Thanks,
Haggai
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 13 lines · Haggai Eran
Quoted 13 lines
Quoted 12 lines
kernel/cgroup_rdma.c line 262
Quoted 10 lines
kernel/cgroup_rdma.c new file +10
-0+retry: +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) { +spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto err; +else + goto retry;Instead of retrying after allocation of a new rpool, why not just return the newly allocated rpool (or the existing one) from
alloc_cg_rpool?
Quoted 6 lines
Quoted 3 lines
It can be done, but locking semantics just becomes difficult to review/maintain with that where
alloc_cg_rpoolwill unlock and lock conditionally later on.Maybe I'm missing something, but couldn't you simply lock
rpool_list_lockinsidealloc_cg_rpool()? It already does that around its call tofind_cg_rpool_locked()and the insertion tocg_list.
No. ref_count and usage counters are updated at level where lock is taken in charge_cg_resource().
If I move locking rpool_list_lock inside alloc_cg_rpool, unlocking will continue outside, alloc_cg_rpool() when its found or allocated. As you acknowledged in below comment that this makes confusing to lock/unlock from different context, I think current implementation achieves both.
(a) take lock from single context
(b) keep functionality of find and alloc in two separate individual functions
Quoted 7 lines
Quoted 4 lines
This path will be hit anyway on first allocation typically. Once application is warm up, it will be unlikely to enter here. I should change if(!rpool) to if (unlikely(!rpool)).
Theoretically the new allocated rpool can be released again by the time you get to the second call to
find_cg_rpool_locked().
Thats ok, because if that occurs find_cg_rpool_locked() won't find the entry and will try to allocate again.
Things work fine in that case.
Quoted 3 lines
I thought that was about functions that only locked the lock, called the find function, and released the lock. What I'm suggesting is to have one function that does "lock + find + allocate if needed + unlock",
I had similar function in past which does,
"lock + find + allocate if needed + + inc_ref_cnt + unlock", (get_cg_rpool) update usage_counter atomically, because other thread/process might update too. check atomic_dec_cnt - on reaching zero, "lock + del_entry + unlock + free".
Tejun asked to simplify this to,
"lock + find + allocate if needed + inc_ref_cnt_without_atomic" + unlock". which I did in this patch v6.
Quoted 3 lines
and another
function that does (under caller's lock) "check ref count + check max count + release rpool".
This can be done. Have one dumb basic question for thiat.
Can we call kfree() with spin_lock held? All these years I tend to avoid doing so.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
Quoted 2 lines
Can we call
kfree()withspin_lockheld? All these years I tend to avoid doing so.
Also it doesn't look correct to hold the lock while freeing the memory which is totally unrelated to the lock.
With that I think current code appears ok with exception that its duplicated at two place for code readability around lock. What say?
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
In reply to Parav PanditQuoted 21 lines · Parav Pandit
Quoted 13 lines · Haggai Eran
Quoted 13 lines
Quoted 12 lines
kernel/cgroup_rdma.c line 262
Quoted 10 lines
kernel/cgroup_rdma.c new file +10
-0+retry: +spin_lock (&cg->rpool_list_lock); + rpool =find_cg_rpool_locked (cg, device); +if (!rpool) { +spin_unlock (&cg->rpool_list_lock); + ret =alloc_cg_rpool (cg, device); +if (ret) + goto err; +else + goto retry;Instead of retrying after allocation of a new rpool, why not just return the newly allocated rpool (or the existing one) from
alloc_cg_rpool?Quoted 6 lines
Quoted 3 lines
It can be done, but locking semantics just becomes difficult to review/maintain with that where
alloc_cg_rpoolwill unlock and lock conditionally later on.Maybe I'm missing something, but couldn't you simply lock
rpool_list_lockinsidealloc_cg_rpool()? It already does that around its call tofind_cg_rpool_locked()and the insertion tocg_list.
Quoted 9 lines
No.
ref_countand usage counters are updated at level where lock is taken incharge_cg_resource().
If I move lockingrpool_list_lockinsidealloc_cg_rpool, unlocking will continue outside,alloc_cg_rpool()when its found or allocated. As you acknowledged in below comment that this makes confusing to lock/unlock from different context, I think current implementation achieves both.
(a) take lock from single context
(b) keep functionality of find and alloc in two separate individual functions
Okay, fair enough.
Quoted 9 lines
Quoted 3 lines
I thought that was about functions that only locked the lock, called the find function, and released the lock. What I'm suggesting is to have one function that does "lock + find + allocate if needed + unlock",
I had similar function in past which does,
"lock + find + allocate if needed + +inc_ref_cnt+ unlock", (get_cg_rpool) updateusage_counteratomically, because other thread/process might update too. checkatomic_dec_cnt- on reaching zero, "lock +del_entry+ unlock + free".
Quoted 4 lines
Tejun asked to simplify this to,
"lock + find + allocate if needed +
inc_ref_cnt_without_atomic" + unlock". which I did in this patch v6.
Okay.
Quoted 7 lines
Quoted 3 lines
and another
function that does (under caller's lock) "check ref count + check max count + release rpool".This can be done. Have one dumb basic question for thiat. Can we call
kfree()withspin_lockheld? All these years I tend to avoid doing so.
I think so. This is an old link but I think it still applies:
https://lkml.org/lkml/2004/11/21/130
Re: [PATCHv6 1/3] rdmacg: Added rdma cgroup controller
In reply to Parav PanditQuoted 7 lines · Parav Pandit
Quoted 2 lines
Can we call
kfree()withspin_lockheld? All these years I tend to avoid doing so.Also it doesn't look correct to hold the lock while freeing the memory which is totally unrelated to the lock.
With that I think current code appears ok with exception that its duplicated at two place for code readability around lock. What say?
Yes, the only thing that bothered me there was the duplication.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCHv6 3/3] rdmacg: Added documentation for rdmacg
In reply to Parav PanditQuoted 7 lines · Parav Pandit
Quoted 6 lines · Haggai Eran
Quoted 4 lines · Parav Pandit
Added documentation for v1 and v2 version describing high level design and usage examples on using rdma controller.
Signed-off-by Parav Pandit <[email protected]>
Quoted 7 lines
Quoted 4 lines
I think you might want to mention that resource limits are reflected in the results returned from ib_uverbs_query_device/ibv_query_device or printed from "
ibv_devinfo-v".Its valid point.
Since this documentation is for rdma controller, I was wondering should I have it this documentation or should I add theuverbs_cmds.c?
I was thinking it should be in the documentation because an application developer might look there first, without reading uverbs_cmd.c.
Haggai
Re: [PATCHv6 3/3] rdmacg: Added documentation for rdmacg
o.k. I will add a note there that IB stack would honor the limits given by the rdma cgroup.
Quoted 21 lines · Haggai Eran
Quoted 7 lines · Parav Pandit
Quoted 6 lines · Haggai Eran
Quoted 4 lines · Parav Pandit
Added documentation for v1 and v2 version describing high level design and usage examples on using rdma controller.
Signed-off-by Parav Pandit <[email protected]>Quoted 7 lines
Quoted 4 lines
I think you might want to mention that resource limits are reflected in the results returned from ib_uverbs_query_device/ibv_query_device or printed from "
ibv_devinfo-v".Its valid point.
Since this documentation is for rdma controller, I was wondering should I have it this documentation or should I add theuverbs_cmds.c?I was thinking it should be in the documentation because an application developer might look there first, without reading
uverbs_cmd.c.Haggai