Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6853239rdb; Tue, 2 Jan 2024 16:30:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdUp+BGujquVpf33qoEyJzq9A1LjZHXaLyvdz5JqbNSXkRdg+yLnKLUuccmV8gOPnEd+Qj X-Received: by 2002:a05:6e02:1446:b0:35f:fcd5:a542 with SMTP id p6-20020a056e02144600b0035ffcd5a542mr19749977ilo.23.1704241849742; Tue, 02 Jan 2024 16:30:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704241849; cv=none; d=google.com; s=arc-20160816; b=hs/KR7+rNO7PRuNN6OxkYC9RMrzWW+aoUgWyc8mRys+diNCKO3JEVjubC8+ALmMMY5 5stRYfKuuTt+K9dAJBgVPnoDxB6qVZz/7TD7BunYdWInaCbqch5MLc3LuqtmHN/5EFHZ F0Ok2MhUSEdiREGKD4ReytpQUKyG3i5uQDGysaHv9o+uHn3pT5gVFbpDeNGdgUZfkG2Y 97bqiD9CTVCVPB80KRqukFR4GKhEEiih7PZp1fVfptG75z30hWo9cjFGaTe08F2HhF9B kh62gaaJ+/S9pLyhWX7SNwje4RiP9ON2TAEgMl0k1ZFyS21fXQp6n4hDffw22xGMO5I+ xmCg== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature; bh=QFvILJ+t1ObHf5nxnhyRtHafjkPPFwRKVWgBM4XnJkU=; fh=sdTwZIqi/HvYQdcXsB/gI3MvqKut552vvb/Jp+aQT1Y=; b=LN5Bh3smXmdGD6Acl1SYEi5U4L7Emey8LMM5ONLKhxeq/cSp3GjSNneth0weS8q3mR IXDwU2p+l2rBB1FzXE1589tgIwjVSjD8Siiw5VqH2CIKKLAuvKQBlQSuCL3M9+BzmPnO ijw3imrvOjjbp2y+ayOhZP04jYxNOwyAitzP08nFr7XLpQ0m1ENy2p7wglgHQQMloVuz DRzLkNxzArjAdn5YIJr258ftVnLVRIR6date4g5wu7uvzmBg1H9uD6wgbkxEG0PDwuxn nxZgIqDZw9UaeCbc8iWAsEg43/E9QkLsukxSNh0Ms9mJHxriFcLrCL7d3ZYjtnFkZDuv vqWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SYeeYVHi; spf=pass (google.com: domain of linux-kernel+bounces-14999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f10-20020a170902ce8a00b001cfb834d371si19208946plg.113.2024.01.02.16.30.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 16:30:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SYeeYVHi; spf=pass (google.com: domain of linux-kernel+bounces-14999-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14999-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 4524FB22882 for ; Wed, 3 Jan 2024 00:30:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D833917E8; Wed, 3 Jan 2024 00:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SYeeYVHi" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D22611390; Wed, 3 Jan 2024 00:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-28ceae32e9fso6375a91.1; Tue, 02 Jan 2024 16:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704241827; x=1704846627; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QFvILJ+t1ObHf5nxnhyRtHafjkPPFwRKVWgBM4XnJkU=; b=SYeeYVHiQiLhjej0E7YLm8V15FV35BzKFb0fFEeWjyDIApB8NvSNAXziWXvBmjweXo ULz7j1aTqNfzzDx43uvQt2I2pUDPkFS2WwPL7VlzsHHhlcXLeE99DAqlHkqR77/3LbB0 3f+nTN7cEFyC2ynPglqfdf5NcUjemz+muMxNUdl7x6f6QgL0FKFHTiwxcajtNR2gjtIO xv4IFrTI0np2ph9COiJOJRXt+HdYfOMzpt31f/0aMWKT4BoZRkVFiN6LQfb6+QNiU8Qg VTbiGoTc4toaya0fXC1kuUUNp0BlGrtkLxHiWssJ4Hc/M4q/9J2PPPQlHQPQRidqnu0N X8hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704241827; x=1704846627; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QFvILJ+t1ObHf5nxnhyRtHafjkPPFwRKVWgBM4XnJkU=; b=psrVJrjtNTBQcmoHFnof7peOdreD9Wnit0qxCOvZcLONsN0AzSg5OILCC1Db3kkEwF DS+7kmFn6KONMWdlyBvXx9RkUgshWf8rCAPwOvQM7JcpB1Si2onXaPM8dc/Lg/xnNZlq uvCqBO0FERZuzR25CoBTZBni5qxXdn6dbuuxVRADGnG5pSYPrFCXS95CT7qB7Pv7U2UJ Iggxlh2EL5GFA6Wy7ZFXYAZDKMiwQOK09Bba7t1E22e4V1oqOwYLTqT+VHsY/8LG15CH yVjvhhIYHSGNzFWJJ3lEsMZ9ecTv1O+wCaoB+PPRGSl4ggWyirEU8B3W/VhHODqxoItS weIA== X-Gm-Message-State: AOJu0YybUXjs12E1YGKYtgpLX9iN9cE3UCQfI1uYB1wX7r3xq5uhny1z JCpUHZuV4yXU+NWsgpMcXJ0= X-Received: by 2002:a17:90b:b15:b0:28c:bbc7:7576 with SMTP id bf21-20020a17090b0b1500b0028cbbc77576mr1859418pjb.77.1704241826950; Tue, 02 Jan 2024 16:30:26 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a7d6:f37a:9130:cd96]) by smtp.gmail.com with ESMTPSA id k5-20020a17090a3e8500b0028ce81d9f32sm254134pjc.16.2024.01.02.16.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 16:30:26 -0800 (PST) From: Barry Song <21cnbao@gmail.com> X-Google-Original-From: Barry Song To: minchan@kernel.org, senozhatsky@chromium.org, axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Barry Song Subject: [PATCH] zram: easy the allocation of zcomp_strm's buffers with 2 pages Date: Wed, 3 Jan 2024 13:30:11 +1300 Message-Id: <20240103003011.211382-1-v-songbaohua@oppo.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There is no need to keep zcomp_strm's buffers contiguous physically. And rarely, 1-order allocation can fail while buddy is seriously fragmented. Signed-off-by: Barry Song --- drivers/block/zram/zcomp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 55af4efd7983..8237b08c49d8 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "zcomp.h" @@ -37,7 +38,7 @@ static void zcomp_strm_free(struct zcomp_strm *zstrm) { if (!IS_ERR_OR_NULL(zstrm->tfm)) crypto_free_comp(zstrm->tfm); - free_pages((unsigned long)zstrm->buffer, 1); + vfree(zstrm->buffer); zstrm->tfm = NULL; zstrm->buffer = NULL; } @@ -53,7 +54,7 @@ static int zcomp_strm_init(struct zcomp_strm *zstrm, struct zcomp *comp) * allocate 2 pages. 1 for compressed data, plus 1 extra for the * case when compressed size is larger than the original one */ - zstrm->buffer = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); + zstrm->buffer = vzalloc(2 * PAGE_SIZE); if (IS_ERR_OR_NULL(zstrm->tfm) || !zstrm->buffer) { zcomp_strm_free(zstrm); return -ENOMEM; -- 2.34.1