From mboxrd@z Thu Jan 1 00:00:00 1970 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 76FD5CF11CD for ; Thu, 10 Oct 2024 11:32:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05E676B0082; Thu, 10 Oct 2024 07:32:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00D5D6B0083; Thu, 10 Oct 2024 07:32:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E170E6B0085; Thu, 10 Oct 2024 07:32:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C33736B0082 for ; Thu, 10 Oct 2024 07:32:09 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 23F98A107B for ; Thu, 10 Oct 2024 11:32:03 +0000 (UTC) X-FDA: 82657478778.10.76F2FBA Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id B33A9C000D for ; Thu, 10 Oct 2024 11:32:04 +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=1728559789; 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=uBQXfyZs+N27E3eIONQi2jOCLEiHJucej5Awfc8mhh8=; b=kbd4/x87HgPragFgigE4vTMyIobZkdkk1o+v/vzzp/OkIFGT/NjF53/VZmuaAWk2GWNq0m a/ejWiK0Vt0fbKi5r7lPxHBVmeGFTKLYZis4LgEH+cKymLVivKxezd6HwikY2RXIbsopVF 57p4rdcDP3yK+Qc2I9nqDcssQh3yO8k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728559789; a=rsa-sha256; cv=none; b=L1RxVF33SkK2TVkDCO5lVNSarpVM7mFDvnalJnK7Wbj6oCEGU5ciaUTvCTgZN02d1bC4lo TpVYO/thcAuhPetl6+tipQHN/1t7bY/+FZp7cELgJqnyQ2sILSQ9paw/YH2hvOrpwKetbq DaUDC22dCh8KU8d7UF3q1smHnO2Rp0E= 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 mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XPSGd2tJSzpWgV; Thu, 10 Oct 2024 19:30:01 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id F39FD18010F; Thu, 10 Oct 2024 19:32:00 +0800 (CST) Received: from [10.67.120.129] (10.67.120.129) 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; Thu, 10 Oct 2024 19:32:00 +0800 Message-ID: <8bc47d27-b8ea-4573-937a-0056bdd8ea2c@huawei.com> Date: Thu, 10 Oct 2024 19:32:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v20 06/14] mm: page_frag: reuse existing space for 'size' and 'pfmemalloc' To: Alexander Duyck CC: , , , , , Andrew Morton , References: <20241008112049.2279307-1-linyunsheng@huawei.com> <20241008112049.2279307-7-linyunsheng@huawei.com> Content-Language: en-US From: Yunsheng Lin In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.120.129] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Stat-Signature: s9e899hqhtwi1tsr1nne39ckdznou6ma X-Rspamd-Queue-Id: B33A9C000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1728559924-980683 X-HE-Meta: U2FsdGVkX1/awpcDwvqZ2fbykOZyDwma5UBEuoPRzYTHV6ocBd7kOTW6HV8FiBWeAI72x3c5IgowdNur//qZjjyyelsJSuschX5Q5fXEtO4RVdXkRvTRnb5aHpxHD66x+69Hqeetd/CGgnCq0S08bEcIeZlchEt8saPpmF27cyvl9jFuqN3/JVWWDNxiQY3jQIgVi7RPRG2OaDoskP54alwwKW5SD2ZlmIn40v+BP6ecaDEyn+EjIlSe5jMhrE8N+eSZj6wE3YX5LmDkGn/rjjbJ4nkLjSPbFt78W5uI3Ihw+yZmflSyzPs+vGFqoUuUCHkUiQeeE5oNjJ54cel0ZINdNK0riyUs61YOsVEvrXEubZQWUcjW6s1VSsjyaACwVbIeJeg7/62y2AClbrzfL5bvBSfVdEUtnZy+HPALX1Fa7rCjoJESCMkuLChdC0UbmMpX84GeTzbRbPF6AhAgRDMpam+OoXQST45LImPHA420sfSqUmMfdMH9dnIXsnIzgDlI2j1AluPBN1hP7Nm6o0RAz9Jai1OlwtvAztCNYUcKQfQoBLFBecp/zggjl+WlUyJhrFOzwKKj72jmeJk5mKOh7OWPgZAAT1tfe1BZyAhw2D4iRCirwwLSy3xamPhsiES+nzKiXFVytZRhqWsIa84SuPGNeS/CQ3akvQBoqP9yx7e+wUxeHQZrba90lLtvJ5KNjKota4mfiI/agkKkWzGzBh+nixB8l/LNqjTLuj2Jk4vQcuXhtKDtc+ero3eG2dv2GZ4OD73wTsC/khNLbCt1IfRVqb92hRmAf0IwzkPAo3jhkXuUWdQLHya5qVJ+5Ybkggj+2v96I2+tgcBc5zQRJ+Z/V0TD3Q8q3gksUhJc4kvM1VuOj3udDaSNjn3sGwvyvLejuGo2iSOmsxJOFUYA9HfFKltcCT3aFBg3uoowyabOu/Cgl601BivnM0xEdpzsgrMX8FM6z4ndVMN 44Qyjf6Z VyBd0txqsVPqxuIq4nCe+vsgmVahIj1KdfCu/Bz/XSM5REKgkMd/wuhxeLiie8qqsaetKqJZELTnCbnqqSALUeoiVEytk7ZHNLjMeRsHwRIkYR2BA3sNihlwdEuk6xXonpr47YvjvuDbhe8WCWoNspo12sDi2cUod6NjBPPhWZ5YXO5ngd7PXNLDewetBZUuXfwpsrivafHb2xxFSz3lja1mwXkrL4CXCFLQQwZRjKw048vW818DlPsAMMAzI6B+fatPYSxp2GW8NcMFYrxM7vaxe8rPRAg7dcBPb 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: On 2024/10/10 7:50, Alexander Duyck wrote: ... >> + >> +#define PAGE_FRAG_CACHE_PFMEMALLOC_BIT (PAGE_FRAG_CACHE_ORDER_MASK + 1) >> + >> +static inline bool page_frag_encoded_page_pfmemalloc(unsigned long encoded_page) >> +{ >> + return !!(encoded_page & PAGE_FRAG_CACHE_PFMEMALLOC_BIT); >> +} >> + > > Rather than calling this encoded_page_pfmemalloc you might just go > with decode_pfmemalloc. Also rather than passing the unsigned long we > might just want to pass the page_frag_cache pointer. As the page_frag_encoded_page_pfmemalloc() is also called in __page_frag_alloc_align(), and __page_frag_alloc_align() uses a local variable for 'nc->encoded_page' to avoid fetching from page_frag_cache pointer multi-times, so passing an 'unsigned long' is perferred here? I am not sure if decode_pfmemalloc() is simple enough that it might be conflicted with naming from other subsystem in the future. I thought about adding a '__' prefix to it, but the naming seems long enough that some inline helper' naming is over 80 characters. > >> static inline void page_frag_cache_init(struct page_frag_cache *nc) >> { >> - nc->va = NULL; >> + nc->encoded_page = 0; >> } >> >> static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *nc) >> { >> - return !!nc->pfmemalloc; >> + return page_frag_encoded_page_pfmemalloc(nc->encoded_page); >> } >> >> void page_frag_cache_drain(struct page_frag_cache *nc); >> diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c >> index 4c8e04379cb3..4bff4de58808 100644 >> --- a/mm/page_frag_cache.c >> +++ b/mm/page_frag_cache.c >> @@ -12,6 +12,7 @@ >> * be used in the "frags" portion of skb_shared_info. >> */ >> >> +#include >> #include >> #include >> #include >> @@ -19,9 +20,41 @@ >> #include >> #include "internal.h" >> >> +static unsigned long page_frag_encode_page(struct page *page, unsigned int order, >> + bool pfmemalloc) >> +{ >> + BUILD_BUG_ON(PAGE_FRAG_CACHE_MAX_ORDER > PAGE_FRAG_CACHE_ORDER_MASK); >> + BUILD_BUG_ON(PAGE_FRAG_CACHE_PFMEMALLOC_BIT >= PAGE_SIZE); >> + >> + return (unsigned long)page_address(page) | >> + (order & PAGE_FRAG_CACHE_ORDER_MASK) | >> + ((unsigned long)pfmemalloc * PAGE_FRAG_CACHE_PFMEMALLOC_BIT); >> +} >> + >> +static unsigned long page_frag_encoded_page_order(unsigned long encoded_page) >> +{ >> + return encoded_page & PAGE_FRAG_CACHE_ORDER_MASK; >> +} >> + >> +static void *page_frag_encoded_page_address(unsigned long encoded_page) >> +{ >> + return (void *)(encoded_page & PAGE_MASK); >> +} >> + >> +static struct page *page_frag_encoded_page_ptr(unsigned long encoded_page) >> +{ >> + return virt_to_page((void *)encoded_page); >> +} >> + > > Same with these. Instead of calling it encoded_page_XXX we could > probably just go with decode_page, decode_order, and decode_address. > Also instead of passing an unsigned long it would make more sense to > be passing the page_frag_cache pointer, especially once you start > pulling these out of this block. For the not passing the page_frag_cache pointer part, it is the same as above, it is mainly to avoid fetching from pointer multi-times. > > If you are wanting to just work with the raw unsigned long value in > the file it might make more sense to drop the "page_frag_" prefix from > it and just have functions for handling your "encoded_page_" value. In > that case you might rename page_frag_encode_page to > "encoded_page_encode" or something like that. It am supposing you meant 'encoded_page_decode' here instead of "encoded_page_encode"? Something like below? encoded_page_decode_pfmemalloc() encoded_page_decode_order() encoded_page_decode_page() encoded_page_decode_virt() > >