evm: stop avoidably reading i_writecount in evm_file_release
Subsystems (4)
PATCH 1/1 evm: stop avoidably reading i_writecount in evm_file_release
The EVM_NEW_FILE flag is unset if the file already existed at the time of open and this can be checked without looking at i_writecount.
Not accessing it reduces traffic on the cacheline during parallel open of the same file and drop the evm_file_release routine from second place to bottom of the profile.
---
The context is that I'm writing a patch which removes one lockref get/put cycle on parallel open. An operational WIP reduces ping-pong in that area and made do_dentry_open skyrocket along with evm_file_release, due to i_writecount access. With the patch they go down again and apparmor takes the rightful first place.
The patch accounts for about 5% speed up at 20 cores running open3 from will-it-scale on top of the above wip. (the apparmor + lockref thing really don't scale, that's next)
I would provide better measurements, but the wip is not ready (as the description suggests) and I need evm out of the way for the actual patch.
security/integrity/evm/evm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/integrity/evm/evm_main.c +2 -1
@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)if (!S_ISREG (inode->i_mode) || !(mode &FMODE_WRITE ))return ; -if (iint &&atomic_read (&inode->i_writecount) ==1 ) +if (iint && iint->flags &EVM_NEW_FILE && +atomic_read (&inode->i_writecount) ==1 ) iint->flags &= ~EVM_NEW_FILE ; }
Signature · 1 line
2.43.0
Quoted 2 lines · Mateusz Guzik
The
EVM_NEW_FILEflag is unset if the file already existed at the time of open and this can be checked without looking ati_writecount.
Agreed. EVM_NEW_FILE is not going to be set during the open(), only before, in evm_post_path_mknod().
Looks good to me.
Thanks
Roberto
Quoted 38 lines
Not accessing it reduces traffic on the cacheline during parallel open of the same file and drop the
evm_file_releaseroutine from second place to bottom of the profile.Signed-off-by Mateusz Guzik <[email protected]>---
The context is that I'm writing a patch which removes one lockref get/put cycle on parallel open. An operational WIP reduces ping-pong in that area and made
do_dentry_openskyrocket along withevm_file_release, due toi_writecountaccess. With the patch they go down again and apparmor takes the rightful first place.The patch accounts for about 5% speed up at 20 cores running open3 from will-it-scale on top of the above wip. (the apparmor + lockref thing really don't scale, that's next)
I would provide better measurements, but the wip is not ready (as the description suggests) and I need evm out of the way for the actual patch.
security/integrity/evm/evm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)security/integrity/evm/evm_main.c +2
-1@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)if (!S_ISREG (inode->i_mode) || !(mode &FMODE_WRITE ))return ; -if (iint &&atomic_read (&inode->i_writecount) ==1 ) +if (iint && iint->flags &EVM_NEW_FILE && +atomic_read (&inode->i_writecount) ==1 ) iint->flags &= ~EVM_NEW_FILE ; }
Quoted 5 lines · Roberto Sassu
Quoted 2 lines · Mateusz Guzik
The
EVM_NEW_FILEflag is unset if the file already existed at the time of open and this can be checked without looking ati_writecount.
Quoted 8 lines
Agreed.
EVM_NEW_FILEis not going to be set during theopen(), only before, inevm_post_path_mknod().Looks good to me.
Reviewed-by Roberto Sassu <[email protected]>Thanks
thanks for the review
are there plans to pick this up for this merge window?
Quoted 42 lines
Roberto
Quoted 38 lines
Not accessing it reduces traffic on the cacheline during parallel open of the same file and drop the
evm_file_releaseroutine from second place to bottom of the profile.Signed-off-by Mateusz Guzik <[email protected]>---
The context is that I'm writing a patch which removes one lockref get/put cycle on parallel open. An operational WIP reduces ping-pong in that area and made
do_dentry_openskyrocket along withevm_file_release, due toi_writecountaccess. With the patch they go down again and apparmor takes the rightful first place.The patch accounts for about 5% speed up at 20 cores running open3 from will-it-scale on top of the above wip. (the apparmor + lockref thing really don't scale, that's next)
I would provide better measurements, but the wip is not ready (as the description suggests) and I need evm out of the way for the actual patch.
security/integrity/evm/evm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)security/integrity/evm/evm_main.c +2
-1@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)if (!S_ISREG (inode->i_mode) || !(mode &FMODE_WRITE ))return ; -if (iint &&atomic_read (&inode->i_writecount) ==1 ) +if (iint && iint->flags &EVM_NEW_FILE && +atomic_read (&inode->i_writecount) ==1 ) iint->flags &= ~EVM_NEW_FILE ; }
Signature · 1 line
Mateusz Guzik <mjguzik gmail.com>
Quoted 12 lines · Mateusz Guzik
Quoted 10 lines · Roberto Sassu
Quoted 2 lines · Mateusz Guzik
The
EVM_NEW_FILEflag is unset if the file already existed at the time of open and this can be checked without looking ati_writecount.Agreed.
EVM_NEW_FILEis not going to be set during theopen(), only before, inevm_post_path_mknod().Looks good to me.
Quoted 7 lines
Quoted 3 lines
Reviewed-by Roberto Sassu <[email protected]>Thanks
thanks for the review
are there plans to pick this up for this merge window?
Welcome! Sorry, Mimi wants to do few more checks. It is more likely that we will pick this for the next version.
Roberto
Quoted 44 lines
Quoted 42 lines
Roberto
Quoted 38 lines
Not accessing it reduces traffic on the cacheline during parallel open of the same file and drop the
evm_file_releaseroutine from second place to bottom of the profile.Signed-off-by Mateusz Guzik <[email protected]>---
The context is that I'm writing a patch which removes one lockref get/put cycle on parallel open. An operational WIP reduces ping-pong in that area and made
do_dentry_openskyrocket along withevm_file_release, due toi_writecountaccess. With the patch they go down again and apparmor takes the rightful first place.The patch accounts for about 5% speed up at 20 cores running open3 from will-it-scale on top of the above wip. (the apparmor + lockref thing really don't scale, that's next)
I would provide better measurements, but the wip is not ready (as the description suggests) and I need evm out of the way for the actual patch.
security/integrity/evm/evm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)security/integrity/evm/evm_main.c +2
-1@@ -1084,7 +1084,8 @@ static void evm_file_release(struct file *file)if (!S_ISREG (inode->i_mode) || !(mode &FMODE_WRITE ))return ; -if (iint &&atomic_read (&inode->i_writecount) ==1 ) +if (iint && iint->flags &EVM_NEW_FILE && +atomic_read (&inode->i_writecount) ==1 ) iint->flags &= ~EVM_NEW_FILE ; }
Mimi Zohar
maintainerQuoted 8 lines · Mateusz Guzik
The
EVM_NEW_FILEflag is unset if the file already existed at the time of open and this can be checked without looking ati_writecount.Not accessing it reduces traffic on the cacheline during parallel open of the same file and drop the
evm_file_releaseroutine from second place to bottom of the profile.Signed-off-by Mateusz Guzik <[email protected]>
Sorry for the delay. It's now queued in next-integrity.
thanks,
Mimi