diff mbox

[i-g-t] lib: Do two writes to /proc/sys/vm/drop_caches again

Message ID 1474968132-16196-1-git-send-email-petri.latvala@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Petri Latvala Sept. 27, 2016, 9:22 a.m. UTC
The drop_caches sysctl has a max value of 4, so writing 7 to it just
fails. Avoid the earlier two-writes problem by opening the fd twice.

v2: Don't lseek(), open() twice. (Chris)

Signed-off-by: Petri Latvala <petri.latvala@intel.com>
---
 lib/intel_os.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Chris Wilson Sept. 27, 2016, 9:41 a.m. UTC | #1
On Tue, Sep 27, 2016 at 12:22:12PM +0300, Petri Latvala wrote:
> The drop_caches sysctl has a max value of 4, so writing 7 to it just
> fails. Avoid the earlier two-writes problem by opening the fd twice.
> 
> v2: Don't lseek(), open() twice. (Chris)
> 
> Signed-off-by: Petri Latvala <petri.latvala@intel.com>

Thanks, pushed. The sysctl being a bitmask and not accepting the full
range is a bit surprising.
-Chris
diff mbox

Patch

diff --git a/lib/intel_os.c b/lib/intel_os.c
index b9f970d..e448bb4 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -299,11 +299,20 @@  void intel_purge_vm_caches(void)
 	if (fd < 0)
 		return;
 
+	/* BIT(2): Be quiet. Cannot be combined with other operations,
+	 * the sysctl has a max value of 4.
+	 */
+	igt_ignore_warn(write(fd, "4\n", 2));
+	close(fd);
+
+	fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
+	if (fd < 0)
+		return;
+
 	/* BIT(0): Drop page cache
 	 * BIT(1): Drop slab cache
-	 * BIT(2): Be quiet in future
 	 */
-	igt_ignore_warn(write(fd, "7\n", 2));
+	igt_ignore_warn(write(fd, "3\n", 2));
 	close(fd);
 }