History

mm: userfaultfd: add feature to request for a signal delivery

In some cases, userfaultfd mechanism should just deliver a SIGBUS signal to the faulting process, instead of the page-fault event. Dealing with page-fault event using a monitor thread can be an overhead in these cases. For example applications like the database could use the signaling mechanism for robustness purpose. Database uses hugetlbfs for performance reason. Files on hugetlbfs filesystem are created and huge pages allocated using fallocate() API. Pages are deallocated/freed using fallocate() hole punching support. These files are mmapped and accessed by many processes as shared memory. The database keeps track of which offsets in the hugetlbfs file have pages allocated. Any access to mapped address over holes in the file, which can occur due to bugs in the application, is considered invalid and expect the process to simply receive a SIGBUS. However, currently when a hole in the file is accessed via the mapped address, kernel/mm attempts to automatically allocate a page at page fault time, resulting in implicitly filling the hole in the file. This may not be the desired behavior for applications like the database that want to explicitly manage page allocations of hugetlbfs files. Using userfaultfd mechanism with this support to get a signal, database application can prevent pages from being allocated implicitly when processes access mapped address over holes in the file. This patch adds UFFD_FEATURE_SIGBUS feature to userfaultfd mechnism to request for a SIGBUS signal. See following for previous discussion about the database requirement leading to this proposal as suggested by Andrea. http://www.spinics.net/lists/linux-mm/msg129224.html

Prakash Sangappa committed 9 years ago

Commit 2d6d6f51 parent c41f0122 files · +12 −1Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/userfaultfd.h+9−1
@@ -23,7 +23,8 @@ · 22 unmodified lines
23 UFFD_FEATURE_EVENT_REMOVE | \23 UFFD_FEATURE_EVENT_REMOVE | \
24 UFFD_FEATURE_EVENT_UNMAP | \24 UFFD_FEATURE_EVENT_UNMAP | \
25 UFFD_FEATURE_MISSING_HUGETLBFS | \25 UFFD_FEATURE_MISSING_HUGETLBFS | \
26 UFFD_FEATURE_MISSING_SHMEM)26 UFFD_FEATURE_MISSING_SHMEM | \
27 UFFD_FEATURE_SIGBUS)
27#define UFFD_API_IOCTLS \28#define UFFD_API_IOCTLS \
28 ((__u64)1 << _UFFDIO_REGISTER | \29 ((__u64)1 << _UFFDIO_REGISTER | \
29 (__u64)1 << _UFFDIO_UNREGISTER | \30 (__u64)1 << _UFFDIO_UNREGISTER | \
@@ -153,6 +154,12 @@ struct uffdio_api { · 123 unmodified lines
153 * UFFD_FEATURE_MISSING_SHMEM works the same as154 * UFFD_FEATURE_MISSING_SHMEM works the same as
154 * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem155 * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem
155 * (i.e. tmpfs and other shmem based APIs).156 * (i.e. tmpfs and other shmem based APIs).
157 *
158 * UFFD_FEATURE_SIGBUS feature means no page-fault
159 * (UFFD_EVENT_PAGEFAULT) event will be delivered, instead
160 * a SIGBUS signal will be sent to the faulting process.
161 * The application process can enable this behavior by adding
162 * it to uffdio_api.features.
156 */163 */
157#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)164#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
158#define UFFD_FEATURE_EVENT_FORK (1<<1)165#define UFFD_FEATURE_EVENT_FORK (1<<1)
@@ -161,6 +168,7 @@ struct uffdio_api { · 2 unmodified lines
161#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)168#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
162#define UFFD_FEATURE_MISSING_SHMEM (1<<5)169#define UFFD_FEATURE_MISSING_SHMEM (1<<5)
163#define UFFD_FEATURE_EVENT_UNMAP (1<<6)170#define UFFD_FEATURE_EVENT_UNMAP (1<<6)
171#define UFFD_FEATURE_SIGBUS (1<<7)
164 __u64 features;172 __u64 features;
165 173
166 __u64 ioctls;174 __u64 ioctls;