Skip to content

Commit

Permalink
3.12 compat, 4.0 compat for super_operations shrinker callbacks
Browse files Browse the repository at this point in the history
3.12 API change - A node ID argument was added to the nr_cached_objects
and free_cached_objects callbacks in struct super_operations.

4.0 API change - The node ID and nr_to_scan arguments to the
nr_cached_objects and free_cached_objects callbacks in struct
super_operations were replaced with a single struct shrink_control
argument.

Also, the return value from each callback should be long.
  • Loading branch information
Tim Chase authored and dweeezil committed Apr 19, 2015
1 parent e23f2b5 commit 445ba57
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 14 deletions.
110 changes: 101 additions & 9 deletions config/kernel-shrink.m4
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,48 @@ AC_DEFUN([ZFS_AC_KERNEL_NR_CACHED_OBJECTS], [
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
int nr_cached_objects(struct super_block *sb) { return 0; }
static const struct super_operations so;
static const unsigned u = sizeof (so.nr_cached_objects);
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_NR_CACHED_OBJECTS, 1,
[sops->nr_cached_objects() exists])
],[
AC_MSG_RESULT(no)
])
])

AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS], [
AC_MSG_CHECKING([whether sops->free_cached_objects() exists])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
static const struct super_operations so;
static const unsigned u = sizeof (so.free_cached_objects);
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_FREE_CACHED_OBJECTS, 1,
[sops->free_cached_objects() exists])
],[
AC_MSG_RESULT(no)
])
])


dnl #
dnl # 3.12 API change
dnl #
dnl # A node ID argument was added to the nr_cached_objects and
dnl # free_cached_objects callbacks in struct super_operations.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_NR_CACHED_OBJECTS_HAS_NID], [
AC_MSG_CHECKING([whether sops->nr_cached_objects() has nid argument])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
long nr_cached_objects(struct super_block *sb, int nid) { return 0; }
static const struct super_operations
sops __attribute__ ((unused)) = {
Expand All @@ -81,20 +122,20 @@ AC_DEFUN([ZFS_AC_KERNEL_NR_CACHED_OBJECTS], [
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_NR_CACHED_OBJECTS, 1,
[sops->nr_cached_objects() exists])
AC_DEFINE(NR_CACHED_OBJECTS_HAS_NID, 1,
[sops->nr_cached_objects() has nid argument])
],[
AC_MSG_RESULT(no)
])
])

AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS], [
AC_MSG_CHECKING([whether sops->free_cached_objects() exists])
AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS_HAS_NID], [
AC_MSG_CHECKING([whether sops->free_cached_objects() has nid argument])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
void free_cached_objects(struct super_block *sb, int x)
{ return; }
long free_cached_objects(struct super_block *sb, long nr_to_scan,
int nid) { return 0; }
static const struct super_operations
sops __attribute__ ((unused)) = {
Expand All @@ -103,8 +144,59 @@ AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS], [
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_FREE_CACHED_OBJECTS, 1,
[sops->free_cached_objects() exists])
AC_DEFINE(FREE_CACHED_OBJECTS_HAS_NID, 1,
[sops->free_cached_objects() has nid argument])
],[
AC_MSG_RESULT(no)
])
])

dnl #
dnl # 4.0 API change
dnl #
dnl # The node ID and nr_to_scan arguments to the nr_cached_objects and
dnl # free_cached_objects callbacks in struct super_operations were replaced
dnl # with a single struct shrink_control argument.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_NR_CACHED_OBJECTS_HAS_SC], [
AC_MSG_CHECKING([whether sops->nr_cached_objects() has shrink_control argument])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
long nr_cached_objects(struct super_block *sb,
struct shrink_control sc) { return 0; }
static const struct super_operations
sops __attribute__ ((unused)) = {
.nr_cached_objects = nr_cached_objects,
};
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(NR_CACHED_OBJECTS_HAS_SC, 1,
[sops->nr_cached_objects() has shrink_control argument])
],[
AC_MSG_RESULT(no)
])
])

AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS_HAS_SC], [
AC_MSG_CHECKING([whether sops->free_cached_objects() has shrink_control argument])
ZFS_LINUX_TRY_COMPILE([
#include <linux/fs.h>
long free_cached_objects(struct super_block *sb,
struct shrink_control sc) { return 0; }
static const struct super_operations
sops __attribute__ ((unused)) = {
.free_cached_objects = free_cached_objects,
};
],[
],[
AC_MSG_RESULT(yes)
AC_DEFINE(NR_CACHED_OBJECTS_HAS_SC, 1,
[sops->free_cached_objects() has shrink_control argument])
],[
AC_MSG_RESULT(no)
])
Expand Down
4 changes: 4 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
ZFS_AC_KERNEL_EVICT_INODE
ZFS_AC_KERNEL_DIRTY_INODE_WITH_FLAGS
ZFS_AC_KERNEL_NR_CACHED_OBJECTS
ZFS_AC_KERNEL_NR_CACHED_OBJECTS_HAS_NID
ZFS_AC_KERNEL_NR_CACHED_OBJECTS_HAS_SC
ZFS_AC_KERNEL_FREE_CACHED_OBJECTS
ZFS_AC_KERNEL_FREE_CACHED_OBJECTS_HAS_NID
ZFS_AC_KERNEL_FREE_CACHED_OBJECTS_HAS_SC
ZFS_AC_KERNEL_FALLOCATE
ZFS_AC_KERNEL_MKDIR_UMODE_T
ZFS_AC_KERNEL_LOOKUP_NAMEIDATA
Expand Down
25 changes: 20 additions & 5 deletions module/zfs/zpl_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,15 @@ zpl_prune_sb(int64_t nr_to_scan, void *arg)
}

#ifdef HAVE_NR_CACHED_OBJECTS
static int
zpl_nr_cached_objects(struct super_block *sb)
static long
zpl_nr_cached_objects(struct super_block *sb,
#ifdef NR_CACHED_OBJECTS_HAS_NID
int nid
#endif /* NR_CACHED_OBJECTS_HAS_NID */
#ifdef NR_CACHED_OBJECTS_HAS_SC
struct shrink_control sc
#endif /* NR_CACHED_OBJECTS_HAS_NID */
)
{
zfs_sb_t *zsb = sb->s_fs_info;
int nr;
Expand All @@ -312,10 +319,18 @@ zpl_nr_cached_objects(struct super_block *sb)
* just a best effort eviction and the exact values aren't critical so we
* extrapolate from an object count to a byte size using the znode_t size.
*/
static void
zpl_free_cached_objects(struct super_block *sb, int nr_to_scan)
static long
zpl_free_cached_objects(struct super_block *sb,
#ifdef NR_CACHED_OBJECTS_HAS_NID
long nr_to_scan, int nid
#elif defined(NR_CACHED_OBJECTS_HAS_SC)
struct shrink_control sc
#else
long nr_to_scan
#endif
)
{
/* noop */
return (0);
}
#endif /* HAVE_FREE_CACHED_OBJECTS */

Expand Down

0 comments on commit 445ba57

Please sign in to comment.