From patchwork Mon Apr 15 13:19:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13630033 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 98662C04FF8 for ; Mon, 15 Apr 2024 13:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 698786B00A0; Mon, 15 Apr 2024 09:22:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F8CB6B00A2; Mon, 15 Apr 2024 09:22:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4257C6B00A3; Mon, 15 Apr 2024 09:22:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 21FBC6B00A0 for ; Mon, 15 Apr 2024 09:22:20 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E8A5FA04D2 for ; Mon, 15 Apr 2024 13:22:19 +0000 (UTC) X-FDA: 82011829998.12.B301360 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 6E84740015 for ; Mon, 15 Apr 2024 13:22:17 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713187338; 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=XfQNv+JcKFCyCnLthBkoL0Yadocs6h7dMObzV8mIa9A=; b=6q/HGpzdjnCE6fezLA4xm49a6y4l/QKTX82YwQsEuGzhXyG+HY9AKOabuj6DmCyfw/iEk1 UrtMVOpnlzQ0n/7c5Jot9CyPmmUDKJdpDiAecGX/5b7Z2gPDw8sjj4Cpl7QctOPThro9SU WmY3ep1ATIhy0kI3B1pmcWdisFjuyNI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713187338; a=rsa-sha256; cv=none; b=B1S1DzUxb/h8lhwYjoLdQSZ+ZZMhz5dhQMakoAAc9Wuzj/ITnGgNDTe1g3EJTeMBSNWZsm UY1C04NBmJy/CW165WcsmESWguPfPOE54GnLy3BrCakW9cb0VweBhAqdV8Q/etQQmNR7NB 2vskS+/f7B7YcGDXzSTh5neG29cIMCo= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4VJ7983ZXkz1wryw; Mon, 15 Apr 2024 21:21:16 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 333DD140410; Mon, 15 Apr 2024 21:22:14 +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_256_GCM_SHA384) id 15.1.2507.35; Mon, 15 Apr 2024 21:22:13 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH net-next v2 09/15] mm: page_frag: reuse MSB of 'size' field for pfmemalloc Date: Mon, 15 Apr 2024 21:19:34 +0800 Message-ID: <20240415131941.51153-10-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240415131941.51153-1-linyunsheng@huawei.com> References: <20240415131941.51153-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 dggpemm500005.china.huawei.com (7.185.36.74) X-Rspamd-Queue-Id: 6E84740015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uoubnyxk9bucjtnpjfosdqphe5nawq54 X-HE-Tag: 1713187337-689124 X-HE-Meta: U2FsdGVkX1/Ge1CS8lcbiqX8BNVKT/vVfYJevv1Qpaa3XhsgoYDctxtHuPrM3S4WXxJ9SgBTd7riy3F5CYZP83xtba6Im5rbQ5QRfEO2dGb7b9Nq88fFULIeq9mr1/GKmtQUquHhPSAdEJTwUu+s6kSnPrxTvzdZL2DycTbUG60pgUrQtsay64Fk6tdowIWrP02+K4hgrwRW4BzMPrNVMarhGtgvDWitus8zMMvh0KyinSlIRCykTQrIhuItCuQmgD13LYZPBHnBLL6MjkKH5cLe+4fbem/MeB9MBgYA/MY2B0hFJ+pSiPFF7ptp+9VUouUFdEsM51L1vKgtdIOxyKBBIZRm1oQsKD9iBsDdaav0v4yMMZ+tsccpne/O8NU2vp/QY7mNzdE+pW9lOIAS26G9W6KtXjlqOCBTyX/XD2EVaYuhJHwKid9qCTfmlpEz5+5q65tg346GdEfjhxphEu3w4uzCiYEM97YdLNkNMiPMi0ob0e6VJT5G7SVu/qM3RdfPV46ZkNvlDSstB6B3xgFEcatNw8eZBu6yfd6bcw8S5ZmEz9m/PB6qTFNlBhC7T9zGkCSK6rHMRjqBwdaqi+tthwDX157LY2k8dvBb9SdyiKxkSj+a87Y1iMQ2izihg6rWS/1UjMPTv6GIPiPXHNU19ONKLsH7zLGBznFUPEBLNykyom64yYsEsjNNLZbtTn4cXJvJ9FCZPPXg8GEMwAb8qr5L8vi3v4F7nma/ADSVaCxJ8LeMzP1WELy6BwmwgeJuviMEKS0e5X0IBgAdlwtRQOPaw8FrvPzeC1lr6jD17rCOtUDYPYC/DwtW5hphtJdUGhn6LO50Dcq85cI5mraHSyVM5y5te/9gERK7tSXEUF59YlbJop1ulFJQME61Wi1ExLZwwhiltN40eyNIKgw0T/nO28QAmzZ50zvPTYzxQGKrJvSe/k503STMLmmD9djLxQmBp4OqosklnsN wq1fVvyP wHuRYBSoUIRsJL7FESj55EvBrJhvoz+F8o8VGfPdBwIGiVWK4EH1VN/1NTwrEX6xTd6IXdCvXJTvzRpgISJolA9Hpln11SJSSOaqN3k7BtwJCXyuuxTsMEzW1fndyudPRpkjfjDhO/DXKaRzHkVdECKaAt1ADeShZnjrpUlG9SgKcBUoJRUeAUdg4l47hJeGCs6PW6fDgY1esuliQg8nxQRdevDLopbMe+wRAAwqkRer7aCSY5b1JrQk9GCnhOlvb+W8a 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: The '(PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE)' case is for the system with page size less than 32KB, which is 0x8000 bytes requiring 16 bits space, change 'size' to 'size_mask' to avoid using the MSB, and change 'pfmemalloc' field to reuse the that MSB, so that we remove the orginal space needed by 'pfmemalloc'. For another case, the MSB of 'offset' is reused for 'pfmemalloc'. Signed-off-by: Yunsheng Lin --- include/linux/page_frag_cache.h | 13 ++++++++----- mm/page_frag_cache.c | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h index fe5faa80b6c3..40a7d6da9ef0 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -12,15 +12,16 @@ struct page_frag_cache { void *va; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) __u16 offset; - __u16 size; + __u16 size_mask:15; + __u16 pfmemalloc:1; #else - __u32 offset; + __u32 offset:31; + __u32 pfmemalloc:1; #endif /* we maintain a pagecount bias, so that we dont dirty cache line * containing page->_refcount every time we allocate a fragment. */ unsigned int pagecnt_bias; - bool pfmemalloc; }; static inline void page_frag_cache_init(struct page_frag_cache *nc) @@ -43,7 +44,9 @@ static inline void *__page_frag_alloc_va_align(struct page_frag_cache *nc, gfp_t gfp_mask, unsigned int align) { - nc->offset = ALIGN(nc->offset, align); + unsigned int offset = nc->offset; + + nc->offset = ALIGN(offset, align); return page_frag_alloc_va(nc, fragsz, gfp_mask); } @@ -53,7 +56,7 @@ static inline void *page_frag_alloc_va_align(struct page_frag_cache *nc, gfp_t gfp_mask, unsigned int align) { - WARN_ON_ONCE(!is_power_of_2(align)); + WARN_ON_ONCE(!is_power_of_2(align) || align >= PAGE_SIZE); return __page_frag_alloc_va_align(nc, fragsz, gfp_mask, align); } diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index 50511d8522d0..8d93029116e1 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -32,7 +32,8 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, __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; + nc->size_mask = page ? PAGE_FRAG_CACHE_MAX_SIZE - 1 : PAGE_SIZE - 1; + VM_BUG_ON(page && nc->size_mask != PAGE_FRAG_CACHE_MAX_SIZE - 1); #endif if (unlikely(!page)) page = alloc_pages_node(NUMA_NO_NODE, gfp, 0); @@ -86,7 +87,7 @@ void *page_frag_alloc_va(struct page_frag_cache *nc, unsigned int fragsz, #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) /* if size can vary use size else just use PAGE_SIZE */ - size = nc->size; + size = nc->size_mask + 1; #else size = PAGE_SIZE; #endif