kernel/vm: Use 64-bit signed types explicitly for memory computations.
off_t is a signed 64-bit type, but size_t isn't signed or 64-bit on 32-bit platforms. That meant adding a sign bit caused strange things to happen there. Fixes incorrect free-memory computations on 32-bit. (cherry picked from commit cc565c81afd2dfba34de6ced607199d757080a8d) Change-Id: I294f92ac1279a6311347b5e25341542d8c862013 Reviewed-on: https://review.haiku-os.org/c/haiku/+/11326 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
0178ddbc88
commit
9d80b76b46
@@ -250,11 +250,11 @@ static uint32 sPageMappingsMask;
|
|||||||
static rw_lock sAreaCacheLock = RW_LOCK_INITIALIZER("area->cache");
|
static rw_lock sAreaCacheLock = RW_LOCK_INITIALIZER("area->cache");
|
||||||
|
|
||||||
static rw_spinlock sAvailableMemoryLock = B_RW_SPINLOCK_INITIALIZER;
|
static rw_spinlock sAvailableMemoryLock = B_RW_SPINLOCK_INITIALIZER;
|
||||||
static off_t sAvailableMemory;
|
static int64 sAvailableMemory;
|
||||||
#if ENABLE_SWAP_SUPPORT
|
#if ENABLE_SWAP_SUPPORT
|
||||||
static off_t sAvailableMemoryAndSwap;
|
static int64 sAvailableMemoryAndSwap;
|
||||||
#endif
|
#endif
|
||||||
static off_t sNeededMemory;
|
static int64 sNeededMemory;
|
||||||
|
|
||||||
static uint32 sPageFaults;
|
static uint32 sPageFaults;
|
||||||
static VMPhysicalPageMapper* sPhysicalPageMapper;
|
static VMPhysicalPageMapper* sPhysicalPageMapper;
|
||||||
@@ -4432,20 +4432,20 @@ vm_unreserve_memory_or_swap(size_t amount)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
vm_try_reserve_internal(off_t& pool, uint32 resource,
|
vm_try_reserve_internal(int64& pool, uint32 resource,
|
||||||
size_t amount, int priority, bigtime_t absoluteTimeout)
|
int64 amount, int priority, bigtime_t absoluteTimeout)
|
||||||
{
|
{
|
||||||
ASSERT((amount % B_PAGE_SIZE) == 0);
|
ASSERT((amount % B_PAGE_SIZE) == 0);
|
||||||
ASSERT(priority >= 0 && priority < (int)B_COUNT_OF(kMemoryReserveForPriority));
|
ASSERT(priority >= 0 && priority < (int)B_COUNT_OF(kMemoryReserveForPriority));
|
||||||
TRACE(("try to reserve %lu bytes, %Lu left\n", amount, pool));
|
TRACE(("try to reserve %lu bytes, %Lu left\n", amount, pool));
|
||||||
|
|
||||||
const size_t reserve = kMemoryReserveForPriority[priority];
|
const size_t reserve = kMemoryReserveForPriority[priority];
|
||||||
const off_t amountPlusReserve = amount + reserve;
|
const int64 amountPlusReserve = amount + reserve;
|
||||||
|
|
||||||
// Try with a read-lock and atomics first, but only if there's more than double
|
// Try with a read-lock and atomics first, but only if there's more than double
|
||||||
// the amount of memory we're trying to reserve available, to avoid races.
|
// the amount of memory we're trying to reserve available, to avoid races.
|
||||||
InterruptsReadSpinLocker readLocker(sAvailableMemoryLock);
|
InterruptsReadSpinLocker readLocker(sAvailableMemoryLock);
|
||||||
if (atomic_get64(&pool) > (off_t)(amountPlusReserve + amount)) {
|
if (atomic_get64(&pool) > (amountPlusReserve + amount)) {
|
||||||
if (atomic_add64(&pool, -amount) >= amountPlusReserve)
|
if (atomic_add64(&pool, -amount) >= amountPlusReserve)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user