All of lore.kernel.org
 help / color / mirror / Atom feed
From: kusumi.tomohiro@gmail.com
To: axboe@kernel.dk, fio@vger.kernel.org
Cc: Tomohiro Kusumi <tkusumi@tuxera.com>
Subject: [PATCH 01/17] Add runtime handlers for 97900ebf for FreeBSD/DragonFlyBSD
Date: Tue,  7 Mar 2017 22:12:52 +0200	[thread overview]
Message-ID: <20170307201308.66814-2-tkusumi@tuxera.com> (raw)
In-Reply-To: <20170307201308.66814-1-tkusumi@tuxera.com>

From: Tomohiro Kusumi <tkusumi@tuxera.com>

As 97900ebf itself explains, this is a runtime tunable on FreeBSD
and DragonFlyBSD, so they need to check the sysctl on runtime.

Not sure if OpenBSD has any tunable for this as the original commit
only says about >=5.1, but afaik recent versions of OpenBSD can't
even compile fio anyway. Also not sure how it works on NetBSD, and
the original commit said nothing about it too. Also see below url.

http://www.spinics.net/lists/fio/msg05586.html
http://www.spinics.net/lists/fio/msg05588.html

--
 # uname -r
 11.0-RELEASE-p1
 # cat ./test1.c
 #include <stdio.h>
 #include "./os/os-freebsd.h"
 int main(void) {
         printf("%d\n", shm_attach_to_open_removed());
         return 0;
 }
 # clang -Wall -g ./test1.c
 # sysctl kern.ipc.shm_allow_removed
 kern.ipc.shm_allow_removed: 1
 # ./a.out
 1
 # sysctl kern.ipc.shm_allow_removed=123
 kern.ipc.shm_allow_removed: 1 -> 123
 # ./a.out
 1
 # sysctl kern.ipc.shm_allow_removed=0
 kern.ipc.shm_allow_removed: 123 -> 0
 # ./a.out
 0

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
---
 init.c            |  5 ++---
 os/os-dragonfly.h | 14 ++++++++++++--
 os/os-freebsd.h   | 15 ++++++++++++---
 os/os-linux.h     |  5 +++++
 os/os-openbsd.h   | 12 +++++++++---
 os/os.h           |  7 +++++++
 6 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/init.c b/init.c
index fabc887..acdc659 100644
--- a/init.c
+++ b/init.c
@@ -356,9 +356,8 @@ static int setup_thread_area(void)
 		perror("shmat");
 		return 1;
 	}
-#ifdef FIO_HAVE_SHM_ATTACH_REMOVED
-	shmctl(shm_id, IPC_RMID, NULL);
-#endif
+	if (shm_attach_to_open_removed())
+		shmctl(shm_id, IPC_RMID, NULL);
 #endif
 
 	memset(threads, 0, max_jobs * sizeof(struct thread_data));
diff --git a/os/os-dragonfly.h b/os/os-dragonfly.h
index 5e94855..97452ca 100644
--- a/os/os-dragonfly.h
+++ b/os/os-dragonfly.h
@@ -24,8 +24,7 @@
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CPU_AFFINITY
 #define FIO_HAVE_IOPRIO
-/* Only have attach-to-open-removed when kern.ipc.shm_allow_removed is 1 */
-#undef  FIO_HAVE_SHM_ATTACH_REMOVED
+#define FIO_HAVE_SHM_ATTACH_REMOVED
 
 #define OS_MAP_ANON		MAP_ANON
 
@@ -234,4 +233,15 @@ static inline int os_trim(int fd, unsigned long long start,
 #define FIO_MADV_FREE	MADV_FREE
 #endif
 
+static inline int shm_attach_to_open_removed(void)
+{
+	int x;
+	size_t len = sizeof(x);
+
+	if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0)
+		return 0;
+
+	return x > 0 ? 1 : 0;
+}
+
 #endif
diff --git a/os/os-freebsd.h b/os/os-freebsd.h
index aa90954..9d1af3b 100644
--- a/os/os-freebsd.h
+++ b/os/os-freebsd.h
@@ -22,9 +22,7 @@
 #define FIO_HAVE_TRIM
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CPU_AFFINITY
-/* Only have attach-to-open-removed when kern.ipc.shm_allow_removed is 1 */
-#undef  FIO_HAVE_SHM_ATTACH_REMOVED
-
+#define FIO_HAVE_SHM_ATTACH_REMOVED
 
 #define OS_MAP_ANON		MAP_ANON
 
@@ -136,4 +134,15 @@ static inline int os_trim(int fd, unsigned long long start,
 #define FIO_MADV_FREE	MADV_FREE
 #endif
 
+static inline int shm_attach_to_open_removed(void)
+{
+	int x;
+	size_t len = sizeof(x);
+
+	if (sysctlbyname("kern.ipc.shm_allow_removed", &x, &len, NULL, 0) < 0)
+		return 0;
+
+	return x > 0 ? 1 : 0;
+}
+
 #endif
diff --git a/os/os-linux.h b/os/os-linux.h
index 1829829..7be833b 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -350,4 +350,9 @@ static inline ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt,
 #endif /* __NR_preadv2 */
 #endif /* CONFIG_PWRITEV2 */
 
+static inline int shm_attach_to_open_removed(void)
+{
+	return 1;
+}
+
 #endif
diff --git a/os/os-openbsd.h b/os/os-openbsd.h
index 4700572..3b19483 100644
--- a/os/os-openbsd.h
+++ b/os/os-openbsd.h
@@ -22,12 +22,10 @@
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 #define FIO_HAVE_FS_STAT
 #define FIO_HAVE_GETTID
+#define FIO_HAVE_SHM_ATTACH_REMOVED
 
 #undef	FIO_HAVE_CPU_AFFINITY	/* XXX notyet */
 
-/* Only OpenBSD 5.1 and above have attach-to-open-removed semantics */
-#undef  FIO_HAVE_SHM_ATTACH_REMOVED
-
 #define OS_MAP_ANON		MAP_ANON
 
 #ifndef PTHREAD_STACK_MIN
@@ -90,4 +88,12 @@ static inline unsigned long long get_fs_free_size(const char *path)
 #define FIO_MADV_FREE	MADV_FREE
 #endif
 
+static inline int shm_attach_to_open_removed(void)
+{
+	/*
+	 * XXX: Return 1 if >= OpenBSD 5.1 according to 97900ebf.
+	 */
+	return 0;
+}
+
 #endif
diff --git a/os/os.h b/os/os.h
index 4178e6f..5e3c813 100644
--- a/os/os.h
+++ b/os/os.h
@@ -386,4 +386,11 @@ static inline int gettid(void)
 }
 #endif
 
+#ifndef FIO_HAVE_SHM_ATTACH_REMOVED
+static inline int shm_attach_to_open_removed(void)
+{
+	return 0;
+}
+#endif
+
 #endif
-- 
2.9.3



  reply	other threads:[~2017-03-07 20:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-07 20:12 [PATCH 00/17] kusumi.tomohiro
2017-03-07 20:12 ` kusumi.tomohiro [this message]
2017-03-07 20:12 ` [PATCH 02/17] HOWTO: Add platforms without fdatasync(2) kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 03/17] configure: Align help messages kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 04/17] Avoid irrelevant "offset extend ends" error message for chrdev kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 05/17] Fix debug print format of file ->file_name kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 06/17] Fixup for a minor 0 byte file size case kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 07/17] Explicitly check td_trim(td) to detect open(2) flag kusumi.tomohiro
2017-03-07 20:12 ` [PATCH 08/17] Drop redundant td_rw(td) tests kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 09/17] Remove unassigned fio_unused variable kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 10/17] Drop fio_unused attribute from used variable kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 11/17] Fix a function name typo in debug print kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 12/17] Don't set FIO_FILE_extend when create_on_open= option is set kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 13/17] Minor fixup for "Layint out IO file..." message kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 14/17] HOWTO: Add some details for invalidate= kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 15/17] Define struct file_name as a file local structure kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 16/17] Use union for per file engine private data storage kusumi.tomohiro
2017-03-07 20:13 ` [PATCH 17/17] configure: Make Cygwin take regular configure path kusumi.tomohiro
2017-03-10 21:44 ` [PATCH 00/17] Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170307201308.66814-2-tkusumi@tuxera.com \
    --to=kusumi.tomohiro@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    --cc=tkusumi@tuxera.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.