From patchwork Mon Jun 17 13:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13700609 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 82D82C27C79 for ; Mon, 17 Jun 2024 13:17:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFA0F6B01AB; Mon, 17 Jun 2024 09:17:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA85F6B01AE; Mon, 17 Jun 2024 09:17:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6FDE6B01B1; Mon, 17 Jun 2024 09:17:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B5E436B01AB for ; Mon, 17 Jun 2024 09:17:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3B9FE1615DF for ; Mon, 17 Jun 2024 13:17:45 +0000 (UTC) X-FDA: 82240432890.01.B6666A3 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id BD4911C0012 for ; Mon, 17 Jun 2024 13:17:42 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 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=1718630257; 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=Eo54SDZoI4MdZH6mlge/hTJyUJjGnpRfYGjUWKAnrPU=; b=upoiOrpyD9uto9/bky0IlP913f38g322FajtVYQiu9Xsp0Nvq34XvK7M+uUFnunuM5cAYt v5U/9ZgAAWjqnN5vZZRC/00tU08L9Dxj6vBdc8RESiSK5NPJVO8By0y9HWi5djjFBGXk3S zt3wGbgE3pRHjsvsmtEHuzuA6RXm5rA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718630257; a=rsa-sha256; cv=none; b=sOxIDpGUvjytP4Q7PEUavES7TMKnndXX5BYnM/LAfx5mRLYB1i0+y5uWug5tteiCvTU6SP 7nvKsMmAOJNSK4YgfPKLp0NICAcM2Vuqlq4QD/CQOPrfmjulOmCzT9nEYvPB1aut3cclF3 0E+jHHYgauWv5Hw4X78wLHzKrCTpM1M= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4W2r141trrzxRsV; Mon, 17 Jun 2024 21:13:28 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 4F1621402CA; Mon, 17 Jun 2024 21:17:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 17 Jun 2024 21:17:38 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v8 07/13] mm: page_frag: some minor refactoring before adding new API Date: Mon, 17 Jun 2024 21:14:06 +0800 Message-ID: <20240617131413.25189-8-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240617131413.25189-1-linyunsheng@huawei.com> References: <20240617131413.25189-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BD4911C0012 X-Stat-Signature: badyf9hhquksmra1ouz443f6jcq8s3ew X-HE-Tag: 1718630262-918736 X-HE-Meta: U2FsdGVkX1/2zNCC/wpNg5MyWfpwwVMtSYUZ/W+9q7XtY6wWP5tRSizzL6+UVGGNQ8fwaspNE4B3wiQVHkPCDTUfxBpzMKcJRE6as80lgITzD34PBlhlenap2MX+N1WWZD6jpzRZ0RAApT6Jb81kIs3rmEyMbvSW64tEIVeD0hxhvUx/Lt1w5BAii7kbe6hM//SoupT5Yvj8HQmo6Zj+61N8P7USVpuhn2hgDyWptc3wj65Kz1O8m2QqB9SntW+XmBK2OPgoJ54J9UZWzh+IXasG11t5uRLLJ4jQOAc7569P/rskqtSQed70WcR9IrP1WsHHfmiuu1hvrZzX9Ze4OrkAh0zXsuMBRp1TuQSbuF1UUM4sqm0Omg8UD7f1PZD124/0j+aBrTsoIVYNBGe6UVsLrpKwpGg6yzqNE7FCIqr7g216ERU1EIUk/eMJM5o6tm55rbW7pEQtUveLPjLEjUy5DlhndcUQzxCAkImWdzcblVwn8hHaR7BVWIGGjLwlGYZdtKhYRJgGkA4oElQlvmbF+lUB02Ytaj85SfPwbHcRESOmIrZtX6nejgHkbwRrBchX3HJJq8nX3kDPPMpP67dbbGU7SNXbFpJJu/ZzlmhWHahtGxb8dEWulw3mzdSL/CJyo1MM+Tpwr00iBCmWD0fs6z9NHp7YBrAZd0Na8Brs2Uzd07T3En3NNGgVfF+8C4WBjID2ZHM1jQ5F2mkfNXDGeOzdTeYwHADx4thBk5V5dSalCHkpOU73C3JCrFFTfB0vBIBbOYm0NDXb2W41KJNWtOJl6x77YSFTCtrf3pk4iyZsc/HklCZZAjitCsJdrYfoaTBKDAlE2FrqwPSQHxDBVHhP4M+417VZ8FA2mBxhvVqtXstlkPGJ7po5bz602G2MRGABUiI6xmpgwD7x28oc3qM0IMBiQD+J0d6GcJ/NifeZtKJtN2tyx5vo1OY0/ltALXJMYwwQBCTX84j ENTaciXz DPR8WEZZ4D/nKuUhDqjXTG4FgTmcscN9Gh8KxANlLfQjRPXMwHqAiRiXZslaPDaHpTTJllNeoAqbLF8oxge6myu16Wavxxj3oo09A32n5IY0voHIJYzB23oC4TWwCPAtvsb7KsqVdwFigTkem+rBBQR7l6U2q6pphI6L8zlPqrTz8KjsMMqHQt93q4WUea/B5lLHnCvMfAElPHEU3iWoQF7XjxgEdl6lYg24AOQaBRecErQc0anRqJBwiSPl/I0VD3ylPNoSP969uvGJ/YfderUaQ/rW0ILh8Yg4B 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: Refactor common codes from __page_frag_alloc_va_align() to __page_frag_cache_refill(), so that the new API can make use of them. CC: Alexander Duyck Signed-off-by: Yunsheng Lin --- mm/page_frag_cache.c | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index a3316dd50eff..4fd421d4f22c 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -29,10 +29,36 @@ static void *page_frag_cache_current_va(struct page_frag_cache *nc) static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_t gfp_mask) { - struct page *page = NULL; + struct encoded_va *encoded_va = nc->encoded_va; gfp_t gfp = gfp_mask; unsigned int order; + struct page *page; + + if (unlikely(!encoded_va)) + goto alloc; + + page = virt_to_page(encoded_va); + if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) + goto alloc; + + if (unlikely(encoded_page_pfmemalloc(encoded_va))) { + VM_BUG_ON(compound_order(page) != + encoded_page_order(encoded_va)); + free_unref_page(page, encoded_page_order(encoded_va)); + goto alloc; + } + + /* OK, page count is 0, we can safely set it */ + set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1); + + /* reset page count bias and remaining of new frag */ + nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; + nc->remaining = page_frag_cache_page_size(encoded_va); + + return page; +alloc: + page = NULL; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; @@ -89,40 +115,15 @@ void *__page_frag_alloc_va_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask) { - struct encoded_va *encoded_va = nc->encoded_va; - struct page *page; - int remaining; + int remaining = nc->remaining & align_mask; void *va; - if (unlikely(!encoded_va)) { -refill: - if (unlikely(!__page_frag_cache_refill(nc, gfp_mask))) - return NULL; - - encoded_va = nc->encoded_va; - } - - remaining = nc->remaining & align_mask; remaining -= fragsz; if (unlikely(remaining < 0)) { - page = virt_to_page(encoded_va); - if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) - goto refill; - - if (unlikely(encoded_page_pfmemalloc(encoded_va))) { - VM_BUG_ON(compound_order(page) != - encoded_page_order(encoded_va)); - free_unref_page(page, encoded_page_order(encoded_va)); - goto refill; - } - - /* OK, page count is 0, we can safely set it */ - set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1); + if (unlikely(!__page_frag_cache_refill(nc, gfp_mask))) + return NULL; - /* reset page count bias and remaining of new frag */ - nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - nc->remaining = remaining = page_frag_cache_page_size(encoded_va); - remaining -= fragsz; + remaining = nc->remaining - fragsz; if (unlikely(remaining < 0)) { /* * The caller is trying to allocate a fragment