|
|
Subscribe / Log in / New account

The "too small to fail" memory-allocation rule

The "too small to fail" memory-allocation rule

Posted Jan 19, 2015 15:53 UTC (Mon) by pal (guest, #57253)
Parent article: The "too small to fail" memory-allocation rule

there is a well-known rule: never call foreign code while holding a lock. which is violated by calling memory allocation in xfs. changing memory allocation behavior instead of following this simple rule is a whack-a-mole game itself


to post comments

The "too small to fail" memory-allocation rule

Posted Jan 19, 2015 18:33 UTC (Mon) by dgm (subscriber, #49227) [Link]

I have never seen this rule (or at least not in that form). What I have seen is a guideline that hints that the code protected by a lock should be as small and straightforward as possible.

Your rule actually makes a lot of sense. Locks exists to ensure concurrent access to a shared resource in a coherent way. If you're calling "foreign" code, then your code is not just accessing the shared resource, and thus it is protecting too much. Probably the "right" thing to do is to move all resource allocations (including memory) outside the lock scope, and only acquire the lock once all the needed resources are ready.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds