Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2105089rwp; Fri, 14 Jul 2023 00:20:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9qKbvlP80xKHviv+gjuGD6SDXCPmXJyKxZbm0cK0Q8KyJj+kf7zpJcvGomeUFwt+ZF9+c X-Received: by 2002:a05:6808:21a8:b0:3a1:eb7c:21d8 with SMTP id be40-20020a05680821a800b003a1eb7c21d8mr5429842oib.39.1689319249152; Fri, 14 Jul 2023 00:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689319249; cv=none; d=google.com; s=arc-20160816; b=SVGaV8p94YHYsNOjrvKJHEutCtdI9GrjNhSYwbNTly4vpMjxyuMbRpVzsNY/gJl7g2 VcrRNHJ1ghie4Aqk4Q7Aj+vaOmv9eYFBTDky/nLHME3SuC2PDCDxZF+7FY92fDFktooK hjSWWRUrF4cFz88A5WI+9VfAkrUFHmoT2FUI6Pn6cwWK3mcSAr+2uqVjaOpNHb8/I/fI Ju7OlF6KrJQ3PwZJmkPhZv8/w4kn4dzdcwrZCmtl30HKHR401JhG83Njuhg0sYfCc5Qr Qqnj2Sdgthzy8hNVlHWgl++G+mU7OXPCuqrG9wN9zC88nPiPjd71ez50no73pqoRjUzx DQhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nq4AlzIUYH74DwmP1AytKvtmR3itDA2LKj6kldjoWZU=; fh=pAEYDNWJRYie2+4b6NWvnVGRkPH0GN5zQvyp/8CctJg=; b=yGleoLZ6xWNfZo9Khi3Y2ZwyCWuT4C1BHmJXGokwoBvqOtc03ao5gpAwF13ImrdAfV j5h7QcVWuZvldjE6SLKNMXuUAwaOpqJabwDn5OCQ0ZXv01yIpLyv72zlhTLjHeRbrrvP j1ZwSJTRnGN2DyuNetAcAw1VZ/kQrI2kCkaVCLyGQxq07IVkp00x0228mZPB+cYnKD2o n9sYu4d0J9XUw6RLeGKYhAbX/x2TfYYzv7lNt5gv3N1OPDSRozfQPxH6WkpsMn9OIwxm dnA17swUD0bkaC+KCM5ZW3Asx+feqfhI/a3laC5OfRJNI2BRjLw8HT6aWTu3s6O2sk26 tJaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Isnpl4d5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o26-20020a635d5a000000b00550e8b3614asi6330779pgm.901.2023.07.14.00.20.36; Fri, 14 Jul 2023 00:20:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Isnpl4d5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231911AbjGNGkP (ORCPT + 99 others); Fri, 14 Jul 2023 02:40:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233975AbjGNGkI (ORCPT ); Fri, 14 Jul 2023 02:40:08 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EECB2D5F; Thu, 13 Jul 2023 23:40:07 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-666eef03ebdso1008691b3a.1; Thu, 13 Jul 2023 23:40:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689316807; x=1691908807; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nq4AlzIUYH74DwmP1AytKvtmR3itDA2LKj6kldjoWZU=; b=Isnpl4d5csD+Aw1s1azsAEeue2LVPzDM371sqUNpQhontnLuOCkx6NHelmtJgSlxno oSqv8mKM9rZP9r9rx6F1ae+YnpqVB8wu/jzFkYNrCovFImrCkCwaz/yS6ZL6PMSzTjok rKkU+HB/14IIa1qaKIBgAwljAvSuFSwGbBMXKdiV7ZuV5vTuInpjmJja+rPQtxaAKVgR tVF5HC9BBB6FAp90L3XazivDj1QkHUQVEEMCm4MWguvjd2bFNlsWOCEC1+bHCSt7+vbj v1YK0fj7mWBbmMVjoFRGJ2AyG2N2dR+uryOMeu7RQ8evtO4oahx0D6DI1H5gPB6+eXBn GDCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689316807; x=1691908807; 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=nq4AlzIUYH74DwmP1AytKvtmR3itDA2LKj6kldjoWZU=; b=Fke493LHADl60xAWcMgrvl0h1NJN+nqzddiw3BTAw+TRheNTyBHIn1yUk8DDELNui+ Anlm0otKZaEEFVomIcl27he1t2zGJah4Uc21dob4wa6qtvF9PFsaotLHfFq128mPcov7 mJmfkW1UZHKGFZACDzo7SFhYxCrdqA7LxiN7frTCXeC4wVpQtfzGLaMg7qbpideK2njL tjwms20BPzgl576IsJMe3c0JHbXAEqGoIr4/uFI5Lyzc6ECBWQRcQ9fospRJom9DY5D8 giT4lO1DoquucX3mOLqPVP/Yyrk2Z4ZMMOL9vGZ+LcyaBPdQrckNRJK03YGOtV/3o5HF YtsA== X-Gm-Message-State: ABy/qLbNXHdhWHu5/m/Qh5AjCDXzg1A8cWLyvLK4Xw/geVfwzLFju1pT +0gURRfSEFKd3lgsKm6vVJw= X-Received: by 2002:a05:6a00:b47:b0:653:de9a:d933 with SMTP id p7-20020a056a000b4700b00653de9ad933mr3505236pfo.17.1689316806795; Thu, 13 Jul 2023 23:40:06 -0700 (PDT) Received: from localhost.localdomain ([159.196.197.79]) by smtp.gmail.com with ESMTPSA id h21-20020a62b415000000b0067b24701daasm6358986pfn.86.2023.07.13.23.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 23:40:06 -0700 (PDT) From: Jamie Bainbridge To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Jamie Bainbridge , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tcp: Add memory pressure flag to sockstat Date: Fri, 14 Jul 2023 16:39:53 +1000 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When tuning a system it can be helpful to know whether the protocol is in memory pressure state or not. This can be determined by corresponding the number of pages in "net.ipv4.tcp_mem" with the current allocation, but a global variable already tracks this as the source of truth. Expose that variable in sockstat where other protocol memory usage is already reported. Add "pressure" which is 0 in normal state and 1 under pressure: # grep TCP /proc/net/sockstat TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 0 # grep TCP /proc/net/sockstat TCP: inuse 5 orphan 0 tw 0 alloc 7 mem 1 pressure 1 Tested by writing a large value to global variable tcp_memory_pressure (it usually stores jiffies when memory pressure was entered) and not just by code review or editing example output. Signed-off-by: Jamie Bainbridge --- net/ipv4/proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index eaf1d3113b62f7dc93fdc7b7c4041140ac63bf69..f4c5ced2de49d5c6d7f5d7ccdaa76c89dcf8c932 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -51,16 +51,17 @@ static int sockstat_seq_show(struct seq_file *seq, void *v) { struct net *net = seq->private; - int orphans, sockets; + int orphans, sockets, tcp_pressure; orphans = tcp_orphan_count_sum(); sockets = proto_sockets_allocated_sum_positive(&tcp_prot); + tcp_pressure = READ_ONCE(tcp_memory_pressure) ? 1 : 0; socket_seq_show(seq); - seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n", + seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %ld pressure %d\n", sock_prot_inuse_get(net, &tcp_prot), orphans, refcount_read(&net->ipv4.tcp_death_row.tw_refcount) - 1, - sockets, proto_memory_allocated(&tcp_prot)); + sockets, proto_memory_allocated(&tcp_prot), tcp_pressure); seq_printf(seq, "UDP: inuse %d mem %ld\n", sock_prot_inuse_get(net, &udp_prot), proto_memory_allocated(&udp_prot)); -- 2.41.0