ummunotify: Userspace support for MMU notifications
Subsystems (3)
RFC PATCH 1/1 ummunotify: Userspace support for MMU notifications
I am resubmitting this to try and restart the discussion about how this should be implemented properly. As the dicsussion was left I see two possible solutions, one is a new class of perf event that would be setup to prioritize catching every event over resource consumption that would monitor MMU events filtered by registered address ranges. The other option is the one presented below, a character device that uses ioctl and read to register address ranges and return MMU events. I want to try and pick the best solution so I can move forward with it.
From: Roland Dreier <rolandd <at> cisco.com>
As discussed in <http://article.gmane.org/gmane.linux.drivers.openib/61925>
and follow-up messages, libraries using RDMA would like to track precisely when application code changes memory mapping via free(), munmap(), etc. Current pure-userspace solutions using malloc hooks and other tricks are not robust, and the feeling among experts is that the issue is unfixable without kernel help.
We solve this not by implementing the full API proposed in the email linked above but rather with a simpler and more generic interface, which may be useful in other contexts. Specifically, we implement a new character device driver, ummunotify, that creates a /dev/ummunotify node. A userspace process can open this node read-only and use the fd as follows:
1. ioctl() to register/unregister an address range to watch in the kernel (cf struct ummunotify_register_ioctl in <linux/ummunotify.h>).
2. read() to retrieve events generated when a mapping in a watched address range is invalidated (cf struct ummunotify_event in <linux/ummunotify.h>). select()/poll()/epoll() and SIGIO are handled for this IO.
3. mmap() one page at offset 0 to map a kernel page that contains a generation counter that is incremented each time an event is generated. This allows userspace to have a fast path that checks that no events have occurred without a system call.
Thanks to Jason Gunthorpe <jgunthorpe <at> obsidianresearch.com> for suggestions on the interface design. Also thanks to Jeff Squyres <jsquyres <at> cisco.com> for prototyping support for this in Open MPI, which helped find several bugs during development.
---
Changes since v3:
- Fixed replaced [get|put] user with copy_[from|to]_user to fix x86 builds
--- Documentation/Makefile | 3 +- drivers/char/Kconfig | 12 + drivers/char/Makefile | 1 + drivers/char/ummunotify.c | 567 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 582 insertions(+), 1 deletions(-) create mode 100644 drivers/char/ummunotify.c
Documentation/Makefile +2 -1
@@ -1,3 +1,4 @@ obj-m := DocBook/ accounting/ auxdisplay/ connector/ \ filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \ - pcmcia/ spi/ timers/ video4linux/ vm/ watchdog/src/ + pcmcia/ spi/ timers/ video4linux/ vm/ ummunotify/ \ + watchdog/src/
drivers/char/Kconfig +12 -0
@@ -1111,6 +1111,18 @@ config DEVPORT depends on ISA || PCI default y +config UMMUNOTIFY + tristate "Userspace MMU notifications" + select MMU_NOTIFIER + help + The ummunotify (userspace MMU notification) driver creates a + character device that can be used by userspace libraries to + get notifications when an application's memory mapping + changed. This is used, for example, by RDMA libraries to + improve the reliability of memory registration caching, since + the kernel's MMU notifications can be used to know precisely + when to shoot down a cached registration. + source "drivers/s390/char/Kconfig" endmenu
drivers/char/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o obj-$(CONFIG_GPIO_TB0219) += tb0219.o obj-$(CONFIG_TELCLOCK) += tlclk.o +obj-$(CONFIG_UMMUNOTIFY) += ummunotify.o obj-$(CONFIG_MWAVE) += mwave/ obj-$(CONFIG_AGP) += agp/
drivers/char/ummunotify.c new file +567 -0
567 lines not on this page · raw message
Signature · 6 lines
1.6.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · On Wed, 7 Apr 2010 13:30:29 +0100 Eric B Munson wrote:
Signed-off-by Roland Dreier <rolandd <at> cisco.com>
Use unobfuscated @.
Quoted 20 lines
Signed-off-by Eric B Munson <ebmunson-r/[email protected]>---
Changes since v3:
- Fixed replaced [get|put] user with copy_[from|to]_user to fix x86 builds--- Documentation/Makefile | 3 +- drivers/char/Kconfig | 12 + drivers/char/Makefile | 1 + drivers/char/ummunotify.c | 567 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 582 insertions(+), 1 deletions(-) create mode 100644 drivers/char/ummunotify.cDocumentation/Makefile +0
-0
Documentation/Makefile line 4
Quoted 5 lines
Documentation/Makefile +2
-1@@ -1,3 +1,4 @@ obj-m := DocBook/ accounting/ auxdisplay/ connector/ \ filesystems/ filesystems/configfs/ ia64/ laptops/ networking/ \ - pcmcia/ spi/ timers/ video4linux/ vm/ watchdog/src/ + pcmcia/ spi/ timers/ video4linux/ vm/ ummunotify/ \ + watchdog/src/
What is this change to Documentation/Makefile for?
Is there some file that should be added in Documentation/ummunotify/ ?
Quoted 28 lines
drivers/char/Kconfig +12
-0@@ -1111,6 +1111,18 @@ config DEVPORT depends on ISA || PCI default y +config UMMUNOTIFY + tristate "Userspace MMU notifications" + select MMU_NOTIFIER + help + The ummunotify (userspace MMU notification) driver creates a + character device that can be used by userspace libraries to + get notifications when an application's memory mapping + changed. This is used, for example, by RDMA libraries to + improve the reliability of memory registration caching, since + the kernel's MMU notifications can be used to know precisely + when to shoot down a cached registration. + source "drivers/s390/char/Kconfig" endmenudrivers/char/Makefile +0
-0
drivers/char/Makefile obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o · line 103
Quoted 7 lines
drivers/char/Makefile +1
-0@@ -97,6 +97,7 @@ obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o obj-$(CONFIG_GPIO_TB0219) += tb0219.o obj-$(CONFIG_TELCLOCK) += tlclk.o +obj-$(CONFIG_UMMUNOTIFY) += ummunotify.o obj-$(CONFIG_MWAVE) += mwave/ obj-$(CONFIG_AGP) += agp/
---
~Randy
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html