Merge "liblockfile:  Disable linear backoff for lockfile_create."
diff --git a/package/liblockfile/liblockfile-0001-Disable-lockfile_create-linear-backoff.patch b/package/liblockfile/liblockfile-0001-Disable-lockfile_create-linear-backoff.patch
new file mode 100644
index 0000000..1ca9421
--- /dev/null
+++ b/package/liblockfile/liblockfile-0001-Disable-lockfile_create-linear-backoff.patch
@@ -0,0 +1,43 @@
+From 97f0b8fdbebac3fd3398079d3db3cccb853eb0e7 Mon Sep 17 00:00:00 2001
+From: Richard Frankel <rofrankel@google.com>
+Date: Fri, 2 Dec 2016 13:46:40 -0500
+Subject: [PATCH] Disable lockfile_create linear backoff.
+
+Linear backoff causes very unfair behavior, in which the longer a
+process has been waiting, the less likely it is to grab a contested
+lock.
+
+Remove the backoff and check once per second instead.
+---
+ lockfile.c | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/lockfile.c b/lockfile.c
+index f571a67..e52f3e4 100644
+--- a/lockfile.c
++++ b/lockfile.c
+@@ -177,7 +177,7 @@ int lockfile_create(const char *lockfile, int retries, int flags)
+ 	char		sysname[256];
+ 	char		buf[8];
+ 	char		*p;
+-	int		sleeptime = 0;
++	int		sleeptime = 1;
+ 	int		statfailed = 0;
+ 	int		fd;
+ 	int		i, e, len;
+@@ -253,8 +253,10 @@ int lockfile_create(const char *lockfile, int retries, int flags)
+ 	for (i = 0; i < tries && tries > 0; i++) {
+ 
+ 		if (!dontsleep) {
+-			sleeptime += 5;
+-			if (sleeptime > 60) sleeptime = 60;
++			// GFiber modification:  Disable linear backoff, which causes very unfair
++			// behavior.
++			// sleeptime += 5;
++			// if (sleeptime > 60) sleeptime = 60;
+ #ifdef LIB
+ 			sleep(sleeptime);
+ #else
+-- 
+2.8.0.rc3.226.g39d4020
+
diff --git a/package/lockfile-progs/lockfile-progs-0001-Change-the-default-retry-count-to-180.patch b/package/lockfile-progs/lockfile-progs-0001-Change-the-default-retry-count-to-180.patch
new file mode 100644
index 0000000..b7c0a22
--- /dev/null
+++ b/package/lockfile-progs/lockfile-progs-0001-Change-the-default-retry-count-to-180.patch
@@ -0,0 +1,27 @@
+From cec6d0a707f2497165f71cfd41f505667bbd1593 Mon Sep 17 00:00:00 2001
+From: Richard Frankel <rofrankel@google.com>
+Date: Wed, 14 Dec 2016 18:23:30 -0500
+Subject: [PATCH] Change the default retry-count to 180.
+
+This maintains the default timeout of 180 seconds, now that GFiber's
+liblockfile uses constant 1s retries rather than linear backoff.
+---
+ lockfile-progs.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lockfile-progs.c b/lockfile-progs.c
+index b8f9586..d675b4e 100644
+--- a/lockfile-progs.c
++++ b/lockfile-progs.c
+@@ -30,7 +30,7 @@
+ static const char *action = NULL;
+ static char *target_file = NULL;
+ static int retry_count_specified = 0;
+-static int retry_count = 9; /* This will be a maximum of 3 minutes */
++static int retry_count = 180; /* This will be a maximum of 3 minutes */
+ static int touchlock_oneshot = 0;
+ static int use_pid = 0;
+ 
+-- 
+2.8.0.rc3.226.g39d4020
+