Commit 7cb02404 authored by Mel Gorman's avatar Mel Gorman Committed by Linus Torvalds
Browse files

netvm: allow the use of __GFP_MEMALLOC by specific sockets

Allow specific sockets to be tagged SOCK_MEMALLOC and use __GFP_MEMALLOC
for their allocations.  These sockets will be able to go below watermarks
and allocate from the emergency reserve.  Such sockets are to be used to
service the VM (iow.  to swap over).  They must be handled kernel side,
exposing such a socket to user-space is a bug.

There is a risk that the reserves be depleted so for now, the
administrator is responsible for increasing min_free_kbytes as necessary
to prevent deadlock for their workloads.

[ Original patches]
Signed-off-by: default avatarMel Gorman <>
Acked-by: default avatarDavid S. Miller <>
Cc: Neil Brown <>
Cc: Peter Zijlstra <>
Cc: Mike Christie <>
Cc: Eric B Munson <>
Cc: Eric Dumazet <>
Cc: Sebastian Andrzej Siewior <>
Cc: Mel Gorman <>
Cc: Christoph Lameter <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 99a1dec7
......@@ -621,6 +621,7 @@ enum sock_flags {
SOCK_LOCALROUTE, /* route locally only, %SO_DONTROUTE setting */
SOCK_QUEUE_SHRUNK, /* write queue has been shrunk recently */
SOCK_MEMALLOC, /* VM depends on this socket for swapping */
......@@ -660,7 +661,7 @@ static inline bool sock_flag(const struct sock *sk, enum sock_flags flag)
static inline gfp_t sk_gfp_atomic(struct sock *sk, gfp_t gfp_mask)
return GFP_ATOMIC;
return GFP_ATOMIC | (sk->sk_allocation & __GFP_MEMALLOC);
static inline void sk_acceptq_removed(struct sock *sk)
......@@ -803,6 +804,8 @@ extern int sk_stream_wait_memory(struct sock *sk, long *timeo_p);
extern void sk_stream_wait_close(struct sock *sk, long timeo_p);
extern int sk_stream_error(struct sock *sk, int flags, int err);
extern void sk_stream_kill_queues(struct sock *sk);
extern void sk_set_memalloc(struct sock *sk);
extern void sk_clear_memalloc(struct sock *sk);
extern int sk_wait_data(struct sock *sk, long *timeo);
......@@ -271,6 +271,28 @@ __u32 sysctl_rmem_default __read_mostly = SK_RMEM_MAX;
int sysctl_optmem_max __read_mostly = sizeof(unsigned long)*(2*UIO_MAXIOV+512);
* sk_set_memalloc - sets %SOCK_MEMALLOC
* @sk: socket to set it on
* Set %SOCK_MEMALLOC on a socket for access to emergency reserves.
* It's the responsibility of the admin to adjust min_free_kbytes
* to meet the requirements
void sk_set_memalloc(struct sock *sk)
sock_set_flag(sk, SOCK_MEMALLOC);
sk->sk_allocation |= __GFP_MEMALLOC;
void sk_clear_memalloc(struct sock *sk)
sock_reset_flag(sk, SOCK_MEMALLOC);
sk->sk_allocation &= ~__GFP_MEMALLOC;
#if defined(CONFIG_CGROUPS)
int net_cls_subsys_id = -1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment