Motr  M0
memory.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 
25 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_LIB
26 #include "lib/assert.h" /* M0_PRE */
27 #include "lib/memory.h"
28 
37 M0_INTERNAL void *m0_arch_alloc(size_t size)
38 {
59  return kzalloc(size, GFP_NOFS);
60 }
61 
62 M0_INTERNAL void m0_arch_free(void *data)
63 {
64  kfree(data);
65 }
66 
67 M0_INTERNAL void m0_arch_allocated_zero(void *data, size_t size)
68 {
69  /* do nothing already zeroed. */
70 }
71 
72 M0_INTERNAL void *m0_arch_alloc_nz(size_t size)
73 {
75  return kmalloc(size, GFP_NOFS);
76 }
77 
78 M0_INTERNAL void m0_arch_memory_pagein(void *addr, size_t size)
79 {
80  /* kernel memory is not swappable */
81 }
82 
83 M0_INTERNAL size_t m0_arch_alloc_size(void *data)
84 {
85  return ksize(data);
86 }
87 
88 M0_INTERNAL void *m0_arch_alloc_aligned(size_t alignment, size_t size)
89 {
90  /*
91  * Currently it supports alignment of PAGE_SHIFT only.
92  */
93  M0_PRE(alignment == PAGE_SIZE);
94  return size == 0 ? NULL : alloc_pages_exact(size,
95  GFP_NOFS | __GFP_ZERO);
96 }
97 
98 M0_INTERNAL void m0_arch_free_aligned(void *addr, size_t size, unsigned shift)
99 {
100  M0_PRE(shift == PAGE_SHIFT);
101  free_pages_exact(addr, size);
102 }
103 
104 M0_INTERNAL void *m0_arch_alloc_wired(size_t size, unsigned shift)
105 {
106  return m0_alloc_aligned(size, shift);
107 }
108 
109 M0_INTERNAL void m0_arch_free_wired(void *data, size_t size, unsigned shift)
110 {
111  m0_free_aligned(data, size, shift);
112 }
113 
114 M0_INTERNAL size_t m0_arch_allocated(void)
115 {
116  return 0;
117 }
118 
119 M0_INTERNAL int m0_arch_dont_dump(void *p, size_t size)
120 {
121  return 0;
122 }
123 
124 M0_INTERNAL int m0_arch_memory_init(void)
125 {
126  return 0;
127 }
128 
129 M0_INTERNAL void m0_arch_memory_fini(void)
130 {
131 }
132 
133 M0_INTERNAL int m0_arch_pagesize_get(void)
134 {
135  return PAGE_SIZE;
136 }
137 
138 M0_INTERNAL int m0_arch_pageshift_get(void)
139 {
140  return PAGE_SHIFT;
141 }
142 
145 /*
146  * Local variables:
147  * c-indentation-style: "K&R"
148  * c-basic-offset: 8
149  * tab-width: 8
150  * fill-column: 80
151  * scroll-step: 1
152  * End:
153  */
static struct m0_addb2_philter p
Definition: consumer.c:40
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_arch_free_wired(void *data, size_t size, unsigned shift)
Definition: memory.c:109
M0_INTERNAL void m0_arch_memory_pagein(void *addr, size_t size)
Definition: memory.c:78
M0_INTERNAL size_t m0_arch_alloc_size(void *data)
Definition: memory.c:83
struct m0_bufvec data
Definition: di.c:40
M0_INTERNAL void m0_free_aligned(void *data, size_t size, unsigned shift)
Definition: memory.c:192
#define PAGE_SIZE
Definition: lnet_ut.c:277
M0_INTERNAL int m0_arch_pagesize_get(void)
Definition: memory.c:133
M0_INTERNAL void m0_arch_free_aligned(void *addr, size_t size, unsigned shift)
Definition: memory.c:98
M0_INTERNAL void * m0_arch_alloc(size_t size)
Definition: memory.c:37
M0_INTERNAL int m0_arch_memory_init(void)
Definition: memory.c:124
M0_INTERNAL void m0_arch_free(void *data)
Definition: memory.c:62
M0_INTERNAL void * m0_arch_alloc_nz(size_t size)
Definition: memory.c:72
Definition: xcode.h:73
M0_INTERNAL void * m0_arch_alloc_aligned(size_t alignment, size_t size)
Definition: memory.c:88
M0_INTERNAL void m0_arch_allocated_zero(void *data, size_t size)
Definition: memory.c:67
m0_bcount_t size
Definition: di.c:39
M0_INTERNAL int m0_arch_pageshift_get(void)
Definition: memory.c:138
M0_INTERNAL void * m0_arch_alloc_wired(size_t size, unsigned shift)
Definition: memory.c:104
M0_INTERNAL size_t m0_arch_allocated(void)
Definition: memory.c:114
M0_INTERNAL void * m0_alloc_aligned(size_t size, unsigned shift)
Definition: memory.c:168
M0_INTERNAL void m0_arch_memory_fini(void)
Definition: memory.c:129
M0_INTERNAL int m0_arch_dont_dump(void *p, size_t size)
Definition: memory.c:119