0

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file? If so, then how?

Reason: need to constantly perform mentioned operations on many files. Will these operations be completed faster if the files will have a certain permissions? For example, "read only" permission.

1
  • having slept over this: this sounds rather interesting. Mind telling us in which context the question arose? Jun 13, 2021 at 9:39

2 Answers 2

3

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file? If so, then how?

Only in that the operation will be denied (and therefore could be considered to take infinite time) if the permissions prevent the operation.

Aside from that extreme edge case, permissions will have no effect on the speed of any copy/move/remove operation.


I've been asked to validate my statement, which is a perfectly acceptable thing for someone to do. Here's my reasoning for my answer. (And apologies if I've poorly quoted/interpreted the challenge; it's not my intention to sidestep.)

What if you have a ton of ACL's for each of millions of small files? Parsing permissions in this case may take more time than actually reading these files from a disk (i.e. PCI-E gen4 SSD). Do you have access to PCI-E gen 4 NVMe drives which often have read speeds up to 10GB/sec?

I cannot find a quantitative maximum on the number of ACLs per file. However, there was some research done on this, with a downloadable script. In the researcher's testing there were around 500 ACLs per file. In my testing I hit the limit at 252 ACLs for an ext4 filesystem on Raspbian. (We're not considering speeds, just limits.)

At this size they're either going to be packed in the inode's block or at most one block away. That's one extra block to read and parse. Really small files can be stored in an ext4 inode, so there's no extra data block to read. With an NVMe drive the read time for an extra ACLs block per file is going to be minimal, and parsing 250 or so ACL entries is not going to be stunningly computationally hard. And that's assuming really small files that don't need extra blocks.

Empirical? Sure. Practical? I believe so.

8
  • I don't know. What if you have a ton of ACL's for each of millions of small files? Parsing permissions in this case may take more time than actually reading these files from a disk (i.e. PCI-E gen4 SSD). I wouldn't be so bloody sure. What if we're talking about files located on a remote PC where the remote system is managing permissions? Jun 12, 2021 at 15:18
  • @ArtemS.Tashkinov there's a maximum of around 500 ACLs per file. I don't see that as significant but I'll add it to my answer if it would be useful Jun 12, 2021 at 15:21
  • Without test data we are rending the air. Do you have access to PCI-E gen 4 NVMe drives which often have read speeds up to 10GB/sec? It's unlikely anyone will have that many ACLs per file but I've seen very weird things in my life :-) Jun 12, 2021 at 15:25
  • 1
    No. I'm using O(n) maths here and some testing. Here on an ext4 filesystem I've just found a practical limit of 252 ACLs on a file (half the number found in the tests I linked). At this size they're either going to be packed in the inode's block or at most one block away. That's one extra block to read and parse. Really small files can be stored in an ext4 inode, so there's no extra data. You're considering an NVMe drive. The read time on that for an extra block per file is minimal. And that's assuming really small files that don't need extra blocks. I stand by my answer. Regards. Jun 12, 2021 at 15:42
  • 1
    @ilkkachu thank you for the reference. I couldn't find anything, which is why I'd resorted to empirical measures. (I didn't have either btrfs or xfs to hand.) Jun 12, 2021 at 20:51
1

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file? If so, then how?

Speed is something that is wholly defined by the file system: For example, a move within the same file system will only be changing entries in the file system data structures and hence doesn't touch the actual file contents. Therefore, the time this takes will be dominated by the time it takes for your system to switch from your program to the kernel to do that, and the complexity of operations on these data structures.

That complexity should be the same, no matter the permissions. But: there's more to permissions than read/write/execute for owner,group,others; there's ACLs and xattrs, too, and that can get more complex in special cases. But these very likely don't matter to you at all.

The only case where permissions might matter is if concurrent access to the file needs to be coordinated (e.g. on a network file system mounted via NFS), but even then I've yet to see such a difference.

So, now, normally, things are "fast", full stop. The point that you're asking this, but do not even mention the actual file system you're using probably means you're worrying about the wrong things. It's very likely you can find differences between your file systems. For example, if you're often copying files, then using a file system that knows multiply-referenced extents will greatly speed up things. Currently, under Linux, there's only two choices there: XFS and btrfs. But even between these two, you'll find measurable speed differences when doing a lot of operations (say, upwards of 10000 per second). I tend towards XFS, but do your own benchmarking; with LVM it's really trivial to make and destroy file systems just for the heck of it.

The fact that you're using the tags , , and , however, might mean that you're equating the time it takes the shell tools of the same names to finish. And that's a very different problem: Calling /usr/bin/rm¹ takes way, way, way longer than the actual deletion of that file. If you're seeing this bottleneck from a shell script, or from some language where you explicitly have to call these tools to modify the file system, it's quite possible that your process creation is your bottleneck - and not your file operations themselves.


¹ that is, forking the starting process, execve("/usr/bin/rm") in the fork, Linux loading the program into RAM, allocating memory for the process the dynamic linker trying to open about 20 libraries, then actually loading one, allocating way more memory, doing a lot of file properties, opening stdout and stderr... then closing all this again, before actually unlinking the file... that's 100× the effort of the actual deletion request (that unlink).

1
  • Thanks for the detailed answer. Including the footnote.
    – pmor
    Jun 12, 2021 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .