From patchwork Thu Mar 12 17:33:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Down X-Patchwork-Id: 11435135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2F8614E5 for ; Thu, 12 Mar 2020 17:33:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F55520753 for ; Thu, 12 Mar 2020 17:33:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="up0/TKVQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F55520753 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chrisdown.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 863E26B0073; Thu, 12 Mar 2020 13:33:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 813E56B0074; Thu, 12 Mar 2020 13:33:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 750E66B0075; Thu, 12 Mar 2020 13:33:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id 5AD9E6B0073 for ; Thu, 12 Mar 2020 13:33:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F416282499A8 for ; Thu, 12 Mar 2020 17:33:09 +0000 (UTC) X-FDA: 76587406140.14.brass43_38b26213fef2f X-Spam-Summary: 2,0,0,f5c5f56139783b99,d41d8cd98f00b204,chris@chrisdown.name,,RULES_HIT:41:355:379:800:960:973:988:989:1260:1277:1312:1313:1314:1345:1359:1431:1437:1516:1518:1519:1535:1542:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:4605:5007:6261:6653:7904:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13439:13846:13895:14096:14097:14181:14394:14721:21080:21444:21451:21627:21990:30054:30064:30090,0,RBL:209.85.128.65:@chrisdown.name:.lbl8.mailshell.net-66.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: brass43_38b26213fef2f X-Filterd-Recvd-Size: 5119 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 17:33:09 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id a132so7026334wme.1 for ; Thu, 12 Mar 2020 10:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XlHPYdHYVGL+ZH9Fy2ExhyAo23ZIkMLKS1ZUcqxxQY0=; b=up0/TKVQ7COgyqEd0H7isdZkegQuEbx6al4+9E95wP3QiMQsdxvH9836eQ+LluSIC5 RrbHhXsGGbJAFQXjNgehCBmeLiF93Sg8ahlpsQiK3ct/C8obWCIZR0CUU9z9GnAc5QUt /KMm82i4Ln7WBp4XE3Bm+5wpBL7eIdIAKbhSk= 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=XlHPYdHYVGL+ZH9Fy2ExhyAo23ZIkMLKS1ZUcqxxQY0=; b=cw+LgVsTA3i0EFsyCr/o3Pep8a5YvGWSgSjYwrpv3oEQQhiepw/zWJONUN3qmE+hX1 K6Fd1f+QWr9056IJ+nCDiz53jXnFGuka8+2S4xwdWHWFUv0vBg0GuSB28ytLjPumBeap nkqMxREesXaIU8mh7dT/+Yfy0zSG7uuJmQIVVMIfgm5sxp1zavU9IAh0ibGWk7kHDcAk LoKdAdDUdr5ST0/1lxwoE13biHSbO9C1jeuMZZNGARgFjI8JeVJvZ+Q3KI+vzYTju1R8 4bCeieQL04DIfIh1UwCL3ox2/mf/S/ki0PiS6Fbgs+K7azb2bhjHNmiheeyLpHFtrHhv 8nSA== X-Gm-Message-State: ANhLgQ1Bl1tuAHYOzggga503fatF30nvPV4OhOQl/LAmu+IPbX4nDTBv qT7OMtBObltCAyHoyjwezBd/mg== X-Google-Smtp-Source: ADFU+vvMEQBOPd6Zfe5WzhxMWesz4iewNlgOu1pm6OgWwYpcAaCXRS0o8aM/RRSitF4y+VwXVIB6pw== X-Received: by 2002:a1c:7d88:: with SMTP id y130mr6104452wmc.5.1584034388539; Thu, 12 Mar 2020 10:33:08 -0700 (PDT) Received: from localhost ([89.32.122.5]) by smtp.gmail.com with ESMTPSA id l17sm14887319wmg.23.2020.03.12.10.33.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 10:33:08 -0700 (PDT) Date: Thu, 12 Mar 2020 17:33:07 +0000 From: Chris Down To: Andrew Morton Cc: Johannes Weiner , Tejun Heo , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/6] mm, memcg: Prevent memory.min load/store tearing Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: 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));