From patchwork Fri Dec 1 12:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13475705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E3C9C07E97 for ; Fri, 1 Dec 2023 12:02:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 716258D0071; Fri, 1 Dec 2023 07:02:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C5BF8D0001; Fri, 1 Dec 2023 07:02:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 518C58D0071; Fri, 1 Dec 2023 07:02:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 438A88D0001 for ; Fri, 1 Dec 2023 07:02:26 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1B7701A0224 for ; Fri, 1 Dec 2023 12:02:26 +0000 (UTC) X-FDA: 81518111892.04.DBA0499 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id 29FEEC0037 for ; Fri, 1 Dec 2023 12:02:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701432143; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3B5fwC9qERbgCOX4tFw3OYiISGUMa0xw9VoqY6py2PY=; b=5tnpz/zAkeHIM69X4EEjYK2WKMJCsKvHv1wtDs+iMWRQzlkntpv+jxd4XhSHeJscltveFt SqYM1+5kJBvyWbSn7ZmICW0uMZ4epMCXCDZxL00tV9LXBIhzSvUUtIS13fzKBNP6zRfx/C oQZI+OCmLVb/uXAw4SAwGLXuNktvl3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701432143; a=rsa-sha256; cv=none; b=okOfY1DtlrYr8psZ+cg3dvJsdCzqFyLBr9Le9ARalS/i+G2D3v3KjlbuNZptzbeknLIwWz 3UvEjVH1u5DcxmQgF7HojUZZlOUdHR1L4QfjOx1qAdN6aPLMVcj8WGOn/XWbnbKt74vYof 4vJWOBkiheTFflYdE74GB+tcoHNZR1M= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4ShWlq02qgzShJS; Fri, 1 Dec 2023 19:57:59 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 1 Dec 2023 20:02:18 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , "Michael S. Tsirkin" , Jason Wang , Andrew Morton , Eric Dumazet , , , Subject: [PATCH RFC 2/6] page_frag: unify gfp bit for order 3 page allocation Date: Fri, 1 Dec 2023 20:02:03 +0800 Message-ID: <20231201120208.15080-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231201120208.15080-1-linyunsheng@huawei.com> References: <20231201120208.15080-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 29FEEC0037 X-Rspam-User: X-Stat-Signature: nheb6hcqfhs8qgyngfmo33hmfxwihijd X-Rspamd-Server: rspam03 X-HE-Tag: 1701432142-217644 X-HE-Meta: U2FsdGVkX1/AzTv9e0t7MmYiTXloskkYAb+Dtw6ua4YMTsSiKfIf+Sj1xAvyE632adjOMZ0BYsar/8zPR9YRkbvsZpbJF74VLZPgYYOABfh4CcvJWm3saEOx25Ei1aPbvQHNe1QrAOqEWL98X0xW4at2TwNyuU40zQXhPl0S96oNvRvKHhMO0qfzBC18zyAo+djs5eqc9mSy4emVhWFd333w6YvdyvB0QXapGTgr5MxvaajZrntE9cs/N2hDnMiHdxqfaZ23bPw5NvXTkXAP88vKMi9+ii/K3NssFFlYJtw4s9ZEatHBqs5/jSKF5qoQU/wzWcnAlM/J6zMYz2s+lgaFHxTyWDomciY2X2OxB8i+vaCbdBikyCdjXAAh580ZKzZ+YzJbXc/5WwJyMaafiyvYpNkhE04a2ZFAM4GqnEtzNXFwI362rQ4zcMTRnH1ImT7KH3k7egZcbbdZj1l3zrlH4Cik8gz+dcIK4f1d1NlXvr1bNtVXW9SsEi+ImD7XiwV6U+mepLneVvvdtiosDGWSIPJfQz4N40paH55ObUwF8H7Rb9YWl9/eloSxt0QmgXli865AARKOnNGc3+9Zb9Rnxg42u1lxIxAx77bVLAtVn6ha4k5ET5arWeXJ7+Sl85ZOgg+Go8K/OAXQ0vHgnxTwkiCpDeEEvD1fPugn+PJ2JuEFusqHvZVAakfyOp3AqqsTtf4QZoziJ4RN05DHca4oXTwdKyMHgUXiEKs1ilqBa56bVHwm6CFgsp+YSz+VU0v53mOAiM5o9rRpZxSBgh6fBKPkP7yOpnjxCLPRkylYQ/EA82DCxiQ+t7IysQsLR0Gx3CNNNWfvo0S2eZlMUTx7A7QqUknkmGeAeZMsYuRtU1ureiS7F6rQSG9lkByY6pGCUSUQej66uR5sXQ/rz5+0vbFVFF5IwzLhut0tjqyVLFnVfmd8wZi5Gr3G5jUhTtVGH93pNl8FJioJRtO AeN516BT UJT9FDl/zo5IQAfK4MVrBo9Q2hskOC3qiFJJ6CnSO1xgiSgpziqW6cde+AxGN5OaTj/P9mBvsosT3jaimSR+eBcbjPp1/+UFoutXrTQyHm14TEaJnVOMuGK5QPqHj7HqtHPwwd4BnGeFQh9w5OFfeD0VSp8D85MuSPumSGinL0415IvdpQJi1YzJudP0u19M2eZlyRC+mq+6YTdj0Cf1sFWCar4b9NUxxOgXYTdKMPHhf9uSyD07n9cwDmD1+ehlogKZApdVj9u68wgpT3Vf8D/i3Ftvar6EzDKsg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Currently there seems to be three page frag implementions 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 xor'd to avoid direct reclaim in skb_page_frag_refill(), but it is not xor'd in __page_frag_cache_refill(). This patch unifies the gfp bits used between different implementions by or'ing __GFP_NOMEMALLOC and xor'ing __GFP_DIRECT_RECLAIM for order 3 page allocation to avoid possible pressure for mm. Signed-off-by: Yunsheng Lin CC: Alexander Duyck --- drivers/vhost/net.c | 2 +- mm/page_alloc.c | 4 ++-- net/core/sock.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index f2ed7167c848..e574e21cc0ca 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -670,7 +670,7 @@ static bool vhost_net_page_frag_refill(struct vhost_net *net, unsigned int sz, /* Avoid direct reclaim but allow kswapd to wake */ pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | - __GFP_NORETRY, + __GFP_NORETRY | __GFP_NOMEMALLOC, SKB_FRAG_PAGE_ORDER); if (likely(pfrag->page)) { pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9a16305cf985..1f0b36dd81b5 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4693,8 +4693,8 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_t gfp = gfp_mask; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) - gfp_mask |= __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | - __GFP_NOMEMALLOC; + gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | + __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page = alloc_pages_node(NUMA_NO_NODE, gfp_mask, PAGE_FRAG_CACHE_MAX_ORDER); nc->size = page ? PAGE_FRAG_CACHE_MAX_SIZE : PAGE_SIZE; diff --git a/net/core/sock.c b/net/core/sock.c index fef349dd72fa..4efa9cae4b0d 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2904,7 +2904,7 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t gfp) /* Avoid direct reclaim but allow kswapd to wake */ pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | - __GFP_NORETRY, + __GFP_NORETRY | __GFP_NOMEMALLOC, SKB_FRAG_PAGE_ORDER); if (likely(pfrag->page)) { pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER;