Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2693095ybh; Mon, 16 Mar 2020 08:00:28 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvnf/j29Nzd7WlYFmWvA7B2OnnNBPJKoZsoqUipokIGGz8QDs4MSz7wbsndwM3rbS/2UoWU X-Received: by 2002:aca:8d5:: with SMTP id 204mr16966739oii.141.1584370828364; Mon, 16 Mar 2020 08:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584370828; cv=none; d=google.com; s=arc-20160816; b=pVXkvVkgCVWfyMS4gQlApHGvkhOdXmV85wz5jyfv0pkOBrZIK4i1flyaQ38GA3DpNA hgJnpE3Y4X1G+AdYPisXrWAE4AHd7GYqT5okDFwcQC5KsMEBkzQ2EDxl9qKIofOzlbMq GJzaM9k7Z9JzbDTg6Budz9qwsegaSp1svd3Tdafqw9ZPVIC74cUaomUb9GXrw+NSCdPz CiEewJRm4GU6mfb0lc/L8pe4b1ERpaJvPDboU0d/zL6YNkTcyJ3l6jpH40/QoVY5BUw4 d3DmSdNEfKhZCK8ymbYitZepqNpVCmKlC+HbCDfIop6nGzHkaVT9hNK0EDYP/zOjR/t2 SI9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=aoR8qIRYYjNc/yM1/A0XpgWDiePb9Xg/ztquG02cRtE=; b=adoSyjFpIYkf2+1+zYDdP0pLOCcY5o5XiQNw/tZ5IXIn4TQZBSomIpffgya5YQna3a NInqDnGR8V597bzK5wUtGL7FVazaIPToE/7YmpSs8n1IIuffAjGVlIwPYja2n19rsqpf mZk3KWx9P+59iAzqfqrYjbdeJvJH/CkJEFklnNA+g+qRSnNusoIm5nYSrzTbk5xogET/ +3welktFv54gawRuqgVYq4FMG5Ixm7WO302qetEB1Mm3VVjLoR1OnNY/wgf1umCcNi4Y LkmV+Sg6DTGpBVNEljT9H0/67H9lPizqy0ZELExBCshknEU97jidDqSHEPyr34mBU8Iq OoeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y17si89327oto.70.2020.03.16.08.00.16; Mon, 16 Mar 2020 08:00:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731751AbgCPO63 (ORCPT + 99 others); Mon, 16 Mar 2020 10:58:29 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35490 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731630AbgCPO62 (ORCPT ); Mon, 16 Mar 2020 10:58:28 -0400 Received: by mail-wr1-f68.google.com with SMTP id h4so1008850wru.2; Mon, 16 Mar 2020 07:58:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aoR8qIRYYjNc/yM1/A0XpgWDiePb9Xg/ztquG02cRtE=; b=IqzE8TNLGcg+JDkk4y+JjiXBmg4Nq6DKIb8TM4I1lMDcUsUL9h5SHGRqmGKkIH+nSN aSh0AUwciwQQ6R61fVd6nt5tpb/qUQJt2m9NpuTHcdgmZKL3z1V7PADRAUIQp9qI/aT2 pfF57ZwbugHsWY0RkgFseCScujPYUZWLaOreq7U9cIn8fgetUgMykL7bHB/sAPGgdibE kHa7o/ZwVg8qpFdJEBKKv/fBGBYCVMXCIVrFhJEHc5NvYd51FWcitDN52IGERwlMaTjT Kc/QO/1wZAeVIfxyssIkAvsLQ0qwFmQ774HH3ZwBuByyIputga2KJscvXn6UJEuTp9I0 lLRw== X-Gm-Message-State: ANhLgQ2RRHChjhevuLWQtyQQ9KgKiCY3OdlV3sBJrpr/NYtzJIxgwP5A qAXHQiGEAacRc8YnmA0OePg= X-Received: by 2002:adf:bbcd:: with SMTP id z13mr31549004wrg.389.1584370707117; Mon, 16 Mar 2020 07:58:27 -0700 (PDT) Received: from localhost ([37.188.132.163]) by smtp.gmail.com with ESMTPSA id f15sm331657wrt.9.2020.03.16.07.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 07:58:26 -0700 (PDT) Date: Mon, 16 Mar 2020 15:58:25 +0100 From: Michal Hocko To: Chris Down Cc: Andrew Morton , Johannes Weiner , Tejun Heo , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 4/6] mm, memcg: Prevent memory.min load/store tearing Message-ID: <20200316145825.GP11482@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 12-03-20 17:33:07, Chris Down wrote: > This can be set concurrently with reads, which may cause the wrong value > to be propagated. > > Signed-off-by: Chris Down > Cc: Andrew Morton > Cc: Johannes Weiner > Cc: Roman Gushchin > Cc: Tejun Heo > Cc: linux-mm@kvack.org > Cc: cgroups@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: kernel-team@fb.com Acked-by: Michal Hocko > --- > mm/memcontrol.c | 4 ++-- > mm/page_counter.c | 10 ++++++---- > 2 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c85a304fa4a1..e0ed790a2a8c 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6261,7 +6261,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > if (!usage) > return MEMCG_PROT_NONE; > > - emin = memcg->memory.min; > + emin = READ_ONCE(memcg->memory.min); > elow = READ_ONCE(memcg->memory.low); > > parent = parent_mem_cgroup(memcg); > @@ -6277,7 +6277,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, > if (emin && parent_emin) { > unsigned long min_usage, siblings_min_usage; > > - min_usage = min(usage, memcg->memory.min); > + min_usage = min(usage, READ_ONCE(memcg->memory.min)); > siblings_min_usage = atomic_long_read( > &parent->memory.children_min_usage); > > diff --git a/mm/page_counter.c b/mm/page_counter.c > index 18b7f779f2e2..ae471c7d255f 100644 > --- a/mm/page_counter.c > +++ b/mm/page_counter.c > @@ -17,14 +17,16 @@ static void propagate_protected_usage(struct page_counter *c, > unsigned long usage) > { > unsigned long protected, old_protected; > - unsigned long low; > + unsigned long low, min; > long delta; > > if (!c->parent) > return; > > - if (c->min || atomic_long_read(&c->min_usage)) { > - if (usage <= c->min) > + min = READ_ONCE(c->min); > + > + if (min || atomic_long_read(&c->min_usage)) { > + if (usage <= min) > protected = usage; > else > protected = 0; > @@ -217,7 +219,7 @@ void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages) > { > struct page_counter *c; > > - counter->min = nr_pages; > + WRITE_ONCE(counter->min, nr_pages); > > for (c = counter; c; c = c->parent) > propagate_protected_usage(c, atomic_long_read(&c->usage)); > -- > 2.25.1 > -- Michal Hocko SUSE Labs