/proc/sys/vm/drop_caches should be able to be configured to allow regular user writes

Bug #71575 reported by Robert Collins
2
Affects Status Importance Assigned to Milestone
linux-source-2.6.19 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

/proc/sys/vm/drop_caches is a fantastic performance testing tool. It would be great to be able to cause a cache drop as a regular user when desired. I can imagine a setuid program to do it, or (better) just having it honour the mode on the file - chmod works, but after a chmod, you still cannot write to it as a regular user.

Revision history for this message
Ben Collins (ben-collins) wrote :

If you are setuid root, then you should be able to write to this file. It is mode 0644, and that is the only thing deciding the perms for it.

Can you provide a sample program that shows the problem?

Changed in linux-source-2.6.19:
status: Unconfirmed → Needs Info
Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 71575] Re: /proc/sys/vm/drop_caches should be able to be configured to allow regular user writes

On Wed, 2006-11-15 at 02:34 +0000, Ben Collins wrote:
> or it.
>
> Can you provide a sample program that shows the problem?

I tried
$ echo 1 > /proc/sys/vm/drop_caches
bash: /proc/sys/vm/drop_caches: Permission denied
$ sudo chmod 0666 /proc/sys/vm/drop_caches
$ echo 1 > /proc/sys/vm/drop_caches
bash: echo: write error: Operation not permitted
$ sudo chmod 0666 /proc/sys/vm/drop_caches
$ ls -ld /proc/sys/vm/drop_caches
-rw-rw-rw- 1 root root 0 2006-11-16 08:52 /proc/sys/vm/drop_caches
$ ls -ld /proc/sys/vm
dr-xr-xr-x 2 root root 0 2006-11-16 08:52 /proc/sys/vm
$ echo 1 > /proc/sys/vm/drop_caches
bash: echo: write error: Operation not permitted
$

So the mode does not seem to be sufficient :(.

-Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.

Revision history for this message
Ben Collins (ben-collins) wrote :

You need root, or CAP_ADMIN. Not really going to make it so you can write to it as normal user, since either of the other options is just as simple.

Changed in linux-source-2.6.19:
status: Needs Info → Rejected
Revision history for this message
Robert Collins (lifeless) wrote :

On Mon, 2006-11-20 at 01:00 +0000, Ben Collins wrote:
> You need root, or CAP_ADMIN. Not really going to make it so you can
> write to it as normal user, since either of the other options is just as
> simple.

Sorry, I dont quite get that.

My use case is not that a normal user can do it adhoc, but that it can
be configured to be done via a normal user.

I presume that by 'other options' you mean CAP_ADMIN/root - neither of
which are appropriate for running performance test suites, which is why
I am asking for this.

I can completely understand that this isn't something you're interested
in fixing yourself, but if you throw me a vague pointer at the relevant
code I can look into it, or can we mark it upstream [I'm disagreeing
that this is an invalid request] ?

Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.

Revision history for this message
Ben Collins (ben-collins) wrote : Re: [Bug 71575] Re: /proc/sys/vm/drop_caches should be able to be configured to allow regular user writes

On Mon, 2006-11-20 at 01:19 +0000, Robert Collins wrote:
> On Mon, 2006-11-20 at 01:00 +0000, Ben Collins wrote:
> > You need root, or CAP_ADMIN. Not really going to make it so you can
> > write to it as normal user, since either of the other options is just as
> > simple.
>
> Sorry, I dont quite get that.
>
> My use case is not that a normal user can do it adhoc, but that it can
> be configured to be done via a normal user.
>
> I presume that by 'other options' you mean CAP_ADMIN/root - neither of
> which are appropriate for running performance test suites, which is why
> I am asking for this.
>
> I can completely understand that this isn't something you're interested
> in fixing yourself, but if you throw me a vague pointer at the relevant
> code I can look into it, or can we mark it upstream [I'm disagreeing
> that this is an invalid request] ?

This is really a question you should be posing to linux-kernel. Saying
that "performance testing shouldn't require root" is somewhat not true,
especially in cases where you are causing cache misses. You need special
perms, you need to setup the system to do it, no matter what your
choices.

So either you chmod the file (if the kernel were patched to recognize
that), or you create a special program setuid root.

I'm not sure why the perms seem easier to you, but this small program,
compiled and setuid root does it without worrying about the kernel you
are running the tests on:

int main()
{
        int fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
        write(fd, "1\n", 2);
        close(fd);
}

This isn't a matter of whether I want to fix it, it's a matter of I
can't see the need, and I've no idea if there's a reason for the way it
is. Best suggestion I can give is to use the program mentioned, or start
a discussion about it on the linux-kernel mailing list where people more
advised than I can discuss it.

Revision history for this message
Piyush Garyali (piyush-garyali) wrote :

Just curious, did you try

echo 1 | sudo tee /proc/sys/vm/drop_caches

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.