Re: [PATCH v2 06/12] mm, swap: implement helpers for reserving data in the swap table
From: YoungJun Park
Date: Thu Jan 29 2026 - 02:44:07 EST
On Wed, Jan 28, 2026 at 05:28:30PM +0800, Kairui Song wrote:
> From: Kairui Song <kasong@xxxxxxxxxxx>
> +static inline bool swp_tb_is_countable(unsigned long swp_tb)
> +{
> + return (swp_tb_is_shadow(swp_tb) || swp_tb_is_folio(swp_tb) ||
> + swp_tb_is_null(swp_tb));
> +}
What do you think about simplifying swp_tb_is_countable by just checking
!swp_tb_is_bad(swp_tb)?
Since this function appears to be called frequently, reducing the number of
comparisons would be beneficial for performance. If validation is
necessary for debugging perhaps we could introduce a separate version for debugging
purposes.
> +static inline int swp_tb_get_count(unsigned long swp_tb)
> +{
> + if (swp_tb_is_countable(swp_tb))
> + return __swp_tb_get_count(swp_tb);
> + return -EINVAL;
> }
Or, could we simply drop the check in swp_tb_get_count and call
__swp_tb_get_count directly?
If we define SWP_TB_BAD to have 0 in the count bits (MSB), it will
naturally yield a count of 0.
Thanks!
Youngjun Park