[Devel] [PATCH vz9 05/23] tmpfs: shmem_fallocate must return ERESTARTSYS

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Fri Oct 1 18:53:13 MSK 2021


From: Maxim Patlasov <mpatlasov at virtuozzo.com>

shmem_fallocate() is restartable, so it can return ERESTARTSYS if
signal_pending(). Although fallocate(2) manpage permits EINTR,
the more places use ERESTARTSYS the better.

https://jira.sw.ru/browse/PSBM-43399

Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
Acked-by: Dmitry Monakhov <dmonakhov at virtuozzo.com>

mpatlasov@: note, shmem_fallocate() doesn't return ERESTARTSYS to userspace.
It returns ERESTARTSYS to some internal kernel function that restarts syscall
(I tested this behavior). This is how any other "return -ERESTARTSYS;" works.

(cherry picked from vz7 commit 0011c60ac1fde1f735d2474c967b454b9019461a)
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>

(cherry-picked from vz8 commit 3eb592c3bd9b ("tmpfs: shmem_fallocate
must return ERESTARTSYS"))

Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 mm/shmem.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 4bce39662d70..6ba6b558d7c1 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2728,11 +2728,13 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
 		struct page *page;
 
 		/*
-		 * Good, the fallocate(2) manpage permits EINTR: we may have
-		 * been interrupted because we are using up too much memory.
+		 * Although fallocate(2) manpage permits EINTR, the more
+		 * places use ERESTARTSYS the better. If we have been
+		 * interrupted because we are using up too much memory,
+		 * oom-killer used fatal signal and we will die anyway.
 		 */
 		if (signal_pending(current))
-			error = -EINTR;
+			error = -ERESTARTSYS;
 		else if (shmem_falloc.nr_unswapped > shmem_falloc.nr_falloced)
 			error = -ENOMEM;
 		else
-- 
2.30.2



More information about the Devel mailing list