blob: ce35c3c19aeb5fbe32fe533036826753794d6987 [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001// SPDX-License-Identifier: GPL-2.0-only
David Teiglande7fd4172006-01-18 09:30:29 +00002/******************************************************************************
3*******************************************************************************
4**
5** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
David Teigland52bda2b2007-11-07 09:06:49 -06006** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00007**
David Teiglande7fd4172006-01-18 09:30:29 +00008**
9*******************************************************************************
10******************************************************************************/
11
12#include "dlm_internal.h"
Alexander Aring6c547f22021-11-30 14:47:18 -050013#include "midcomms.h"
Alexander Aring3af23262021-11-30 14:47:19 -050014#include "lowcomms.h"
David Teiglande7fd4172006-01-18 09:30:29 +000015#include "config.h"
16#include "memory.h"
17
Alexander Aring3af23262021-11-30 14:47:19 -050018static struct kmem_cache *writequeue_cache;
Alexander Aring6c547f22021-11-30 14:47:18 -050019static struct kmem_cache *mhandle_cache;
Alexander Aringe4dc81e2021-11-30 14:47:20 -050020static struct kmem_cache *msg_cache;
Christoph Lametere18b8902006-12-06 20:33:20 -080021static struct kmem_cache *lkb_cache;
David Teigland3881ac02011-07-07 14:05:03 -050022static struct kmem_cache *rsb_cache;
David Teiglande7fd4172006-01-18 09:30:29 +000023
24
Denis Cheng30727172008-02-02 01:53:46 +080025int __init dlm_memory_init(void)
David Teiglande7fd4172006-01-18 09:30:29 +000026{
Alexander Aring3af23262021-11-30 14:47:19 -050027 writequeue_cache = dlm_lowcomms_writequeue_cache_create();
28 if (!writequeue_cache)
29 goto out;
30
Alexander Aring6c547f22021-11-30 14:47:18 -050031 mhandle_cache = dlm_midcomms_cache_create();
32 if (!mhandle_cache)
Alexander Aring3af23262021-11-30 14:47:19 -050033 goto mhandle;
Alexander Aring6c547f22021-11-30 14:47:18 -050034
David Teiglande7fd4172006-01-18 09:30:29 +000035 lkb_cache = kmem_cache_create("dlm_lkb", sizeof(struct dlm_lkb),
Paul Mundt20c2df82007-07-20 10:11:58 +090036 __alignof__(struct dlm_lkb), 0, NULL);
David Teiglande7fd4172006-01-18 09:30:29 +000037 if (!lkb_cache)
Alexander Aring6c547f22021-11-30 14:47:18 -050038 goto lkb;
David Teigland3881ac02011-07-07 14:05:03 -050039
Alexander Aringe4dc81e2021-11-30 14:47:20 -050040 msg_cache = dlm_lowcomms_msg_cache_create();
41 if (!msg_cache)
42 goto msg;
43
David Teigland3881ac02011-07-07 14:05:03 -050044 rsb_cache = kmem_cache_create("dlm_rsb", sizeof(struct dlm_rsb),
45 __alignof__(struct dlm_rsb), 0, NULL);
Alexander Aring6c547f22021-11-30 14:47:18 -050046 if (!rsb_cache)
47 goto rsb;
David Teigland3881ac02011-07-07 14:05:03 -050048
Dan Carpenter75af271e2012-05-15 11:58:12 +030049 return 0;
Alexander Aring6c547f22021-11-30 14:47:18 -050050
51rsb:
Alexander Aringe4dc81e2021-11-30 14:47:20 -050052 kmem_cache_destroy(msg_cache);
53msg:
Alexander Aring6c547f22021-11-30 14:47:18 -050054 kmem_cache_destroy(lkb_cache);
55lkb:
56 kmem_cache_destroy(mhandle_cache);
Alexander Aring3af23262021-11-30 14:47:19 -050057mhandle:
58 kmem_cache_destroy(writequeue_cache);
Alexander Aring6c547f22021-11-30 14:47:18 -050059out:
60 return -ENOMEM;
David Teiglande7fd4172006-01-18 09:30:29 +000061}
62
63void dlm_memory_exit(void)
64{
Alexander Aring3af23262021-11-30 14:47:19 -050065 kmem_cache_destroy(writequeue_cache);
Alexander Aring6c547f22021-11-30 14:47:18 -050066 kmem_cache_destroy(mhandle_cache);
Alexander Aringe4dc81e2021-11-30 14:47:20 -050067 kmem_cache_destroy(msg_cache);
Wen Yangf31a8962018-11-28 15:25:00 +080068 kmem_cache_destroy(lkb_cache);
69 kmem_cache_destroy(rsb_cache);
David Teiglande7fd4172006-01-18 09:30:29 +000070}
71
David Teigland52bda2b2007-11-07 09:06:49 -060072char *dlm_allocate_lvb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000073{
74 char *p;
75
David Teigland573c24c2009-11-30 16:34:43 -060076 p = kzalloc(ls->ls_lvblen, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000077 return p;
78}
79
David Teigland52bda2b2007-11-07 09:06:49 -060080void dlm_free_lvb(char *p)
David Teiglande7fd4172006-01-18 09:30:29 +000081{
82 kfree(p);
83}
84
David Teigland3881ac02011-07-07 14:05:03 -050085struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +000086{
87 struct dlm_rsb *r;
88
David Teigland3881ac02011-07-07 14:05:03 -050089 r = kmem_cache_zalloc(rsb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000090 return r;
91}
92
David Teigland52bda2b2007-11-07 09:06:49 -060093void dlm_free_rsb(struct dlm_rsb *r)
David Teiglande7fd4172006-01-18 09:30:29 +000094{
95 if (r->res_lvbptr)
David Teigland52bda2b2007-11-07 09:06:49 -060096 dlm_free_lvb(r->res_lvbptr);
David Teigland3881ac02011-07-07 14:05:03 -050097 kmem_cache_free(rsb_cache, r);
David Teiglande7fd4172006-01-18 09:30:29 +000098}
99
David Teigland52bda2b2007-11-07 09:06:49 -0600100struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
David Teiglande7fd4172006-01-18 09:30:29 +0000101{
102 struct dlm_lkb *lkb;
103
David Teigland573c24c2009-11-30 16:34:43 -0600104 lkb = kmem_cache_zalloc(lkb_cache, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +0000105 return lkb;
106}
107
David Teigland52bda2b2007-11-07 09:06:49 -0600108void dlm_free_lkb(struct dlm_lkb *lkb)
David Teiglande7fd4172006-01-18 09:30:29 +0000109{
David Teigland597d0ca2006-07-12 16:44:04 -0500110 if (lkb->lkb_flags & DLM_IFL_USER) {
111 struct dlm_user_args *ua;
David Teiglandd292c0c2008-02-06 23:27:04 -0600112 ua = lkb->lkb_ua;
David Teigland597d0ca2006-07-12 16:44:04 -0500113 if (ua) {
Wen Yangf31a8962018-11-28 15:25:00 +0800114 kfree(ua->lksb.sb_lvbptr);
David Teigland597d0ca2006-07-12 16:44:04 -0500115 kfree(ua);
116 }
117 }
David Teiglande7fd4172006-01-18 09:30:29 +0000118 kmem_cache_free(lkb_cache, lkb);
119}
120
Alexander Aring6c547f22021-11-30 14:47:18 -0500121struct dlm_mhandle *dlm_allocate_mhandle(void)
122{
123 return kmem_cache_alloc(mhandle_cache, GFP_NOFS);
124}
125
126void dlm_free_mhandle(struct dlm_mhandle *mhandle)
127{
128 kmem_cache_free(mhandle_cache, mhandle);
129}
Alexander Aring3af23262021-11-30 14:47:19 -0500130
131struct writequeue_entry *dlm_allocate_writequeue(void)
132{
133 return kmem_cache_alloc(writequeue_cache, GFP_ATOMIC);
134}
135
136void dlm_free_writequeue(struct writequeue_entry *writequeue)
137{
138 kmem_cache_free(writequeue_cache, writequeue);
139}
Alexander Aringe4dc81e2021-11-30 14:47:20 -0500140
141struct dlm_msg *dlm_allocate_msg(gfp_t allocation)
142{
143 return kmem_cache_alloc(msg_cache, allocation);
144}
145
146void dlm_free_msg(struct dlm_msg *msg)
147{
148 kmem_cache_free(msg_cache, msg);
149}