Comments (6)
Sorry for the delay. I’ve taken another look. Recapping, we have the array
fds_lock = malloc(max_fds * sizeof(*fds_lock));
and the companion
fds = malloc(max_fds * sizeof(*fds));
For both these arrays, we must maintain that the array index is between 0 and max_fds - 1
, inclusive. In the case of a loop like for(i=0; i<max_fds; i++)
we’re good as you mention, so what’s left is inspect all other call sites where we don’t iterate.
In both cases, the functions have an if(fd >= ...)
block at the top. Because we must have fd < max_fds
, we should return when fd >= max_fds
. The check in free_unclaimed_pages()
here is already correct, and your patch is simply changing the check to be correct in the store_pageinfo()
case.
Again, sorry about the delay, and thanks for contributing! Merging your change.
from nocache.
Are you sure that setlimit works?
$ env NOCACHE_MAX_FDS=1 nocache ./a.out;
soft limit= 16384 hard limit= 16384
soft limit= 100 hard limit= 1024
from nocache.
@pavlinux as far as I understand you were left with the impression that the resource limits for the child process would be amended by setting NOCACHE_MAX_FDS
.My understanding is that NOCACHE_MAX_FDS
only controls the number of file descriptors that nocache
would posix_fadvise
on (the lesser between that env var and the current RLIMIT_NOFILE
hard limit will be used). It would not change resource limits neither for itself nor for the child process. (see here)
from nocache.
Stanislav, thanks for digging into this. I think in the default settings it doesn’t matter if the value is 2^20 or 2^20-1, but after re-reading man getrlimit
I agree with you that it would be better if the max fd number follows the same semantics as the RLIMIT_NOFILE
limit (i.e. not count FDs, but instead denote an exclusive upper bound on the FD number).
However, I belive your pull request introduces the possiblity of an out-of-bounds array access: fds
is initialized with max_fds
elements, which means it can store a FD with number 0..max_fds-1
. Your pull request changes the semantics bound, but doesn’t grow the memory allocation by 1 (here). Can you amend the PR if you agree?
from nocache.
Julius, I am not entirely sure about this. The man page reads that the RLIMIT_NOFILE
is a value one greater than the maximum file descriptor number that can be opened by the process. Since I believe file descriptors are zero-based, this would mean that it matches the number of supported file descriptors. With this in mind, the current referenced allocation
fds_lock = malloc(max_fds * sizeof(*fds_lock));
makes sense to me - it would support a number of locks matching the number of file descriptors. Furthermore, I believe the fds_lock
is always accessed in a fashion similar to this:
for(i = 0; i < max_fds; i++)
so I am not sure I see where the out of bounds access may happen. However, I am not that used to C so I may be missing a key point, please follow up.
from nocache.
Merged #43
from nocache.
Related Issues (20)
- Support O_DIRECT? HOT 1
- Incompatibility with glibc 2.28 HOT 23
- Do SubProcess calls work as expected. HOT 2
- "transmission-gtk" freezes right after downloading because of "nocache" HOT 4
- nocache.c:148: init_mutexes: Assertion `fds_lock != NULL' failed. HOT 3
- nocache makes MC very slow HOT 2
- Doesn't work for pv in conjunction with physical partitions/disks? HOT 3
- GCC cache size flags HOT 3
- Lock pages from preventing of being paged and tune malloc. HOT 1
- Trivial suggestions for README.md
- effect on write cache HOT 1
- Command line parsing issue(s?) causing undefined behaviour HOT 3
- Default Thread limit is not respecting container cpu limit but underline node(vm) HOT 2
- Mention no help for huge files
- unexpected nocache overhead on trivial commands HOT 14
- BUG: pthread_mutex_lock on destroy HOT 3
- nocache works, systemd-run doesn't
- backup still using cache HOT 1
- FTBFS on armhf: symbol `fopen64' is already defined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nocache.