From patchwork Mon Sep 12 15:27:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12973742 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 80055C6FA82 for ; Mon, 12 Sep 2022 15:29:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A88666B0071; Mon, 12 Sep 2022 11:29:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A381B8D0002; Mon, 12 Sep 2022 11:29:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FF358D0001; Mon, 12 Sep 2022 11:29:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7E2B96B0071 for ; Mon, 12 Sep 2022 11:29:25 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B55D1A105A for ; Mon, 12 Sep 2022 15:29:25 +0000 (UTC) X-FDA: 79903817490.21.C63D910 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf14.hostedemail.com (Postfix) with ESMTP id F096010009A for ; Mon, 12 Sep 2022 15:29:24 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id d12so8931268plr.6 for ; Mon, 12 Sep 2022 08:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=CPqjDBRnfd3YUUYjuwzH1YFz7BdjyfL6bOnI/3LB5Bk=; b=hIYiAqgrhPuKXd5jVuPdYSi5Zizxj4WGgX6YJ2Oh96Mtz4pq2+QH5so6OLdi/7M2Bn 3UG82Fno3pnL7Pkj6jWxE2NNfpvvGrTA2oHiKOd2jgC0YmcPxysBoYBI/QbllbhMceAS Yq4gYXpNdceW218uHLM738DLTZg5il7HIaNDs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=CPqjDBRnfd3YUUYjuwzH1YFz7BdjyfL6bOnI/3LB5Bk=; b=XtYVZyzgXLmgUWQBWOO/Jhfu68bhuGzJDUS8x/d//gKY6XorF2C1sAj69D9fjMjB4H qKF5SNKgvcioEzCDVdO+rGSH2Cv2WDO7fIG4wMIaSLve82/Rl0QlsrgVUB7qQbwsx+rv PxyUXkoTymmNDKdJqKQK5FyzDQyDAYkUY7Gmcimy3GZVjUB05cJxrGms/u7Lce4gPSDC ci3huEtNX1dkng+IjKquVn06LLzJbCWWLQYQ5//UtqJDM+nyc01RKCCOiyZN40GZzuaR mxd9nuUHAC7JJdwK7SgXgD5NYaXPPRHwE77Ot8OIKGIaPIogeO6aMSFgvDQeILnAI7ax PDLQ== X-Gm-Message-State: ACgBeo347W4ttIuFo31lXeGm4FLgmCe3LiENKOqJfU1vg1/9aPBP64y3 TnakUzOEhL5G1tPcf4nRvrYzvQ== X-Google-Smtp-Source: AA6agR70svDQ1mN9/etbL0P8c90uZL97hW9UfLOcxZ4CDtx4b4tpOYbVDQK88XcBUyKNyaJUG3vHXw== X-Received: by 2002:a17:902:e947:b0:170:d739:8cbe with SMTP id b7-20020a170902e94700b00170d7398cbemr27884626pll.141.1662996563948; Mon, 12 Sep 2022 08:29:23 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:e064:d5ac:4dae:9920]) by smtp.gmail.com with ESMTPSA id l72-20020a63914b000000b00419ab8f8d2csm5748847pge.20.2022.09.12.08.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 08:29:23 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Brian Geffon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv2] zram: do not waste zram_table_entry flags bits Date: Tue, 13 Sep 2022 00:27:44 +0900 Message-Id: <20220912152744.527438-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662996565; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=CPqjDBRnfd3YUUYjuwzH1YFz7BdjyfL6bOnI/3LB5Bk=; b=yeQhzeR9FW5o7wgWBzF+d37c1Lw3SpyOihteIZP9SdAQ7Fz4H+LNzrOo6wYxVl8ejHuyVV FPxb2kS7ZWQ1iqr5fbgOvP6qUNvaJfl6bxIxuAZKIvBrD3JaQrztaqH9I0tgqHCf+zNE7E gOZznaycvmOYxgcL8WNQVX+7Ng4ZM5I= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=hIYiAqgr; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662996565; a=rsa-sha256; cv=none; b=HDoogJBbt+CCAe8GUaTqvY5aMk7qg5UppwbdgOEXTMYCe6I1SmpvlJxEDR6wr9f92H0JKL zehe7o1K+5mkBDbCsKVKJWLXNiLzm5w0CAn7r7SncnP6KOxUxxFqI7o2IkIrwmpFoHbBcm MwzLjZU9nBPCzUVFZ64lwPO8Z8vluxE= X-Stat-Signature: owwgabjax4ej1g6g7wcd7z7uossrq3xn X-Rspamd-Queue-Id: F096010009A Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=hIYiAqgr; spf=pass (imf14.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1662996564-365872 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: zram_table_entry::flags stores object size in the lower bits and zram pageflags in the upper bits. However, for some reason, we use 24 lower bits, while maximum zram object size is PAGE_SIZE, which requires PAGE_SHIFT bits (up to 16 on arm64). This wastes 24 - PAGE_SHIFT bits that we can use for additional zram pageflags instead. Also add a BUILD_BUG_ON() to alert us should we run out of bits in zram_table_entry::flags. Signed-off-by: Sergey Senozhatsky Reviewed-by: Brian Geffon Acked-by: Minchan Kim --- drivers/block/zram/zram_drv.c | 2 ++ drivers/block/zram/zram_drv.h | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index f3948abce2f7..07913bcdb5c2 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2449,6 +2449,8 @@ static int __init zram_init(void) { int ret; + BUILD_BUG_ON(__NR_ZRAM_PAGEFLAGS > BITS_PER_LONG); + ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare", zcomp_cpu_up_prepare, zcomp_cpu_dead); if (ret < 0) diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index b4eecef2a11f..2b50f0521bd3 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -30,16 +30,15 @@ /* - * The lower ZRAM_FLAG_SHIFT bits of table.flags is for - * object size (excluding header), the higher bits is for - * zram_pageflags. + * ZRAM is mainly used for memory efficiency so we want to keep memory + * footprint small and thus squeeze size and zram pageflags into a flags + * member. The lower ZRAM_FLAG_SHIFT bits is for object size (excluding + * header), which cannot be larger than PAGE_SIZE (requiring PAGE_SHIFT + * bits), the higher bits are for zram_pageflags. * - * zram is mainly used for memory efficiency so we want to keep memory - * footprint small so we can squeeze size and flags into a field. - * The lower ZRAM_FLAG_SHIFT bits is for object size (excluding header), - * the higher bits is for zram_pageflags. + * We use BUILD_BUG_ON() to make sure that zram pageflags don't overflow. */ -#define ZRAM_FLAG_SHIFT 24 +#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1) /* Flags for zram pages (table[page_no].flags) */ enum zram_pageflags {