Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp834289lqe; Sun, 7 Apr 2024 06:13:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwFyiNmomCZkFbrt6jqYXWyv8+/EFaf51SIpP/fJXpNlKWByhX014fTcmyCsYYKOw+ycGy6tpGdYomLHc0S+AJyZrtxpPZWv6Qa+VI/g== X-Google-Smtp-Source: AGHT+IEZ/va3aOIIQm/fCSF33iQOjMAINtOc9S0gMVwtLxXrZ37kxYsj2h5n+KwP7qTJvUUOyL8/ X-Received: by 2002:a05:6a20:9f8f:b0:1a7:6894:cec3 with SMTP id mm15-20020a056a209f8f00b001a76894cec3mr1090033pzb.32.1712495602498; Sun, 07 Apr 2024 06:13:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712495602; cv=pass; d=google.com; s=arc-20160816; b=GPtjVHBRZhLJRCjWs/bGeabWxSY/OpFChQMp1zUf/wlSNadqcu06hqiCYgVeuHrYYX vnCkO9/BtmBvzRh+PHhx92VgFq9zhB+Nla3L54KM29LCv80F+/9x+DxFn6VoSZj8lNa8 ysC/anKh5yK6bsNt0GDTvkDJiHKbVcpjWbpS3YqMrtZ4o2+z0mi9XiiCU8GKIaPN5afE osuyjv1miM9UX9hGTSYqXHow5Ki7TtxIS/R/WDPAHYT2PU7lPFKUO88NvW8+CUtkLDS6 ZOs/L/iHPtg5iPg9ugrJHgewVokFD+RTCN4IeBZASbgY8M/Rs/3V6YBtC/YU7WONps5f G7Cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qN8xvUp/Pz6qhwsNImm1ke4lu/qTGOMKjtF+7ZY9FQE=; fh=inFsbniLgByi1PvLyextVSu1v80SuS19K1zpiR/HfaU=; b=PSU6d4Fe7r+L3Fl19DCgXnIW9P7Mo3nUddfKaZR3ctbCKemY/WWmTdulxP08TmtgUQ PMLnY/r/SsVgva7DWwYdbvKJlC0Qlb0Zllgw0XdgBaW/B/cwXicsnP5yKOJq/Tb2eaC1 OvoIvuSS8bAoZa3qK8irjOUDHE4TSfDKFcNC6wGvzv58Nei3mEnjSA6i0eDpVdFkWCDN OmJf9xTNogjwOPUNtPpuJU6UTALA3NMLSOyVkCX4fsmlNzvCOhaZYIeNtfNH2C/md+4G I5bpsEE+HosgUlrbwDf0CtB1vFgBimvyd/C38B9+V8K0RLF9pe0LzUot8HUoOZgte9OV q4qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-134403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f18-20020a637552000000b005cdc5c9d6a2si4697493pgn.576.2024.04.07.06.13.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:13:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-134403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6271AB21480 for ; Sun, 7 Apr 2024 13:13:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E7AC3F9DE; Sun, 7 Apr 2024 13:11:17 +0000 (UTC) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB4093D3AC; Sun, 7 Apr 2024 13:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495476; cv=none; b=Y2ImguY/cgEdABNNEpZUIVpeBn2UBCvZQ43n+Eit9Tf5qKeSxmwJzn9VbsQd2NuXvoDtrreaVPVmxgGuBiHkuC06LI3a31CL3NgwkZHhW/JjZvNOEeMpuB3ENw0nezYH2qaK0/dR76oR8kXsdOjL0e1toL3423YiupKUmevZEII= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712495476; c=relaxed/simple; bh=dvnuWSgw2pdf+CQ3hiV4nkuRSA4Mui25VpqM8+ZL28w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B3Rr/zZtxPo5TCYwvY1ysG/20bLP+IWOROKYUqyTO+c8wO0fefCVNzP79w6H1LuTJBNhOx/n+8vSnVORVd1fSzbx+4PHQfYV5RtOnyPzVvpDiC7gbGYM+xBLiifU15MhhsaeedK+Ks1mC11FzGL024vfQAWQseMArWiJlfiStDA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4VCCGg1PZQzNn76; Sun, 7 Apr 2024 21:08:59 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 2B7ED1404F7; Sun, 7 Apr 2024 21:11:12 +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; Sun, 7 Apr 2024 21:11:11 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Andrew Morton , Subject: [PATCH net-next v1 06/12] mm: page_frag: reuse MSB of 'size' field for pfmemalloc Date: Sun, 7 Apr 2024 21:08:43 +0800 Message-ID: <20240407130850.19625-7-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240407130850.19625-1-linyunsheng@huawei.com> References: <20240407130850.19625-1-linyunsheng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) 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 7f639af4e518..a02e57a439f0 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -29,7 +29,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); @@ -88,7 +89,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 -- 2.33.0