Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp945762rdb; Fri, 9 Feb 2024 06:06:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWS+TiIrCmjDzEkYQtPspCc1clO4RUXOa28xK0ncglLwlzFfcD9UCI9SlIY3zupkB2ghM6Y1ditEInATolD3zpPoHp0qyagpz76SmODEA== X-Google-Smtp-Source: AGHT+IF7Kl2uzR8JfjIvLli3gRLDw/EtTEzirEcXZ8+c+3BKTZLSJaNIToG0Mafyey8NtpfObiiY X-Received: by 2002:a05:622a:1651:b0:42a:8922:9fc6 with SMTP id y17-20020a05622a165100b0042a89229fc6mr2097351qtj.57.1707487570583; Fri, 09 Feb 2024 06:06:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707487570; cv=pass; d=google.com; s=arc-20160816; b=Yt3EEGmjCNc4O7G0fQvOWgO2znilVHX36YW/+kGpMLTc+BMqtw/uevfYlC4WX4A/+r rrJfnR9XjzyxE3jBd5OCrVHW2uPQiM3xrSIGzGC/xLa7vXRgGZ9MJhOG56Aaune/y2Jx Ww5Ar+BLHaBR8jXpHSoOYvse15oDnLtq7d2A1MkyF33lkrXN7kg/nlMsvENom3aSmnkS oL4+JJjsSBXle6pLViNES4XyO8BBfLoJo9xJPdxdHIx0Z+rFjlCAAHMwuQUAFs2JLa8a BtJZ6dDIoKJz3HCna3Z/kLviFRixggPUOhU6QrlwvQ4yYcHIJ9eWNGQK3nVd+FSqnxsF Wnvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=lKA5gd0kAysmtmJiTFc+UzPJXBilmJbj5vIhHZF9bnA=; fh=/+Drum3epSTyYDC0ZRXAWhuPKvt+3UMRO8KZ89sd66E=; b=eOiRp0UHa4935WsM1ghq4+OLWJvIjuY35tmU5H9d9FehyTazGUOasvrVwduPNF1mVn dNXX4WSXz2CQ8O4apFy0k2EUH4ViE3c9kMX3+/KTuHB4bP7Wnx4eeBE31LXjaXrojyUj rvmfFyzJozRjvRVBHMK1vY/yred0dt0H8VZnt/Rf1OXRd9ynQUF7GlgaP+Gihl96r/ae iSCbKyyr1nDePHXLWopMihDoKuO0Csp1DSlmziBplvdTBdd4LhJ+PbAz/ueQplJzPBKh H2RQYUj7ngMIMpoECJu5xAN4mQUNIQZI1JPpPvMmyFmaLGItxbexxey5aTmrKLmOQGPh YWIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="S5B/5p2Z"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-59185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCV8Uh9sJ83kV4rVwZQRzP1J60IkebPsQnIAcj1hEUhZFMuX66JqLKRtLUFfDkZJOWTWTxbcPxNovX7R63SJvW+iA/ElrIlYli2AN4W9HQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d19-20020ac85ad3000000b0042c1bfd7c6esi1899412qtd.401.2024.02.09.06.06.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:06:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="S5B/5p2Z"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-59185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59185-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0BD621C24296 for ; Fri, 9 Feb 2024 09:56:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 366D967E7A; Fri, 9 Feb 2024 09:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="S5B/5p2Z" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3C2A67E61 for ; Fri, 9 Feb 2024 09:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707472566; cv=none; b=qiCK0mSrStPWGCI3R4o/Ag48+x/v3HNkve+WKhfqzuJWevet5a+WPmpffrEoOj2LOAyQnPN1Stu2gU5CORUcJ28hhx6Ht4HssK8b+DPy5zB0zrxh7KwADoI4II+2W5ECMjikewH+OULD7ukGhC28iGqgesXA+FUXvGcSQKoMnT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707472566; c=relaxed/simple; bh=KfsHmDe3ZLFgrnm+SKa5mnKBmWNtSbWGSugWsXTB7lw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=UiQO+w4XuB0poW00TDXekpUXA3AXQjfB3+vYztfyePo8a6hhZlaEBabOmWhlY3gqckWe3bW16+2CBQjcLpSzm1xGMyJMoKiVNLafm27lvIg7DOSYvbPFV8AlElrnRbI/4O6hF/0RIMAcZVLCW/fTgTMtSephmWAH12xf3Ov/cN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=S5B/5p2Z; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707472565; x=1739008565; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=KfsHmDe3ZLFgrnm+SKa5mnKBmWNtSbWGSugWsXTB7lw=; b=S5B/5p2ZzJS7GxzfuqPbGpwYZpDoxy9RsxT2bYJKZLlg3kcRiU4+INEp zBxuv2QfA5+IqTs3WGKsWwKaQRFUcQRDz9SqhxJFFyqFDCJnqIHd4FEXw c6AkmvvV86nB1lMzktP9aSEhJ6lBCS3RmWe0UY1rKI1puRSzx1mEmDHXb /p0K7L+N/WKS9C6x12HOD0SlK35vWaeY0XGgvUwZJxmX/EBLJ8+eGySKy nWCkb4I5jFtH/qs2jPpr8Qsx4Eq55jhpN5cIlCwcvagTYgpRy9QZ1MRLf kckYUIzQsLBHitHKqgEmAFKTuzGkQnYi4vxy44P3SdiA4HQxUJtTtd1UZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="5194091" X-IronPort-AV: E=Sophos;i="6.05,256,1701158400"; d="scan'208";a="5194091" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 01:56:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,256,1701158400"; d="scan'208";a="6535901" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.54.38.190]) by orviesa005.jf.intel.com with ESMTP; 09 Feb 2024 01:56:03 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 9D2E8301B21; Fri, 9 Feb 2024 01:56:03 -0800 (PST) From: Andi Kleen To: Chunsheng Luo Cc: gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] meminfo: provide estimated per-node's available memory In-Reply-To: <20240204083414.107799-1-luochunsheng@ustc.edu> (Chunsheng Luo's message of "Sun, 4 Feb 2024 03:34:14 -0500") References: <20240204083414.107799-1-luochunsheng@ustc.edu> Date: Fri, 09 Feb 2024 01:56:03 -0800 Message-ID: <87fry2t0zw.fsf@linux.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Chunsheng Luo writes: > + available = sum_zone_node_page_state(nid, NR_FREE_PAGES) - pgdat->totalreserve_pages; > + > + /* > + * Not all the page cache can be freed, otherwise the system will > + * start swapping or thrashing. Assume at least half of the page > + * cache, or the low watermark worth of cache, needs to stay. > + */ > + pagecache = node_page_state(pgdat, NR_ACTIVE_FILE) + > + node_page_state(pgdat, NR_INACTIVE_FILE); > + pagecache -= min(pagecache / 2, wmark_low); The magic number 2 should be a define (or maybe even a tunable). Similar below. It seems quite arbitrary, but I don't have a better solution either. Maybe could handle dirty differently, but nothing stands out here > + node_page_state(pgdat, NR_KERNEL_MISC_RECLAIMABLE); > + reclaimable -= min(reclaimable / 2, wmark_low); > + available += reclaimable; > + > + if (available < 0) > + available = 0; That would be a bug? Perhaps add a WARN_ON With those changes: Reviewed-by: Andi Kleen -Andi