am a28056b3: Set VM dirty ratio to zero when UMS is active
* commit 'a28056b38275003895ff5d9576681aca01544822':
Set VM dirty ratio to zero when UMS is active
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 3b229b7..32b5679 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -57,6 +57,10 @@
mBroadcaster = NULL;
mUsbMassStorageEnabled = false;
mUsbConnected = false;
+ mUmsSharingCount = 0;
+ mSavedDirtyRatio = -1;
+ // set dirty ratio to 0 when UMS is active
+ mUmsDirtyRatio = 0;
readInitialState();
}
@@ -1064,6 +1068,21 @@
close(fd);
v->handleVolumeShared();
+ if (mUmsSharingCount++ == 0) {
+ FILE* fp;
+ mSavedDirtyRatio = -1; // in case we fail
+ if ((fp = fopen("/proc/sys/vm/dirty_ratio", "r+"))) {
+ char line[16];
+ if (fgets(line, sizeof(line), fp) && sscanf(line, "%d", &mSavedDirtyRatio)) {
+ fprintf(fp, "%d\n", mUmsDirtyRatio);
+ } else {
+ SLOGE("Failed to read dirty_ratio (%s)", strerror(errno));
+ }
+ fclose(fp);
+ } else {
+ SLOGE("Failed to open /proc/sys/vm/dirty_ratio (%s)", strerror(errno));
+ }
+ }
return 0;
}
@@ -1100,6 +1119,16 @@
close(fd);
v->handleVolumeUnshared();
+ if (--mUmsSharingCount == 0 && mSavedDirtyRatio != -1) {
+ FILE* fp;
+ if ((fp = fopen("/proc/sys/vm/dirty_ratio", "r+"))) {
+ fprintf(fp, "%d\n", mSavedDirtyRatio);
+ fclose(fp);
+ } else {
+ SLOGE("Failed to open /proc/sys/vm/dirty_ratio (%s)", strerror(errno));
+ }
+ mSavedDirtyRatio = -1;
+ }
return 0;
}
diff --git a/VolumeManager.h b/VolumeManager.h
index ffba5e6..11b5ed3 100644
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -62,6 +62,11 @@
bool mUsbConnected;
bool mDebug;
+ // for adjusting /proc/sys/vm/dirty_ratio when UMS is active
+ int mUmsSharingCount;
+ int mSavedDirtyRatio;
+ int mUmsDirtyRatio;
+
public:
virtual ~VolumeManager();