btrfs: speed up btrfs_set_token_##bits helpers
authorDavid Sterba <dsterba@suse.com>
Wed, 29 Apr 2020 16:23:37 +0000 (18:23 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 May 2020 09:25:33 +0000 (11:25 +0200)
commitce7afe8782a5293edbf4bc2165ac4a866ed430db
tree5891f656bde8d96312a3bf540c58914f5eec0e9b
parent029e4a42a2b22f3c82e5b325820219963aa3f13b
btrfs: speed up btrfs_set_token_##bits helpers

The set/get token helpers either use the cached address in the token or
unconditionally call map_private_extent_buffer to get the address of
page containing the requested offset plus the mapping start and length.
Depending on the return value, the fast path uses unaligned put to write
data within a page, or fall back to write_extent_buffer that can handle
writes spanning more pages.

This is all wasteful. We know the number of bytes to write, 1/2/4/8 and
can find out the page. Then simply check if it's contained or the
fallback is needed. The token address is updated to the page, or the on
the next index, expecting that the next write will use that.

This saves one function call to map_private_extent_buffer and several
unnecessary temporary variables.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/struct-funcs.c