@@ -318,6 +318,9 @@ struct sk_filter;
318318 * @sk_stamp: time stamp of last packet received
319319 * @sk_stamp_seq: lock for accessing sk_stamp on 32 bit architectures only
320320 * @sk_tsflags: SO_TIMESTAMPING flags
321+ * @sk_use_task_frag: allow sk_page_frag() to use current->task_frag.
322+ * Sockets that can be used under memory reclaim should
323+ * set this to false.
321324 * @sk_bind_phc: SO_TIMESTAMPING bind PHC index of PTP virtual clock
322325 * for timestamping
323326 * @sk_tskey: counter to disambiguate concurrent tstamp requests
@@ -512,6 +515,7 @@ struct sock {
512515 u8 sk_txtime_deadline_mode : 1 ,
513516 sk_txtime_report_errors : 1 ,
514517 sk_txtime_unused : 6 ;
518+ bool sk_use_task_frag ;
515519
516520 struct socket * sk_socket ;
517521 void * sk_user_data ;
@@ -2560,16 +2564,14 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
25602564 * Both direct reclaim and page faults can nest inside other
25612565 * socket operations and end up recursing into sk_page_frag()
25622566 * while it's already in use: explicitly avoid task page_frag
2563- * usage if the caller is potentially doing any of them.
2564- * This assumes that page fault handlers use the GFP_NOFS flags.
2567+ * when users disable sk_use_task_frag.
25652568 *
25662569 * Return: a per task page_frag if context allows that,
25672570 * otherwise a per socket one.
25682571 */
25692572static inline struct page_frag * sk_page_frag (struct sock * sk )
25702573{
2571- if ((sk -> sk_allocation & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC | __GFP_FS )) ==
2572- (__GFP_DIRECT_RECLAIM | __GFP_FS ))
2574+ if (sk -> sk_use_task_frag )
25732575 return & current -> task_frag ;
25742576
25752577 return & sk -> sk_frag ;
0 commit comments