1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
3 *******************************************************************************
5 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
6 ** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
9 *******************************************************************************
10 ******************************************************************************/
12 #include "dlm_internal.h"
19 static struct kmem_cache
*writequeue_cache
;
20 static struct kmem_cache
*mhandle_cache
;
21 static struct kmem_cache
*msg_cache
;
22 static struct kmem_cache
*lkb_cache
;
23 static struct kmem_cache
*rsb_cache
;
24 static struct kmem_cache
*cb_cache
;
27 int __init
dlm_memory_init(void)
29 writequeue_cache
= dlm_lowcomms_writequeue_cache_create();
30 if (!writequeue_cache
)
33 mhandle_cache
= dlm_midcomms_cache_create();
37 lkb_cache
= kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb
),
38 __alignof__(struct dlm_lkb
), 0, NULL
);
42 msg_cache
= dlm_lowcomms_msg_cache_create();
46 rsb_cache
= kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb
),
47 __alignof__(struct dlm_rsb
), 0, NULL
);
51 cb_cache
= kmem_cache_create("dlm_cb", sizeof(struct dlm_callback
),
52 __alignof__(struct dlm_callback
), 0,
60 kmem_cache_destroy(rsb_cache
);
62 kmem_cache_destroy(msg_cache
);
64 kmem_cache_destroy(lkb_cache
);
66 kmem_cache_destroy(mhandle_cache
);
68 kmem_cache_destroy(writequeue_cache
);
73 void dlm_memory_exit(void)
77 kmem_cache_destroy(writequeue_cache
);
78 kmem_cache_destroy(mhandle_cache
);
79 kmem_cache_destroy(msg_cache
);
80 kmem_cache_destroy(lkb_cache
);
81 kmem_cache_destroy(rsb_cache
);
82 kmem_cache_destroy(cb_cache
);
85 char *dlm_allocate_lvb(struct dlm_ls
*ls
)
87 return kzalloc(ls
->ls_lvblen
, GFP_ATOMIC
);
90 void dlm_free_lvb(char *p
)
95 struct dlm_rsb
*dlm_allocate_rsb(void)
97 return kmem_cache_zalloc(rsb_cache
, GFP_ATOMIC
);
100 static void __free_rsb_rcu(struct rcu_head
*rcu
)
102 struct dlm_rsb
*r
= container_of(rcu
, struct dlm_rsb
, rcu
);
104 dlm_free_lvb(r
->res_lvbptr
);
105 kmem_cache_free(rsb_cache
, r
);
108 void dlm_free_rsb(struct dlm_rsb
*r
)
110 call_rcu(&r
->rcu
, __free_rsb_rcu
);
113 struct dlm_lkb
*dlm_allocate_lkb(void)
115 return kmem_cache_zalloc(lkb_cache
, GFP_ATOMIC
);
118 static void __free_lkb_rcu(struct rcu_head
*rcu
)
120 struct dlm_lkb
*lkb
= container_of(rcu
, struct dlm_lkb
, rcu
);
122 if (test_bit(DLM_DFL_USER_BIT
, &lkb
->lkb_dflags
)) {
123 struct dlm_user_args
*ua
;
126 kfree(ua
->lksb
.sb_lvbptr
);
131 kmem_cache_free(lkb_cache
, lkb
);
134 void dlm_free_lkb(struct dlm_lkb
*lkb
)
136 call_rcu(&lkb
->rcu
, __free_lkb_rcu
);
139 struct dlm_mhandle
*dlm_allocate_mhandle(void)
141 return kmem_cache_alloc(mhandle_cache
, GFP_ATOMIC
);
144 void dlm_free_mhandle(struct dlm_mhandle
*mhandle
)
146 kmem_cache_free(mhandle_cache
, mhandle
);
149 struct writequeue_entry
*dlm_allocate_writequeue(void)
151 return kmem_cache_alloc(writequeue_cache
, GFP_ATOMIC
);
154 void dlm_free_writequeue(struct writequeue_entry
*writequeue
)
156 kmem_cache_free(writequeue_cache
, writequeue
);
159 struct dlm_msg
*dlm_allocate_msg(void)
161 return kmem_cache_alloc(msg_cache
, GFP_ATOMIC
);
164 void dlm_free_msg(struct dlm_msg
*msg
)
166 kmem_cache_free(msg_cache
, msg
);
169 struct dlm_callback
*dlm_allocate_cb(void)
171 return kmem_cache_alloc(cb_cache
, GFP_ATOMIC
);
174 void dlm_free_cb(struct dlm_callback
*cb
)
176 kmem_cache_free(cb_cache
, cb
);