Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp3025885rwp; Fri, 14 Jul 2023 15:59:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFm54ZW5MTF2RuW6YALCUVmr1v41rCl+dAwqW8oWrTzWaLh4tQwAVblYF9ovB3RUx7mRFy1 X-Received: by 2002:a05:6a00:2484:b0:668:94a2:2ec7 with SMTP id c4-20020a056a00248400b0066894a22ec7mr6089028pfv.25.1689375563714; Fri, 14 Jul 2023 15:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689375563; cv=none; d=google.com; s=arc-20160816; b=xRYwZomta+dsW4Llng2XVCaWzOoF7iqlv0faPjJW8KspFQ6DRmpPlpMOxWZlerQtLs LdhwIhACzp0Kkoyi4UwdAHp5/U3KJ8cXtp4ZjZst5EOhvDN8h3zXXCuM9O5CcQ8kgbvG QplqDLiFqlEyn8fv35Wez7XCbl1YwEQvqiHlq3PWa6dD3//yo2SDRAsjCO5NSx8+b9F1 NDa492JGNs2I9CcXfOwIAGsHLWEiETzrU6MDthF0xUUdpcz7XDf4CiJNrtQ7arp4NwrY o3fVusqPMdUrQZ33Du6mjKtSLDeHxR9TUiKG016nBz7Vs6eeow3XCk5qUlHiGT+6IjYZ 5zuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:comments:references:in-reply-to:subject:cc :to:from:dkim-signature; bh=FP8NFo5ttl/GuZaVvQMiK1O2vkwG6/VwhootU2UrwC8=; fh=A29/vcst/RUQW8netVIb71N0GUL8x0zjaLfpRoKtH+0=; b=fE9gvXunvNNZn1Bme9g1AogBQihFfXCGIod2Ku0UHrjkHEDj1R7H9AUA19rUbTSoJo LjPqv5oqN6QVbfyDHFSA4eN/Xay+cxCn4BGtHRTyutUueF8NN6z0jgFsdi76198KNOim aRPioNOhnFVE69iDelJ6FRqr+jw165OqpmXWkBU+0IPCHzYT2/lbHVGQt+bGAf1qmqCp WzSirO+s12mcKT4hhF9F9y06qngMo7k1Fxw/5BE8U2ptjyjLs6vpsXBhTI+s1FI0D3FT 30xP3XkPYF3XtfN1NVW8SEblwbDFxE7BfsKWc11EU44vtTCkVgpcdc7lhMcPkTXv0pUt WweQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=r+rXyLF7; 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=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by12-20020a056a00400c00b0064d4d472935si7642796pfb.18.2023.07.14.15.59.12; Fri, 14 Jul 2023 15:59:23 -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=@canonical.com header.s=20210705 header.b=r+rXyLF7; 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=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjGNWpP (ORCPT + 99 others); Fri, 14 Jul 2023 18:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjGNWpO (ORCPT ); Fri, 14 Jul 2023 18:45:14 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B8DE30FF for ; Fri, 14 Jul 2023 15:45:07 -0700 (PDT) Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 9AF7E3F723 for ; Fri, 14 Jul 2023 22:45:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1689374705; bh=FP8NFo5ttl/GuZaVvQMiK1O2vkwG6/VwhootU2UrwC8=; h=From:To:cc:Subject:In-reply-to:References:MIME-Version: Content-Type:Date:Message-ID; b=r+rXyLF7jsf2GuBfJrSdhn8efT8sA85PXz5nUtexayV55R8ScRxL+ZU0w1iiEKOEc UmbeIc5OPCpHLdga69o1SGGinA5elbklAzIZKFBzBs+k68gRXysUSwZhXBuKFLEYbI RLeO59VVTbUDe5UuCdwLerajwG+KxsakUw/7yjXu3sYGboRU21hjPGZbIBlFdkbHrK N5ym46qYfY6ZBOAcgMRSHVF8rkKJysS7QD8L+91UcVeLWl0dPOxSaeFA9E2sHirBcV 7vm3m2v1X6G6hjXgnvLS5WCA26oo/6HJ/v2jnwe6nxMURPK3es89t5nkX625Ktrf9W F2aGcuWwZa6qA== Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-55c79a5565aso1215475a12.3 for ; Fri, 14 Jul 2023 15:45:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689374704; x=1691966704; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FP8NFo5ttl/GuZaVvQMiK1O2vkwG6/VwhootU2UrwC8=; b=kCtdaeA0uEwShDraoBwd6Fw3DY/yi6tEULCq7+A51Utuam58U1+fPxf/Q6R1EXUgsz +IuehgWwgyfTNDkYJbtCED1BSC+UHg7krt4gkzYD+/L1nqpLZ5PYGwwfBhh+pcD3X8qi IKjQhxYy9EAjtrUkDQkpygUZmA0n+Z/oXbNtCq81udNgjRQpDb8CVBXrmTwpIwvAafVE NurVe/tFiuGrQmqzYH/4ANfRXfmJWpVE3wb/V8QP7elES5IfBTQ1Xl99G7j7EdRGeuJ9 j8fq3A+FrNtb2nti+l1kSmq2X0KgO2wQx9awAnto9b9Jp8V2X17d1OWpUtoYO2J1JhFe TZtg== X-Gm-Message-State: ABy/qLbRzcJxcQkf9M4IOldjBZqlCyg4D5Fbmba2FY1TPB3G4sfIQP4n /7TKZQjP1NBsGXm96VVYrkQqK+0on/swj0j1egQJ7eF7/gQREZeHbWTwSckjLu6YjTsMD7rVlWk RDRgr+3UMEKRiHxvYYK9Nqla+aGdpRwtcfD/iIp61Fg== X-Received: by 2002:a05:6a20:1451:b0:132:e1ec:796f with SMTP id a17-20020a056a20145100b00132e1ec796fmr5071576pzi.26.1689374704095; Fri, 14 Jul 2023 15:45:04 -0700 (PDT) X-Received: by 2002:a05:6a20:1451:b0:132:e1ec:796f with SMTP id a17-20020a056a20145100b00132e1ec796fmr5071566pzi.26.1689374703660; Fri, 14 Jul 2023 15:45:03 -0700 (PDT) Received: from famine.localdomain ([50.125.80.253]) by smtp.gmail.com with ESMTPSA id g7-20020aa78187000000b00659b8313d08sm7638033pfi.78.2023.07.14.15.45.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2023 15:45:03 -0700 (PDT) Received: by famine.localdomain (Postfix, from userid 1000) id DDB3D5FEAC; Fri, 14 Jul 2023 15:45:02 -0700 (PDT) Received: from famine (localhost [127.0.0.1]) by famine.localdomain (Postfix) with ESMTP id D65DC9FABB; Fri, 14 Jul 2023 15:45:02 -0700 (PDT) From: Jay Vosburgh To: Jamie Bainbridge cc: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tcp: Add memory pressure flag to sockstat In-reply-to: References: Comments: In-reply-to Jamie Bainbridge message dated "Fri, 14 Jul 2023 16:39:53 +1000." X-Mailer: MH-E 8.6+git; nmh 1.6; Emacs 29.0.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30996.1689374702.1@famine> Content-Transfer-Encoding: quoted-printable Date: Fri, 14 Jul 2023 15:45:02 -0700 Message-ID: <30997.1689374702@famine> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Jamie Bainbridge wrote: >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 Isn't this already available in /proc/net/protocols? protocol size sockets memory press maxhdr slab module cl co di ac i= o in de sh ss gs se re sp bi br ha uh gp em [...] UDP 1472 7 6 NI 0 yes kernel y y y n = y y y n y y y y y n n y y y n TCP 2512 5 1 no 320 yes kernel y y y y = y y y y y y y y y n y y y y y -J >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..f4c5ced2de49d5c6d7f5d7ccd= aa76c89dcf8c932 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 =3D seq->private; >- int orphans, sockets; >+ int orphans, sockets, tcp_pressure; > = > orphans =3D tcp_orphan_count_sum(); > sockets =3D proto_sockets_allocated_sum_positive(&tcp_prot); >+ tcp_pressure =3D 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 pressur= e %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 > > --- -Jay Vosburgh, jay.vosburgh@canonical.com