From 198e79f0e8f0b24c1e36ab6032d348f40de20262 Mon Sep 17 00:00:00 2001 From: Dominik Sliwa Date: Fri, 22 Dec 2017 12:07:34 +0000 Subject: backports: bluetooth: Support 4.9 kernels Signed-off-by: Dominik Sliwa --- compat/backport-4.10.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'compat/backport-4.10.c') diff --git a/compat/backport-4.10.c b/compat/backport-4.10.c index 44e02dd..97d152b 100644 --- a/compat/backport-4.10.c +++ b/compat/backport-4.10.c @@ -251,4 +251,41 @@ int mii_ethtool_get_link_ksettings(struct mii_if_info *mii, return 0; } EXPORT_SYMBOL(mii_ethtool_get_link_ksettings); + +void *kvmalloc_node(size_t size, gfp_t flags, int node) +{ + gfp_t kmalloc_flags = flags; + void *ret; + + /* + * vmalloc uses GFP_KERNEL for some internal allocations (e.g page tables) + * so the given set of flags has to be compatible. + */ + WARN_ON_ONCE((flags & GFP_KERNEL) != GFP_KERNEL); + + /* + * We want to attempt a large physically contiguous block first because + * it is less likely to fragment multiple larger blocks and therefore + * contribute to a long term fragmentation less than vmalloc fallback. + * However make sure that larger requests are not too disruptive - no + * OOM killer and no allocation failure warnings as we have a fallback. + */ + if (size > PAGE_SIZE) { + kmalloc_flags |= __GFP_NOWARN; + kmalloc_flags |= __GFP_NORETRY; + } + + ret = kmalloc_node(size, kmalloc_flags, node); + + /* + * It doesn't really make sense to fallback to vmalloc for sub page + * requests + */ + if (ret || size <= PAGE_SIZE) + return ret; + + return vmalloc(size); +} +EXPORT_SYMBOL(kvmalloc_node); + #endif /* LINUX_VERSION_IS_GEQ(4,6,0) */ -- cgit v1.2.3