From patchwork Sun Oct 23 16:25:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13016323 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 86900ECAAA1 for ; Sun, 23 Oct 2022 16:25:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5504900003; Sun, 23 Oct 2022 12:25:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A050F900002; Sun, 23 Oct 2022 12:25:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F3A1900003; Sun, 23 Oct 2022 12:25:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 83926900002 for ; Sun, 23 Oct 2022 12:25:40 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4D0A916035A for ; Sun, 23 Oct 2022 16:25:40 +0000 (UTC) X-FDA: 80052740040.06.9F8EF57 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf14.hostedemail.com (Postfix) with ESMTP id F098310001D for ; Sun, 23 Oct 2022 16:25:39 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id g62so3103026pfb.10 for ; Sun, 23 Oct 2022 09:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=+jcQPE22A48a95d0Ogt+bAyJJhmrH6Y8yK7TFRPuffA=; b=KnSZxGmLWc/7oLtUvXu2L7AuOqPgZ8Dmv0wdB5e3Jt4pUOCSMjGwFQ77x+tMF4GUO4 2CgS6mtfqdBJSKi1J0SppHTDP7oZARauEjG4Z+NXdnMTrlv9uS2p8NhWe7zsbdm3KFd2 2lnfp1zk9YNQwXFZSBVg+emUfNubt7gdKe3a6yQEMioHBfiYk9NobaOKIhsVEDafDXrA D0kp4oWYHPkEKIGmhY672F0wVt6GtArCZlMg2C29GHviUTfChGgyZbJPIzZDXKcv4LEX v0j0NVBqc+tQgldsSUmQAXRJFsRD5OydkM2pGHJ1qIHLq3u/eMncvqwUIJw1W/vH52Sk 1KDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+jcQPE22A48a95d0Ogt+bAyJJhmrH6Y8yK7TFRPuffA=; b=JOZQolXDKttW1EuYsopIEyCNSPIUTHQSS5oMUv3qY7jD2XaA5BE73syVjnrErdYWGx w2qO9rrB/GvJ9P5dD4otlMFSzolbDUpq/5if+aoqzJ460/jWQueqFsWjossiseAFCwyv 0BJoYusMjkcYd0laxeyvWmJNgf+bBncFTJgkGxeJQeqArzsXj/kQVgoNOyFcMFxupjWm qzrhFJlhreHyh0J+jK3yVl8kH/wTf0jcl6jq+QuITcSqXCGfDPcH4/3dHvDrt2RrxxVv q1AM3LmMXA5ud+smp/yuUllPgv/E/ys7puyu4cRqj2CQOgMGgeK8xs9kreRsdVc1DPKz abLA== X-Gm-Message-State: ACrzQf2PXHnRJp3qpvDgTYB4TLAstg85RgWY9Avgx/GKIKLIWtdmSHYF ZlIpZrMvr8J+3+dAU+h6vFEM0Q0I2+HcKlmocOE= X-Google-Smtp-Source: AMsMyM7NWsfmhTNzlYUbFoEXLmLkWMTX9T8RDOi/P8KojKBVLs3iONMPEjEDjjUcKnRmgJR32vKy3g== X-Received: by 2002:a65:4bc3:0:b0:439:103b:fc35 with SMTP id p3-20020a654bc3000000b00439103bfc35mr24587501pgr.248.1666542338259; Sun, 23 Oct 2022 09:25:38 -0700 (PDT) Received: from KASONG-MB0.tencent.com ([1.203.117.185]) by smtp.gmail.com with ESMTPSA id x9-20020a170902ec8900b0018685aaf41dsm3727420plg.18.2022.10.23.09.25.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 23 Oct 2022 09:25:37 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Kairui Song Subject: [PATCH] swap: add a limit for readahead page-cluster value Date: Mon, 24 Oct 2022 00:25:33 +0800 Message-Id: <20221023162533.81561-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.35.2 Reply-To: Kairui Song MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KnSZxGmL; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666542340; a=rsa-sha256; cv=none; b=h5YOfTxtUR8Qdg9pOGu7M+FKPRJVCEj/LbOe/pfWZhfBsRIkh57VKL+CXiU0uwCoNsuapY rFFLX/sUfJMCfstNsFGyXZHGm1Wxw2+XtRDTRAUChqBbOcxUfxY0DYAw8scOBTV1e/Ypqp mChTx6PNINCQqEv5dJBDLfWDgSBM3VU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666542340; h=from:from:sender:reply-to: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=+jcQPE22A48a95d0Ogt+bAyJJhmrH6Y8yK7TFRPuffA=; b=JeB8hG625SsZlpoJ2Hj/VPzkjdLZx2NjqAbTAIkvrGsifrRWFNoctKZT6cHTSlysX2KxSE /u3Cus8B1EAZQt2ozHWBUB8zWdSqrtXchR6cxbbqJ0dmrMOObIOXBKwa1+BVK97WUEIdDK 6aSaUzg60IheendVyKN0O7kQ2hn5cEg= X-Rspamd-Queue-Id: F098310001D Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KnSZxGmL; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Stat-Signature: 3dib64gwcowudeme4gstjsu1m1ngdsjw X-HE-Tag: 1666542339-217795 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: From: Kairui Song Currenty there is no upper limit for /proc/sys/vm/page-cluster, and it's a bit shift value, so it could result in overflow of the 32-bit integer. Add a reasonable upper limit for it, read-in at most 2**31 pages, which is a large enough value for readahead. Signed-off-by: Kairui Song --- include/linux/mm.h | 1 + kernel/sysctl.c | 1 + mm/swap.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d42536ce1dab4..5512f3b188fab 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -74,6 +74,7 @@ static inline void totalram_pages_add(long count) extern void * high_memory; extern int page_cluster; +extern const int page_cluster_max; #ifdef CONFIG_SYSCTL extern int sysctl_legacy_va_layout; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 188c305aeb8b7..71a4350ac601b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2125,6 +2125,7 @@ static struct ctl_table vm_table[] = { .mode = 0644, .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, + .extra2 = (void *)&page_cluster_max, }, { .procname = "dirtytime_expire_seconds", diff --git a/mm/swap.c b/mm/swap.c index 955930f41d20c..2ab33c82cb062 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -43,8 +43,9 @@ #define CREATE_TRACE_POINTS #include -/* How many pages do we try to swap or page in/out together? */ +/* How many pages do we try to swap or page in/out together? As a power of 2 */ int page_cluster; +const int page_cluster_max = 31; /* Protecting only lru_rotate.fbatch which requires disabling interrupts */ struct lru_rotate {