On 01/03/2024 12:42 pm, Roger Pau Monne wrote:
> The current usage of a cmpxchg loop to increase the value of page count is not
> optimal on amd64, as there's already an instruction to do an atomic add to a
> 64bit integer.
>
> Switch the code in get_page_light() to use an atomic increment, as that avoids
> a loop construct.  This slightly changes the order of the checks, as current
> code will crash before modifying the page count_info if the conditions are not
> correct, while with the proposed change the crash will happen immediately
> after having carried the counter increase.  Since we are crashing anyway, I
> don't believe the re-ordering to have any meaningful impact.
>
> Note that the page must already have a non-zero reference count which prevents
> the flags from changing, and the previous usage of the cmpxchg loop didn't
> guarantee that the rest of the fields in count_info didn't change while
> updating the reference count.
>
> Signed-off-by: Roger Pau MonnĂ© <[email protected]>

Reviewed-by: Andrew Cooper <[email protected]>

I think the minor new corner case is well worth the simplification this
change provides.

Reply via email to