Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

page_frag: unify gfp bits for order 3 page allocation

Currently there seems to be three page frag implementations
which all try to allocate order 3 page, if that fails, it
then fail back to allocate order 0 page, and each of them
all allow order 3 page allocation to fail under certain
condition by using specific gfp bits.

The gfp bits for order 3 page allocation are different
between different implementation, __GFP_NOMEMALLOC is
or'd to forbid access to emergency reserves memory for
__page_frag_cache_refill(), but it is not or'd in other
implementions, __GFP_DIRECT_RECLAIM is masked off to avoid
direct reclaim in vhost_net_page_frag_refill(), but it is
not masked off in __page_frag_cache_refill().

This patch unifies the gfp bits used between different
implementions by or'ing __GFP_NOMEMALLOC and masking off
__GFP_DIRECT_RECLAIM for order 3 page allocation to avoid
possible pressure for mm.

Leave the gfp unifying for page frag implementation in sock.c
for now as suggested by Paolo Abeni.

Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
CC: Alexander Duyck <alexander.duyck@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Yunsheng Lin and committed by
Paolo Abeni
4bc0d63a 411c5f36

+3 -3
+1 -1
drivers/vhost/net.c
··· 670 670 /* Avoid direct reclaim but allow kswapd to wake */ 671 671 pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) | 672 672 __GFP_COMP | __GFP_NOWARN | 673 - __GFP_NORETRY, 673 + __GFP_NORETRY | __GFP_NOMEMALLOC, 674 674 SKB_FRAG_PAGE_ORDER); 675 675 if (likely(pfrag->page)) { 676 676 pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER;
+2 -2
mm/page_alloc.c
··· 4685 4685 gfp_t gfp = gfp_mask; 4686 4686 4687 4687 #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) 4688 - gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | 4689 - __GFP_NOMEMALLOC; 4688 + gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | 4689 + __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; 4690 4690 page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, 4691 4691 PAGE_FRAG_CACHE_MAX_ORDER); 4692 4692 nc->size = page ? PAGE_FRAG_CACHE_MAX_SIZE : PAGE_SIZE;