From patchwork Tue Jun 25 13:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13711196 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 B1920C2BBCA for ; Tue, 25 Jun 2024 13:55:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B02B6B02CD; Tue, 25 Jun 2024 09:55:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 660556B02D6; Tue, 25 Jun 2024 09:55:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FFE66B02D7; Tue, 25 Jun 2024 09:55:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 293516B02CD for ; Tue, 25 Jun 2024 09:55:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E29FF419C9 for ; Tue, 25 Jun 2024 13:55:44 +0000 (UTC) X-FDA: 82269559008.21.681A6DB Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id 7843720004 for ; Tue, 25 Jun 2024 13:55:42 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1719323731; 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=szJ1a+TOEgR68JR0E7tb3smyGH6K4iWbKu51eq0wPBxLgFP7P/nl0J68yld2kISoyjgtdt v67nmqlE48qANTL0D+ndHac2W9hnsKfYsiaE2ZGZv0BCIVIhl7NaUpaN8ViLFGkAuETRlp rF3s5oyulJk/Kbxf9VEsAeEAWMkL+Qo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719323732; a=rsa-sha256; cv=none; b=E7S8lnB7qfhotBlr2xMEgOUqQpGCSRUfUJ+RDEpfUg8L+eIaqu+hCddZtgVO5GTRKof4tO aa3EDvLO3n3FSBGpWRvjey4U2djsthtYmDlD1uR3d2w64zb27DBKvKO3Q1rqGhAfPfGNrn nTE7Uk1/9ZDTv+sB47T+G+IKpfXzfP8= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4W7mYy3VWQznXcN; Tue, 25 Jun 2024 21:55:34 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 6198718006E; Tue, 25 Jun 2024 21:55:39 +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; Tue, 25 Jun 2024 21:55:39 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v9 07/13] mm: page_frag: some minor refactoring before adding new API Date: Tue, 25 Jun 2024 21:52:10 +0800 Message-ID: <20240625135216.47007-8-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240625135216.47007-1-linyunsheng@huawei.com> References: <20240625135216.47007-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) X-Stat-Signature: 1dhwxzn3jhbjwtusznnqjtofphedwjqz X-Rspam-User: X-Rspamd-Queue-Id: 7843720004 X-Rspamd-Server: rspam02 X-HE-Tag: 1719323742-499697 X-HE-Meta: U2FsdGVkX18UHjgInZtLew6+eVe1YwNO/HFOut/Q1ckN47TPfR08SSrdigDUx0uvvxzx2R6kMgk9EtOAfRpC6YSHBlbg9vlJ4iN7oQBBumS0lwkUwXo2Uk13QRycz8qQMbvMrog20hsvBBx0fnWsp4SFO4DLpTv60aXQBJiOq2KSwpp8W9qfSxF+xQ9gXvLPuJCFar/klLMl86Mdj0CqVZCXJCcv86gqDQuihaNZB9mYM5XrKnbIV2vP0Hib+Z89r98kJNPxLyOf3CqRg2fFdFzUFMFKuVwWM5xNCvjz+zbzbXq8VMhSMah9uQOvbbydUf+kTA4sD3PMUWhNTJtP+rXHBx8c9beBCr+lHGM4g/tEWDMVZDZ67MesJOXydgCOd8GDZPJJThOuiZRcn6UC8xguv7DjEAsvDYq7Iz6uoTc36INVW5lkQ6NplfuMcnChTSn/SBM3r91908+UON2IqUJ4VfdCBT5PdqjAr6Wae6a2jLCT0ckoKmiD82Z9QzQniRVgzmBzZpb1zmvE8L0UXLnRiUZZ12etfrX0QCLSl44VvWpcnmmOZKVLV+h9xlrin1wEQeg+OfXw2KCAtMzNa0QKu7TOb4oVcZf6BRLud/w49/at8qNtCXbRjrsUWZzwPYmnJ+oZaG8A5nH0CUyKdXKVSwe7gj3fqrHnQxz5DGCa+F1IOaZ/YhLQQPopcoSvobqAvVt8iyzLtxe5CUzyZzcI8Oi/Hc8roHSKoHIj3prhtsf08HsMVUvqtkuO4eDP0XpE0TsaySqfjPZ6NY8mhSVuZE47faHB7efi9P+eBnKvUxwB61pab0jCtR8WMslKsjo5pmcZ/5ejlyw7UQLMqtiSJn6J5Txm2OC9gG4JbmGcKGPgirT2DWRUaquFzMMKWpjeyfjPeA1c0ljqya1FbVD+vcJjo/g6jM6ys/YvxijkBiUwxe4t1acc6Lq1qxd2DzMRxZe5jZkMa7b1FCR dBS9hojn W/ZSM73rC0d+I/sIuHgHhZNuia+4ls1J4+QP3SlzPoFzwgFPqZwBKlZWR7DnYF9NZDjH+KAsgig/jpNVAUoZR1aobac/qvRYzKcpkv16zuNs/zjGof3WxCyW5AIhssjX7vQ62UhlCSQKr5Cv6RZmeZqiVA/Pzmbq+mgw1p9Ywuhq1UrCVIqEE7py7i82XUTNDXxNujBmbJX+zsHmWaXjVHTLlUmYwXwTxydQfTXFly/JrU6PWM0/Zpiq5e+OaJI495o8i5/IrXFLPcv1FMKac8WRC6nt7bT9pap3J 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