mirror of
https://github.com/linux-apfs/apfsprogs.git
synced 2026-05-01 15:01:13 -07:00
0aa9f9a32d
The formula for ip_fq_node_limit() currently considers containers with fewer than 376 chunks as a special case, even though they follow the same linear function as the others. The intention was to avoid dealing with negative numbers, since all the variables are unsigned and rounding behaves differently. Instead, rearrange the linear formula to avoid these problems. Signed-off-by: Ernesto A. Fernández <ernesto@corellium.com>
49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/*
|
|
* Copyright (C) 2021 Ernesto A. Fernández <ernesto@corellium.com>
|
|
*
|
|
* Calculation of filesystem parameters needed by both mkfs and fsck.
|
|
*/
|
|
|
|
#include <apfs/parameters.h>
|
|
#include <apfs/types.h>
|
|
|
|
/**
|
|
* ip_fq_node_limit - Calculate the node limit for the internal pool free queue
|
|
* @chunks: chunk count for the container
|
|
*/
|
|
u16 ip_fq_node_limit(u64 chunks)
|
|
{
|
|
u16 ret = 3 * (chunks + 751) / 1127 - 1;
|
|
|
|
if (ret == 2)
|
|
ret = 3; /* Leave room for a new root node */
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* main_fq_node_limit - Calculate the node limit for the main free queue
|
|
* @blocks: block count for the container
|
|
*/
|
|
u16 main_fq_node_limit(u64 blocks)
|
|
{
|
|
u64 blks_1gb = 0x40000;
|
|
u64 blks_4gb = 0x100000;
|
|
u16 ret;
|
|
|
|
/*
|
|
* The node limit is required to be a function of the block count.
|
|
* Inside each of the (0, 1G), [1G, 4G) and [4G, +inf) intervals, the
|
|
* function is linear.
|
|
*/
|
|
if (blocks < blks_1gb)
|
|
ret = 1 + (blocks - 1) / 4544;
|
|
else if (blocks < blks_4gb)
|
|
ret = 116 + (blocks - 261281) / 2272;
|
|
else
|
|
ret = 512;
|
|
|
|
if (ret == 2)
|
|
ret = 3; /* Leave room for a new root node */
|
|
return ret;
|
|
}
|