From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 219433446A7 for ; Tue, 23 Jun 2026 04:22:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782188571; cv=none; b=uRyBmUsyOX7+u5hsppPrqgKL6/fwi2/tnXSQ2ywdh5mcLp/sdutGjO0KZnRzg/5yvqn+x7stvxvwbKTeS2LNb/QYxcyxwsO8u+hwaMi2oSm19rCJNxsIQ8u/OiOEUCuni3pfaeVUaWGCj+TZZYqgmTCCwAncxueRGzs0JYPBmTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782188571; c=relaxed/simple; bh=4t0xdu/x4CUgTFmS5tHcLJGRYc5MCuN2kDwc5kKtw7A=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References: MIME-version:Content-type; b=ArEvOBt1IMjlQAx/U7oHXCeFGGvm9/n1QhKSDoRVvp593v07gfhHyMEfjm7nMpHfQxrBC5dnxYEJlXaheHXV/PCAQCQ48PMM/6yg9Z71uxQDzdl5LBYMzP/fe8v6BFm4xBZMoQizHH1fTHQ0VRpw+Cr+WokBbihdomK60kkTQto= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b5ZsMFrP; arc=none smtp.client-ip=209.85.216.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b5ZsMFrP" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-37ce68a54f8so3169704a91.0 for ; Mon, 22 Jun 2026 21:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782188569; x=1782793369; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:message-id:date :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=iCeZzcSVN670PFFl9OXDzKKPTpZS94DK0FINkgJfL0o=; b=b5ZsMFrPFTPFM3y8vz5nDG2HITpEcfs0nXet/ssphsu2PqZBP0gZ4oW9Sr79c8qyjH LVMsnZXmirShHxbMUJ46rq4ks5JKRUpI6SPnptOKBkW77P6BbMp601vhAIT7eZ0rJiWg 9f3v6YjJYM+xBiBCCL7lhslTcR3K34OqFS/tr8wguKQ4PMGMWbd1XiKc0xjmJpR1/FzK OIACZN0y5nE3COAxDz8elDfIcbQKMYK41FJmCpiXGf2CBv0z5Ms/JwkHvP/fp5a0+56y LEr6i4QTW8pxTrVPPSzjQ+qLQC5SgPfTz5Qfl9ZeclPfNd++mPtbmIQq+ESFApifW8nD CFIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782188569; x=1782793369; h=content-transfer-encoding:mime-version:references:message-id:date :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=iCeZzcSVN670PFFl9OXDzKKPTpZS94DK0FINkgJfL0o=; b=PkuYW3Kx/I5tYc6o5cg7Yg6c2AD3JB4MXFovXY6tKhflxaqb0En4jWQ0GDDHMPiJbb eVvB3yyoa76yigNW653Mlo4C0vCmHXv72BECe9F1Xaep7xnymjo+sPqp8YQO0BW1sXyq aZZR+LDeLje9Euqx+31OEIf/FUejkIjHl2foE6ju0J+yHpdKNPV5t8E6WqUR1BSCpc4y kcAUvw07LbsPhCrrIhrKLY5suKoQztFc3qdmPEJqdL6tqsxRDXUiMHzy5jCiwjWxBSZ6 yb2Bk3MS0CA5EuYtdohM7OyILB5VgUqelzxBOhgupWtX2tFw21MWEMvnwNwVEmTL6tiP Kdow== X-Forwarded-Encrypted: i=1; AHgh+RqySjfCWNKwZO/RauGkiu9/Z7m9mEGkrxQoZupggXzddkKIIcWMlzw3HvYMc538KaSnt/lMbuFcKR9pKyg=@vger.kernel.org X-Gm-Message-State: AOJu0YwlJ3dS/WHCHPRzPsAOmrKuX7kp84FP48Gq4751viFNzvoG3VmU GsUNM/c09Y5v94/9nLYd969YLvRsSoh0yp24fxE1ShmFLUFOLyvvoW7gL5t4Dg== X-Gm-Gg: AfdE7cm/5QPNjEIANnC6ZEjtzKAP9uz2PGcZkXo+LOUiKU3gOvaQTOUxyvS8ylSeY1v GL/9N2uhG0yy9wV2tSpf356DVhk/u67lB452eG2pNUWJPn0EH6NXZBTCN7KPUXlh70rANjMCtQy ezw2gJ96ftDOwrOXNooPS8ZfsTcfvXFLltUWz93jSN+qcDo0ks0Eh9j4qk69ktVpe4rCu6BBbFN sdKeTSWla1ZD8k844EeSr2CYm4AL4BCDb0Qb9jx4mnmhYXJMG0gv6IKLcwFyNs8NdXlcqVY5jyC pzlqxeb0NIbkl4NDdPi/BpPAI23TIKXISfzVtkS6ag5/B0kVobASnCLQSNDv4aAIst3zbdbWoJc aaF1zzE8BJ5t4yCUaaEkQxUJZI7elicvScPtmVhUcLxwU2gIhG/KpkhBm2ZhKr0mKwGK1cEqdK+ Ctpf7lvuoH7HinmEc= X-Received: by 2002:a17:90b:5346:b0:36d:5dbe:2a0d with SMTP id 98e67ed59e1d1-37dd0d30e19mr1352554a91.7.1782188568802; Mon, 22 Jun 2026 21:22:48 -0700 (PDT) Received: from pve-server ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37d1536b541sm11397460a91.1.2026.06.22.21.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2026 21:22:47 -0700 (PDT) From: Ritesh Harjani (IBM) To: Barry Song Cc: linux-mm@kvack.org, Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Youngjun Park , David Hildenbrand , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Sayali Patil Subject: Re: [PATCH v4 1/3] mm, swap: make SWAPFILE_CLUSTER runtime In-Reply-To: Date: Tue, 23 Jun 2026 09:41:48 +0530 Message-ID: <4iityjy3.ritesh.list@gmail.com> References: 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=utf-8 Content-Transfer-Encoding: 8bit Barry Song writes: > On Fri, Jun 19, 2026 at 12:41 PM Ritesh Harjani (IBM) > wrote: >> >> On PowerPC Book3S64, MMU is selected at runtime, so macros like >> PMD_SHIFT are effectively runtime variables in the Book3S64 code. THP > > Not an expert on Book3S64—could you explain the runtime variables in > more detail? Does enabling THP_SWAP on PowerPC cause any build issues? > yes, build issues. We cannot declare array sizes by using runtime variables. That's what this patch series fixes. >> swap code uses these macros to size some of its array data structures >> based on PMD_ORDER e.g. SWAPFILE_CLUSTER macro is used for this very >> purpose. >> Hence this patch makes the users of SWAPFILE_CLUSTER to use this macro value at >> runtime and also modifies swap_table and swap_memcg_table which were earlier >> using this macro for defining the number of table entries. >> >> Signed-off-by: Ritesh Harjani (IBM) >> --- >> mm/swap_table.h | 6 ++---- >> mm/swapfile.c | 17 ++++++++++++----- >> 2 files changed, 14 insertions(+), 9 deletions(-) >> >> diff --git a/mm/swap_table.h b/mm/swap_table.h >> index e6613e62f8d0..90e2a7852300 100644 >> --- a/mm/swap_table.h >> +++ b/mm/swap_table.h >> @@ -8,16 +8,14 @@ >> >> /* A typical flat array in each cluster as swap table */ >> struct swap_table { >> - atomic_long_t entries[SWAPFILE_CLUSTER]; >> + DECLARE_FLEX_ARRAY(atomic_long_t, entries); >> }; >> >> /* For storing memcg private id */ >> struct swap_memcg_table { >> - unsigned short id[SWAPFILE_CLUSTER]; >> + DECLARE_FLEX_ARRAY(unsigned short, id); >> }; >> >> -#define SWP_TABLE_USE_PAGE (sizeof(struct swap_table) == PAGE_SIZE) >> - >> /* >> * A swap table entry represents the status of a swap slot on a swap >> * (physical or virtual) device. The swap table in each cluster is a >> diff --git a/mm/swapfile.c b/mm/swapfile.c >> index 78b49b0658ad..4bf11c5b87eb 100644 >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c >> @@ -129,6 +129,8 @@ static DEFINE_PER_CPU(struct percpu_swap_cluster, percpu_swap_cluster) = { >> .lock = INIT_LOCAL_LOCK(), >> }; >> >> +static bool swap_table_use_page __ro_after_init; > > Does a static key help here? That IMO won't give much benefit, given the allocation by either kmem or alloc pages, anyway dominates the cost. Also I believe this is exactly the usecase where branch predictor helps signficantly and reliably given the variable is ro_after_init. > > Best Regards > Barry Thanks Barry for looking into this. -ritesh