From patchwork Fri Jun 7 12:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13689833 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 50FF6C27C53 for ; Fri, 7 Jun 2024 12:41:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7FBD6B00AE; Fri, 7 Jun 2024 08:41:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0AB86B00AF; Fri, 7 Jun 2024 08:41:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5A406B00B1; Fri, 7 Jun 2024 08:41:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9763B6B00AE for ; Fri, 7 Jun 2024 08:41:39 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5FA51A04CB for ; Fri, 7 Jun 2024 12:41:39 +0000 (UTC) X-FDA: 82204053918.20.2F6DC26 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id B2767180015 for ; Fri, 7 Jun 2024 12:41:36 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.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=1717764097; 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=1CGtCMHvPErhP/ku6clFd74qAjNGPU/Wh2Wb/FHnvmg=; b=qjSCOCuo89CzyT/yltZKXSmcAEqrh8TY7vqGgMKFeTvVbWebJOIe2ava7cmpMIQfbuc20l fLBuvDeoBgi6AOlOg50VMPuBczbvLGorZy04ek6Tr1e+6x7G5v4iEQPjBsS1tMAQor9OeK iiA1K9dKsCdI3n4dujFEvjN6yZSK+RQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717764097; a=rsa-sha256; cv=none; b=Vo/TBvLSo5X6Q/8zE4nojsMmsd9vMdaCULy81FR+0bbD2Zj41IbG7am6+8F43mwRVVbDAp lfziTR27HJq7pXyxa3YBUbuAEMu+2t1BFA/OIqto0Ljj0F8Gl+oOUFJi8Z/YyS6JFkGCdl +HAkomrU2LITLabznkPnnYcGdMc8Doc= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VwghG1fDHzwSJh; Fri, 7 Jun 2024 20:37:34 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 950F718007A; Fri, 7 Jun 2024 20:41:33 +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; Fri, 7 Jun 2024 20:41:33 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v7 09/15] mm: page_frag: some minor refactoring before adding new API Date: Fri, 7 Jun 2024 20:38:12 +0800 Message-ID: <20240607123819.40694-10-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240607123819.40694-1-linyunsheng@huawei.com> References: <20240607123819.40694-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 dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B2767180015 X-Stat-Signature: cki5yyftj3sc4gubyinos436uygxfmbf X-HE-Tag: 1717764096-238567 X-HE-Meta: U2FsdGVkX18ZZmS6n0SfTCOqEq0+4ul4V37HL+XoNiQMsI7hJbdUcpztsKULSNXqq1nqLgeLA4HOBhZjRJZKIZf2nNiyp9xiQRwdPe5dDjwKrwC3tPCRINd6046j5+wF+wyDp6Pd50qWHIBbDW8KhDpjsiehaqt8GhSaqpyB16qdiYndNJWuA7DslbB0tcWNiQN7Qm1bL8+VkODs5r1+zunbkiQ3uQkxVrLw4QxGNb64gjSMejg7b0DXyqh+5NAoShxf0BNUZl01r0jHRKhsmtEI0isCKh65EFn5MTL/sGHq2l+zzeFtwwIEf7HGTeq8ll49WGIpQxV4qyieURx/oWiOgy3Su9PTmNAbkUgt1hwevQ/s/xXej4LcGlIlx69mpGHsyRyPVYPqZ652f9tfyk1ZJAaYVa8h5QyBqCd0SG+YHK+WXWyIIEXUCuww0SGoD/6+/R4Uu8pjKiGjqiw5HCWIcyxMUJoG5zbFAG8U9VVjQpWe6GUwAmWXxMu0HMcDwhE3JaRwTEQZP3dL2LwC+SNira0Q3c6IPP4MpDjS3xIPW75/WuKR3SFyCLMYhKZ2egXVOWz5OJmtlg2kRZsbaVGQ0OWqNC/F0OSD5Kqc9o4WLEIxnQteA67EexvmM+JnUlFrLvtK5pDPSZZeDSoWQUR/bkJj8DeDLIBsEBCBqeHy3iMnA3dwVTxn+HeeItdagorg8YBuNejp/TPQv6FNoKMeEnNbVAxb5fs0RLsSW+UDspE53flzB55P/IdR88FckT/UtDmiJa3/ScN2zajri5NlkcP875tgW1o+671zIE6wLxAAvgeTvtTWOJiNICVSsMebEuzetQJSdOwSHXqXoBTy5gJpjMxsCN4E5IPJL4dM7H3Enbg0XGUuPtij/oBKfD+LL86KE3p1lM6vf0v8FermsPbNlAUli6va+l6hABjRUAVHXbYIgkyyPnlcbwCuXJCk+4mS+9h/Qb+gO9V kcvydrmn 0i7q/2C13xaoJe+bLMAi/NgtB8VM5GUYp5a7Qy/7wGe/XhAU2SHVrMNK4aQHfi9n2qaebKxiGVytXq0lr1RPhNSUItzg2rJTXKy7b+GACnZa8zs+xUnCkZuA1JXASQM9vKVAOoyApe3vDwizFA7tq630HIT1fWIE7s/6k2AOpUSbMO2ivkknAsbswz/644FOpTChAwxT6QGCQl3kzYGaQTFGw51C1ATqKhdQLmcMwcaRgOOj1FKuwj/rkTVhBvdabB4QKzNj2ruIGjd6yDc7QJ8v8ngNYfgYpaiA2 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 756ef68cce21..b5ad6e9d316d 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) /* Ensure free_unref_page() can be used to free the page fragment */ BUILD_BUG_ON(PAGE_FRAG_CACHE_MAX_ORDER > PAGE_ALLOC_COSTLY_ORDER); @@ -92,40 +118,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