prometheus-client-mmap 0.9.10 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_mmaped_file/mmap.c +41 -7
- data/lib/fast_mmaped_file.bundle +0 -0
- data/lib/prometheus/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f1ee3b09ba34253c97cbc24ea1423e5a9974e679fd4a0d63c596aae583440bd
|
4
|
+
data.tar.gz: 2e2712829e334fb9d4a52658247f0e3a33b553ef40c7b9d67e008ff66d035661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa63176edd44f14614d1546fc9d3c467177e061182dc36594c3c23bcb074a6470e7b441bd36a72538ad41866d00741c7afd580a2131500eb72954e3c3458f084
|
7
|
+
data.tar.gz: 8962a9d8d7df151b4645234291fb1a2f75f1caf9a99a9d5d755c7078cbb5705850864084cd0af5330dd2b346a5d2451000035a5e88798d5391bc06f37e26bab2
|
data/ext/fast_mmaped_file/mmap.c
CHANGED
@@ -170,6 +170,35 @@ VALUE mm_s_alloc(VALUE obj) {
|
|
170
170
|
return res;
|
171
171
|
}
|
172
172
|
|
173
|
+
size_t next_page_boundary(size_t value) {
|
174
|
+
size_t page_size = sysconf(_SC_PAGESIZE);
|
175
|
+
|
176
|
+
while (page_size < value) {
|
177
|
+
page_size *= 2;
|
178
|
+
}
|
179
|
+
|
180
|
+
return page_size;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Reference implementations:
|
184
|
+
* mozilla: https://hg.mozilla.org/mozilla-central/file/3d846420a907/xpcom/glue/FileUtils.cpp#l71
|
185
|
+
* glibc: https://github.com/lattera/glibc/blob/master/sysdeps/posix/posix_fallocate.c
|
186
|
+
*/
|
187
|
+
int reserve_mmap_file_bytes(int fd, size_t size) {
|
188
|
+
#if __linux__
|
189
|
+
/* From https://stackoverflow.com/a/22820221: The difference with
|
190
|
+
* ftruncate(2) is that (on file systems supporting it, e.g. Ext4)
|
191
|
+
* disk space is indeed reserved by posix_fallocate but ftruncate
|
192
|
+
* extends the file by adding holes (and without reserving disk
|
193
|
+
* space). */
|
194
|
+
return posix_fallocate(fd, 0, size);
|
195
|
+
#else
|
196
|
+
/* We simplify the reference implemnetations since we generally
|
197
|
+
* don't need to reserve more than a page size. */
|
198
|
+
return ftruncate(fd, size);
|
199
|
+
#endif
|
200
|
+
}
|
201
|
+
|
173
202
|
VALUE mm_init(VALUE obj, VALUE fname) {
|
174
203
|
struct stat st;
|
175
204
|
int fd, smode = 0, pmode = 0, vscope, perm, init;
|
@@ -206,6 +235,7 @@ VALUE mm_init(VALUE obj, VALUE fname) {
|
|
206
235
|
}
|
207
236
|
|
208
237
|
if (fstat(fd, &st) == -1) {
|
238
|
+
close(fd);
|
209
239
|
rb_raise(rb_eArgError, "Can't stat %s", path);
|
210
240
|
}
|
211
241
|
size = st.st_size;
|
@@ -215,17 +245,21 @@ VALUE mm_init(VALUE obj, VALUE fname) {
|
|
215
245
|
offset = 0;
|
216
246
|
init = 0;
|
217
247
|
|
218
|
-
if (size == 0
|
219
|
-
if (lseek(fd, INITIAL_SIZE - 1, SEEK_END) == -1) {
|
220
|
-
rb_raise(rb_eIOError, "Can't lseek %zu", INITIAL_SIZE - 1);
|
221
|
-
}
|
222
|
-
if (write(fd, "\000", 1) != 1) {
|
223
|
-
rb_raise(rb_eIOError, "Can't extend %s", path);
|
224
|
-
}
|
248
|
+
if (size == 0) {
|
225
249
|
init = 1;
|
226
250
|
size = INITIAL_SIZE;
|
227
251
|
}
|
228
252
|
|
253
|
+
/* We need to ensure the underlying file descriptor is at least a page size.
|
254
|
+
* Otherwise, we could get a SIGBUS error if mmap() attempts to read or write
|
255
|
+
* past the file. */
|
256
|
+
size_t reserve_size = next_page_boundary(size);
|
257
|
+
|
258
|
+
if (reserve_mmap_file_bytes(fd, reserve_size) != 0) {
|
259
|
+
close(fd);
|
260
|
+
rb_raise(rb_eIOError, "Can't reserve %zu bytes for memory-mapped file", reserve_size);
|
261
|
+
}
|
262
|
+
|
229
263
|
addr = mmap(0, size, pmode, vscope, fd, offset);
|
230
264
|
|
231
265
|
if (addr == MAP_FAILED || !addr) {
|
data/lib/fast_mmaped_file.bundle
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-client-mmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Schmidt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fuzzbert
|