From 8c8de14b703e11331646b041ca5868bdac448122 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 6 Jan 2019 11:49:06 -0500 Subject: ratelimiter: totalram_pages is now a function Reported-by: Alex Xu --- src/compat/compat.h | 4 ++++ src/ratelimiter.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compat/compat.h b/src/compat/compat.h index 4ffe387..15cf8bb 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -748,6 +748,10 @@ static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2, #define hlist_add_behind(a, b) hlist_add_after(b, a) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 21, 0) +#define totalram_pages() totalram_pages +#endif + /* https://github.com/ClangBuiltLinux/linux/issues/7 */ #if defined( __clang__) && (!defined(CONFIG_CLANG_VERSION) || CONFIG_CLANG_VERSION < 80000) #include diff --git a/src/ratelimiter.c b/src/ratelimiter.c index 82d1379..b3b1d25 100644 --- a/src/ratelimiter.c +++ b/src/ratelimiter.c @@ -170,9 +170,9 @@ int wg_ratelimiter_init(void) * we borrow their wisdom about good table sizes on different systems * dependent on RAM. This calculation here comes from there. */ - table_size = (totalram_pages > (1U << 30) / PAGE_SIZE) ? 8192 : + table_size = (totalram_pages() > (1U << 30) / PAGE_SIZE) ? 8192 : max_t(unsigned long, 16, roundup_pow_of_two( - (totalram_pages << PAGE_SHIFT) / + (totalram_pages() << PAGE_SHIFT) / (1U << 14) / sizeof(struct hlist_head))); max_entries = table_size * 8; -- cgit v1.2.3-59-g8ed1b