From patchwork Sun Aug 27 11:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13366946 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 E61A4C83F10 for ; Sun, 27 Aug 2023 11:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DEDB940007; Sun, 27 Aug 2023 07:08:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18ECF8E0001; Sun, 27 Aug 2023 07:08:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07EE2940007; Sun, 27 Aug 2023 07:08:55 -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 ED41C8E0001 for ; Sun, 27 Aug 2023 07:08:54 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C5697A01C8 for ; Sun, 27 Aug 2023 11:08:54 +0000 (UTC) X-FDA: 81169612188.04.539B5B9 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf26.hostedemail.com (Postfix) with ESMTP id 06DBA14000E for ; Sun, 27 Aug 2023 11:08:52 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=qVmdDWjH; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693134533; 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=sONyVx9cK/CieoE/wcRBUETqKBRrm5Dew5BY7/Nseo0=; b=0eXFra6HR18OePS4VQFanNybyEU1/2CbiJD638z70JlzMJ68NdGn+IJnPJ4nSaMgRMZHEM 6xFCjfCab8EPWnQRE/ldyF/fdXVUPTKi+dSYQYsu1F8goeKSmM4cgqztZ44k5kPba4kfqp 8YzADfv3VUyiQH6Ff+CLVh2gEOc3vkc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693134533; a=rsa-sha256; cv=none; b=dk8e2TWCM8KiQQEXC3rWDYTjJoecZb+3lY2r/OC4u1hNSpd4wBuxADJ49cykBvowUwOp0Z lz2TknWWt0yyAzfdZyhW9Zv5qdzHmGC/gOGYXtITg0LuHr6JDoZLgZt6/LJenaE4UBANJC EA8iXJMh5BsQQKc1UH6SEsLYWDte6NA= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=qVmdDWjH; spf=pass (imf26.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-31c79850df5so1941198f8f.1 for ; Sun, 27 Aug 2023 04:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693134531; x=1693739331; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sONyVx9cK/CieoE/wcRBUETqKBRrm5Dew5BY7/Nseo0=; b=qVmdDWjHPSeSGp2+zhejnysiAKOaPT5mXMxwVIHfWdz8rPNQGowjpptzLhZRnPikTv oMkPQDJwZ5yyAF2/0j42NG5ncK8QCRm2U2PDnfEUEh41Kk3kfgg4UCYHHdXtWcYTTBEP dMduXB1dy1Uj/2mz9HA4uy2QMaq/sRl5LMhBe/xmFdKCFLCfkdNbeVfmfFs/adjNrnHd urnz3MTCRj5fcoET90oYjo4D/j6FXoXb5uL62juMF4+d8z7zagWDTUJD/CclXyV2Decj t1hNd/sb8e81pJQoXWQzMxN2j16GwcX8ffqSYeuEMcU9CPDTX1sAsTMqRlsvAoWGi46O FZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693134531; x=1693739331; 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=sONyVx9cK/CieoE/wcRBUETqKBRrm5Dew5BY7/Nseo0=; b=HHcBTVu7R38E6Ij++y0EixTXWCMQhfhm5q6uL6XnVuMTPO2h55czRYCAKHs4O9y/Pu +FzVnZKJ+YQxdq1c3V82BLhIWmTanGsXgd8kxExC086P7tJYKaJG7oZhSBNgDbYIxLe7 ZIvlYqfWZV1s3N+HVgQNXMfbOP8FxXD1D/vULRTC2NYzDY8AlUuZD+7yXh0nTI7x+SF0 4ZVMKDL4Ghq8embLBOi5g0M2yxhyddQVMg5gX2hHRVBOB8i59C7yDEVdyTbXamb+A3aL 89nZavTfE5uCNhSjo0wblVroqc2MJDY9+2zw4e2agr6l6QHSrlU7ntCuUj8Sy9GfCIHX PDNQ== X-Gm-Message-State: AOJu0Yx3NWFyOqSocevmIo7wrxW/8NyDBG2P98Pi7qEJiSGSb4cbHhEI 2jk8SQthQwwqtgNBMloVrWN1KFdZaHg= X-Google-Smtp-Source: AGHT+IE6A9cejXZz+BLsFwob3V1yjzDPwsZo4kaUzgcstoivARk5t1e9p32fyCpIsi+pSTAC8OZgpA== X-Received: by 2002:a5d:4f0f:0:b0:319:89ce:da0b with SMTP id c15-20020a5d4f0f000000b0031989ceda0bmr16765705wru.68.1693134530967; Sun, 27 Aug 2023 04:08:50 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id f12-20020adff44c000000b00319779ee691sm7299281wrp.28.2023.08.27.04.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 04:08:50 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: Kefeng Wang , David Hildenbrand , Hugh Dickins , Lorenzo Stoakes Subject: [PATCH] mm: refactor si_mem_available() Date: Sun, 27 Aug 2023 12:08:48 +0100 Message-ID: <20230827110848.43510-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Stat-Signature: 8mqs7cor1gg34mcphfgidxexqsfqzkws X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 06DBA14000E X-Rspam-User: X-HE-Tag: 1693134532-56145 X-HE-Meta: U2FsdGVkX19AtMxdreVIGMb71P62Jiy0tUYKtSCW2kbAwDpaHXqFxHOX3nCOLa6H6Ktj6Myc7x0oVF+82xKyH2TC+FbiqgsRIoBW+GCsmyWXurjj/96KYd7CO7TspE0gHSm21SWJY7aNuFCQpHAqrtZ9tJdqMtZxsUfXJiZKdQ2yIpdtQAt2+YUQ2yVhVX7hAv3I1YMP0Cdgz79KprZFDM1fsav38URRSf4mSI5isr39sh6Q2nvqJ3gKArI7ZKMSjynqaWCR3+WlFc8ascDAaP7a50nn9FbZCuVtFjtpVkviU/sAYkQ0Ey7+hmzc2Tt7FpnA8KyPXa+YYdqJJtjYU5LnT1MNj7hfFgRVbLTIGeA1UUQwUc623UrM5DohLe+pVAb/IIMcUMb5Fk7h7ynJe+XaC9VlDCLB15Z1WxVC5H3drD/j3Ze3NiLaYlp0kIL5C1cc9j4if28uLU2n9WOAzDSH1H4DT2QDYnPEX3aq+kMV/zfkY+eBdh+XTaPQzQCtYDaxBg2ooB6UpgUBK7A1kvbdAsHRotpn/EEnBl6WthDDLfqFiRhSTZGI5w12xXjK2hXqsVwhPLibTbYNfrzm4hegj4P3zh3nv5VRofhm/T6LXMmWWzK0ch9p03hrlRGxWSqf65RjHoG+WCttIj9hO/wB1OzfVxFfb23mfl4WkikYxFsH1I0PtSajlaQMCYZ/ZG+tesXBV87rsEHqOkfyPf179u+YMLh/lZYt5kQ6asaXk5oYrTE5lsTyDE5sd05n/f0KhDnfG6KjZkK5wlCQHIR8DTubgKBCZboWXhXpjZfVGJ3ca/6fslSZ+GFJEzzdv+6rjjukkdOI8LQx7zT5SbFg7nfH1TQk2p9M0sCPO5EcJlkCeSgsU4KTOAnGVcI7mhKuFNqo8zIEAuhAWZ+84VA7c/IQjNo2vbmOcJBd8HKtFkLN9GHJ1EDbAvLaGaijjC6l/UnY42HQLSF7Jqg xyYEKC+I zFXJz0br0I9OLre+p7q3s6Q+SiaNPayEsi96YCT7MxPDapsNC6tkNXCHjOBVFFYd19VaPc7gYDqCU84nwET7+1dnoX95t3M0Q3dg9A1qkq0lbXiPWd7mUhqzyl+7pyo4bBr7PMHNruPjgH7LmongmJCSnMD+W1o6HsKZ9MRAfN07wbe/w+mivvbpyYue2dJoGGEDI0f9/R7CmlnfvzWBDmcydT0A0TKKWy6pei2A9y/C2PIjC8X2yeewv/JDehyBhrs43TIMhYI12UOIMj3cTZuRI1t6zPLgENdmkUreC4IjfV7KmJzB7bIYZvAGQhlaDh6VvKzG2Xm9zPpKnF4KrubAK/heKm40qBlQ7qabkWP0ixI4tLzrQ4A48BlEQQS2+MyTxRKkI5TekvxPf6Zd/A1T32BJsGmiUwUZ9wC2bO9FxJjXbF+KsWm6wwYL+dnFjlxeiwB8G8FysCV0MmbmGBSYsnisHBDt+luNK 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: The si_mem_available() function needlessly places LRU statistics into an array before retrieving only two of them, simply access those directly. In addition, refactor the code so that the blocks of code which calculate the page cache and reclaimable components each resemble one another to clearly indicate we cap both against wmark_low in the same fashion. Signed-off-by: Lorenzo Stoakes --- mm/show_mem.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mm/show_mem.c b/mm/show_mem.c index 4b888b18bdde..ba0808d6917f 100644 --- a/mm/show_mem.c +++ b/mm/show_mem.c @@ -34,13 +34,8 @@ long si_mem_available(void) long available; unsigned long pagecache; unsigned long wmark_low = 0; - unsigned long pages[NR_LRU_LISTS]; unsigned long reclaimable; struct zone *zone; - int lru; - - for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++) - pages[lru] = global_node_page_state(NR_LRU_BASE + lru); for_each_zone(zone) wmark_low += low_wmark_pages(zone); @@ -56,7 +51,8 @@ long si_mem_available(void) * start swapping or thrashing. Assume at least half of the page * cache, or the low watermark worth of cache, needs to stay. */ - pagecache = pages[LRU_ACTIVE_FILE] + pages[LRU_INACTIVE_FILE]; + pagecache = global_node_page_state(NR_ACTIVE_FILE) + + global_node_page_state(NR_INACTIVE_FILE); pagecache -= min(pagecache / 2, wmark_low); available += pagecache; @@ -67,7 +63,8 @@ long si_mem_available(void) */ reclaimable = global_node_page_state_pages(NR_SLAB_RECLAIMABLE_B) + global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE); - available += reclaimable - min(reclaimable / 2, wmark_low); + reclaimable -= min(reclaimable / 2, wmark_low); + available += reclaimable; if (available < 0) available = 0;