Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1266408lqe; Mon, 8 Apr 2024 04:14:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUb7TeMtIlAjwn0/xtE2Y428CuFEFh7YPd6lfTRaBtAZGAmqhmroyva2QLFWnJAM86+EGFnq9q+AfSpwcLiRESbsqARB/OTECH9spY9jQ== X-Google-Smtp-Source: AGHT+IHEy74sKT7Y3jAlzb63T7OkWVjE1ptzAtmr9r47jMwZ+UsZ6AYamgQ8MmO3rvj3KPMfFUgn X-Received: by 2002:a17:902:dacd:b0:1e2:bed0:317a with SMTP id q13-20020a170902dacd00b001e2bed0317amr8093742plx.21.1712574847375; Mon, 08 Apr 2024 04:14:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712574847; cv=pass; d=google.com; s=arc-20160816; b=AIrdp1MNLFw5B/zP0YXOedtOY7XDYi8wGvQwskGHEZkF6DiQpI4zaBULHFKNEUJAG7 gf7hAok+w2LPnvphvWi/U4LrqAZ4DJI5oHWZ3DsXixGtcIDummNuQ3upn02Z5g4R+w3L 3rd8FBPAKU6RCQn6GgojG+fjiDnE+lkTmlXfXRcmRymlJjACgwmTqACfE5IdJtIS9aNK rRp0mxdnTZ7liMRMD12SAKAB07GYQJBs171VdQzTMZ1bwwJue58mB4L9hZSKCqj98tEQ orDdbEsmFlyRmgztRzC+2icXuMjdyXN0/ekA9nzZClhvw8o6OJhFjSKxgazko6N+7WIA Z7Tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=Lk5jTXS1R3gpG4dXLk9/g/Ee95SLR84MxNk7dz4nLRQ=; fh=7Sz5j4XycbzFHHdo6Yrq5kPpeqaD+sokA2CFlOb/qbA=; b=j2SE01RbkVbIzQGler3Z9zMn0MXO5sz1e9YqXZvGvR4n6pertI6rbLWB1bpm2bC8J9 YiOn9AwaB/Jyjh/UHozhDQQIDEHs7K+6JRPPVyrfVg/qpybk1QvGkllZyESNm1HRWicB VAs6/s2SNVI+Y98TzWiz54JEOFQb6fWctzOTfem2rJq/YnEbLsvAk4a0y6yeQCbtVPCm ZKCY81fWvI3nk8+THNtuuYpWquozOC2aP/+B/aVx0lXzLpd+m3ZkXL65cuBGV83ftkPS XZ2bjY27WPgkKnZczd8TTAYVELAtByr13nfNj8i7RfI9V0qHJJaaAXPucWHw55rnm7Tq YWpw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="KV/DZvAL"; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-135254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 l13-20020a170903244d00b001e0bee74c2fsi83906pls.68.2024.04.08.04.14.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 04:14:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135254-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; dkim=pass header.i=@bytedance.com header.s=google header.b="KV/DZvAL"; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-135254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135254-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 5CBC1B234FD for ; Mon, 8 Apr 2024 11:12:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DECA657BE; Mon, 8 Apr 2024 11:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="KV/DZvAL" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 3C84F524AF for ; Mon, 8 Apr 2024 11:12:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712574731; cv=none; b=cMBuB6EVjvyMOuoNMC8RweiC+CvcamC9Cql3zDo8AztfJF0cvBOvUiOMx+t/beu8H33mc7TgRjmxCGrfZvKw5P1k8r315JnVKl81HycSWRKy9TU5WtblNlOdSN1ykslJe0NnpE4yKpIAKOX7OsK+aFtJprVVh3yMAC6nAAb0bnE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712574731; c=relaxed/simple; bh=WIo8Cob0ubQ6cNbEg1jHYOeFb/hVRTAaOywGwnSVCZM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=W/eNcTpH3HG3p17zj8Vqh+qsjiH1yCettZDEacT3bgzkWCp4Qk7r36hlbuGB6lOg+71fvZayF5NfJqK6h/YJ1y/7PAEETKwovciL2ohNx5oGKNDqVKLboVF++XBPYlOus+93WzoymnQd57uwpmeLzBClzVWTZ2RKQmVUC3PL+90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=KV/DZvAL; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6ed112c64beso1246639b3a.1 for ; Mon, 08 Apr 2024 04:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1712574728; x=1713179528; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=Lk5jTXS1R3gpG4dXLk9/g/Ee95SLR84MxNk7dz4nLRQ=; b=KV/DZvALUH02cvXJMPzCPukLwYOFlKOMGIkSUb2qBs+QdvG2qnEAjPxCsFA1AZY/+x NAfjy2zzSwuBHUzAqI7rVyRhWXJlJMN2wgZZ8ezIoYJfwq9Iym015BOBJpIGPjwdft+1 lxSAHe0Ex+ncwJXzUNH1HO3vbSTEiHn+QgE7lKoYRAKzrNR1ns4NrxAtVJJuloSoMpuL Pe6Qrrx9RZ/3zgcuJWvi6JDY/ple8oNdis6v7jR06LzwBrFVbu65btylH8V57mBf6YHu hUV4ZNQPzB0bSnKEuRPshaFR8h96RG6gKUreQ8kyeShLF/q2UnLyDe7I32WHWwLcIaxF /yvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712574728; x=1713179528; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Lk5jTXS1R3gpG4dXLk9/g/Ee95SLR84MxNk7dz4nLRQ=; b=W01Acb/7g9fB1z81uAcFiDu9N6ijtz4m454U1RcofyHm+sxwng0HU0A7kY+2tXJ3H1 lJaLImHBnRpsUKB3KLLbe20Iu5xrK3r7EKSM0mQPHGuEqIJetrxvtV9E+a6HYfQO3wHH JWbYMWYpJbiHHp6SSFVrPehwMXWJl1qJDXQ091edruqnOjrxmEm+Wch0SrwkQ4x0OgAP VgR2hRaH4B2xxgiV1WyXjWRek2PwOWAR5/7bK56LtlhgU/cV6cAjJ1DKtDvQsharJXM3 E681C5lH4AZgekmNK9hKf3uhMey10kUoYAP58eeg8YdYdDF/OZ3LVz3jXKvD8YF9IYn+ VYBQ== X-Gm-Message-State: AOJu0Yye9BMRFBjSo1pcpe4+JF2HxH+19//Xb7javeRwO0ecFdRiBtzB kvSlhHjDPrkwMAJzdiwdeRz6dUTBwNpk7hXyuzR6Fv2+QoihDOJoU1nDIsb+t7M= X-Received: by 2002:a05:6a21:789f:b0:1a5:6f20:d131 with SMTP id bf31-20020a056a21789f00b001a56f20d131mr8291893pzc.42.1712574728571; Mon, 08 Apr 2024 04:12:08 -0700 (PDT) Received: from bytedance ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id b19-20020a170902ed1300b001e2bb03893dsm6711958pld.198.2024.04.08.04.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 04:12:08 -0700 (PDT) Date: Mon, 8 Apr 2024 19:12:03 +0800 From: Zhaoyu Liu To: liuzhaoyu.zackary@bytedance.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH] mm: swap: calculate pages via roundup() in __swapin_nr_pages() Message-ID: <20240408111203.GA203766@bytedance> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Use roundup() to replace while&shift. When the "pages" is large, using roundup() will be faster than while&shift. Signed-off-by: Zhaoyu Liu --- mm/swap_state.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 642c30d8376c..d34dc95d0910 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -590,12 +590,8 @@ static unsigned int __swapin_nr_pages(unsigned long prev_offset, */ if (offset != prev_offset + 1 && offset != prev_offset - 1) pages = 1; - } else { - unsigned int roundup = 4; - while (roundup < pages) - roundup <<= 1; - pages = roundup; - } + } else + pages = roundup(pages, 4); if (pages > max_pages) pages = max_pages; -- 2.25.1