From mboxrd@z Thu Jan 1 00:00:00 1970 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 B763DC3F6B0 for ; Mon, 22 Aug 2022 16:07:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F6EA8D0002; Mon, 22 Aug 2022 12:07:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A6E58D0001; Mon, 22 Aug 2022 12:07:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 297AC8D0002; Mon, 22 Aug 2022 12:07:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1A2EB8D0001 for ; Mon, 22 Aug 2022 12:07:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E3D1841269 for ; Mon, 22 Aug 2022 16:07:19 +0000 (UTC) X-FDA: 79827708198.14.B949573 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf08.hostedemail.com (Postfix) with ESMTP id E4F93160151 for ; Mon, 22 Aug 2022 16:06:29 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id 2so10371109pll.0 for ; Mon, 22 Aug 2022 09:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=Hzk+uAP2EkRL9Sia/SFiFvZ5KFrXcliMp2X+SwbXgJE=; b=FE+FMGBU8Io/f8ZTnMHGJbZ5+wKLBIfpgdiJ6n9Ye3xjsJwJiWRthFQZesalJXxr6v asH26nv62+9fFdn9DJY/PQ1wPTtD6mMrkdyqnfgjWtwbLUQNbfsJW7Z+/hWmDC3TbCia 2FYtPJmqybTobZ3vBqr+CuVzk+yEwkmsH9R0W5mALHZIucQJPqWPJCmrJrzIS1ROB3sd 6xEvpo7fvLpHxrjZZw/rZL5CitN6yBN20KzM1+O9ofyu/Fq8+Fm97MZib4/BNUa3yJIN hdYuobZLS7CYbd0581wdytZboHm0+/k0dtsJtGtlEMvmaubqnB7a7hY+Xz9Gr4zduXKf Y4pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=Hzk+uAP2EkRL9Sia/SFiFvZ5KFrXcliMp2X+SwbXgJE=; b=nLcMfcxJNz2QvpmvvBtBr4bp+LH9v3jSr//+jKBeDqR3c5HwxxafVmUKqgc0fV4vWS vQdz7iX+FKhxHjE7w+wehCOyinWruEkWvjiOmJ1cpxQDk4nA59DfPcg33GupLczIfpdN FObawfKG5I7rxU+XMflSeHxIRQrEG1mgLx8mY1p/V7Mec+MdYLhZl9EX00w94oV+Ikyg 80Ge3tjhCzpN5h6gZ4kGTT8pN8PNQRafRCKhc6YukHEP8Marj15VxsCWLEwVoaZIZiW6 kTpmi/k1CH3jqtu0PM14d2WGDVxn+W9+dpwd58AoDDbLkHtq/CGBS8+KeyaGT1c8w0q4 spxg== X-Gm-Message-State: ACgBeo31d7v7VblyxvwGFYHdudWY6TkAoaaA39K+HAPId4h7886/759A wysLvMF5BUEI6885fqc7IEN/D1K+mKXBqMkcxuXZvQ== X-Google-Smtp-Source: AA6agR6jVzDkGiBKD1GwoCYyQtpCU1z9BROhd8tOPEO6X5bKXjyo66sucaWs+VXhEve1C/WahqOzVbUuMF7phoy6aII= X-Received: by 2002:a17:902:e80e:b0:16f:14ea:897b with SMTP id u14-20020a170902e80e00b0016f14ea897bmr20878023plg.6.1661184388337; Mon, 22 Aug 2022 09:06:28 -0700 (PDT) MIME-Version: 1.0 References: <20220822001737.4120417-1-shakeelb@google.com> <20220822001737.4120417-2-shakeelb@google.com> In-Reply-To: From: Shakeel Butt Date: Mon, 22 Aug 2022 09:06:17 -0700 Message-ID: Subject: Re: [PATCH 1/3] mm: page_counter: remove unneeded atomic ops for low/min To: Michal Hocko Cc: Johannes Weiner , Roman Gushchin , Muchun Song , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Eric Dumazet , Soheil Hassas Yeganeh , Feng Tang , Oliver Sang , Andrew Morton , lkp@lists.01.org, Cgroups , Linux MM , netdev , LKML Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661184389; a=rsa-sha256; cv=none; b=Ts0+YWg+crLL5Z8xrmjvAF2FWGIERSEs82GodkXnTYV9yDJuIcY7WekwZgvKThV8K6dic6 mVgagc7dj3mXDZGRBf+ZvB2phjNJWBSIQDvHDkSFf3TEWPHbDoNnjNMNbQaN72roMBImLS E37yeWkTvpxdeOeQcbMCIzekzMFRnlg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FE+FMGBU; spf=pass (imf08.hostedemail.com: domain of shakeelb@google.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=shakeelb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661184389; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Hzk+uAP2EkRL9Sia/SFiFvZ5KFrXcliMp2X+SwbXgJE=; b=EozTeA64G7UxiUEwrLTwDFucAqx5olN/UkIx3gxJoG+e/afitBz3kCPLxLBlW9zTSkKst4 PveVpLC9L6WdeMKVRlcKIGrsWYWIsAEgYUAQ38HtsjzHV/RZ8S2tat7mIDlz0gUJIZDc/n GJPRIuMfuH1OpW+F4/oaAa26FxGsG6o= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E4F93160151 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FE+FMGBU; spf=pass (imf08.hostedemail.com: domain of shakeelb@google.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=shakeelb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: p1mrbx1f8w9bhfybogcrzafsukuuim11 X-Rspam-User: X-HE-Tag: 1661184389-468108 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: On Mon, Aug 22, 2022 at 8:20 AM Michal Hocko wrote: > > On Mon 22-08-22 07:55:58, Shakeel Butt wrote: > > On Mon, Aug 22, 2022 at 3:18 AM Michal Hocko wrote: > > > > > > On Mon 22-08-22 11:55:33, Michal Hocko wrote: > > > > On Mon 22-08-22 00:17:35, Shakeel Butt wrote: > > > [...] > > > > > diff --git a/mm/page_counter.c b/mm/page_counter.c > > > > > index eb156ff5d603..47711aa28161 100644 > > > > > --- a/mm/page_counter.c > > > > > +++ b/mm/page_counter.c > > > > > @@ -17,24 +17,23 @@ static void propagate_protected_usage(struct page_counter *c, > > > > > unsigned long usage) > > > > > { > > > > > unsigned long protected, old_protected; > > > > > - unsigned long low, min; > > > > > long delta; > > > > > > > > > > if (!c->parent) > > > > > return; > > > > > > > > > > - min = READ_ONCE(c->min); > > > > > - if (min || atomic_long_read(&c->min_usage)) { > > > > > - protected = min(usage, min); > > > > > + protected = min(usage, READ_ONCE(c->min)); > > > > > + old_protected = atomic_long_read(&c->min_usage); > > > > > + if (protected != old_protected) { > > > > > > > > I have to cache that code back into brain. It is really subtle thing and > > > > it is not really obvious why this is still correct. I will think about > > > > that some more but the changelog could help with that a lot. > > > > > > OK, so the this patch will be most useful when the min > 0 && min < > > > usage because then the protection doesn't really change since the last > > > call. In other words when the usage grows above the protection and your > > > workload benefits from this change because that happens a lot as only a > > > part of the workload is protected. Correct? > > > > Yes, that is correct. I hope the experiment setup is clear now. > > Maybe it is just me that it took a bit to grasp but maybe we want to > save our future selfs from going through that mental process again. So > please just be explicit about that in the changelog. It is really the > part that workloads excessing the protection will benefit the most that > would help to understand this patch. > I will add more detail in the commit message in the next version. > > > Unless I have missed anything this shouldn't break the correctness but I > > > still have to think about the proportional distribution of the > > > protection because that adds to the complexity here. > > > > The patch is not changing any semantics. It is just removing an > > unnecessary atomic xchg() for a specific scenario (min > 0 && min < > > usage). I don't think there will be any change related to proportional > > distribution of the protection. > > Yes, I suspect you are right. I just remembered previous fixes > like 503970e42325 ("mm: memcontrol: fix memory.low proportional > distribution") which just made me nervous that this is a tricky area. > > I will have another look tomorrow with a fresh brain and send an ack. I will wait for your ack before sending the next version.