From patchwork Thu Mar 12 17:33:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Down X-Patchwork-Id: 11435137 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 CFFB01668 for ; Thu, 12 Mar 2020 17:33:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D6D320716 for ; Thu, 12 Mar 2020 17:33:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="L2f+CaL9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D6D320716 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 7C7326B0074; Thu, 12 Mar 2020 13:33:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 777E16B0075; Thu, 12 Mar 2020 13:33:14 -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 68E6C6B0078; Thu, 12 Mar 2020 13:33:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 51AF46B0074 for ; Thu, 12 Mar 2020 13:33:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id F3991181AEF2A for ; Thu, 12 Mar 2020 17:33:13 +0000 (UTC) X-FDA: 76587406266.09.teeth09_394b6485f9d55 X-Spam-Summary: 2,0,0,3d3a493f4d3f8f46,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:1534:1541:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3871:3874:5007:6261:6653:10004:10400:11026:11232:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13069:13161:13229:13311:13357:13439:13846:13895:14181:14394:14721:21080:21444:21451:21627:21990:30054:30056:30064,0,RBL:209.85.221.67:@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:31,LUA_SUMMARY:none X-HE-Tag: teeth09_394b6485f9d55 X-Filterd-Recvd-Size: 4641 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 17:33:13 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id l18so8528724wru.11 for ; Thu, 12 Mar 2020 10:33:13 -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=urzcg1/zbcSllHCQ82ap2K/ib0OV1jVM8zTOxSBSSFk=; b=L2f+CaL9yyAPG75AYGECf5KTcw7S8M4rdsMmRBSZMeGR8jRzPXKEG698E3haidM1SB EphvHD/U1lU3Tsfx19T+saKeeS1FVjHvlGAnaixK8Xiuvpf85YAi1FH8cmHHyStdVQ6x s3ChNGG7YtV2ejMML1Tln752ExwS8WXNN1Xzw= 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=urzcg1/zbcSllHCQ82ap2K/ib0OV1jVM8zTOxSBSSFk=; b=n7SRViz5EMxVJf5bl7XsUcec9HGKtf/XPKQue0pjXSlAOGGLcp8jWBE0Xbv/1JBmJ+ GPFinFLbtd0VQN1dvlaCcH/EIHOECKT2NsiQgiCSC2nakBcLtzBuWUKVEwA5++TChGiK kmL1bXi2qAr0yM7B9XglCcAVmsK0W8riLFvJypySOjDlCCV44M4YajDvakAi8qsI5i23 7L52Z/yLz5iulNkv2cSdUnXFAVpjMJM3RA2TAMCIT6hB8Iz2myxe4pyarsQooJ1qHnEB wr2W8qeCguVH0t3pZ3k0XCMtbJDpy9MUREGsbx2a9aLvE6O7DP1HTrtVtBbFZUVb3+vW Btag== X-Gm-Message-State: ANhLgQ0XsRleslJBhQYHkMzLgUZd7fh0BtHdYNe38wmMcBtoky288nYE jZ5oMyrECMiCoTXPnnFdS1QwIQ== X-Google-Smtp-Source: ADFU+vsFeyzbj5Xi2Wyqn57AJA4UE5JVSsw2uGMltfcBbAOKBHZZOyTjRytBGKPSYXhiCWlTxa3BBA== X-Received: by 2002:a5d:410a:: with SMTP id l10mr11343394wrp.380.1584034392630; Thu, 12 Mar 2020 10:33:12 -0700 (PDT) Received: from localhost ([89.32.122.5]) by smtp.gmail.com with ESMTPSA id s28sm106147wrb.42.2020.03.12.10.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 10:33:12 -0700 (PDT) Date: Thu, 12 Mar 2020 17:33:11 +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 5/6] mm, memcg: Prevent memory.swap.max load 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: The write side of this is xchg()/smp_mb(), so that's all good. Just a few sites missing a READ_ONCE. 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e0ed790a2a8c..57048a38c75d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1511,7 +1511,7 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) pr_info("swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->swap)), - K((u64)memcg->swap.max), memcg->swap.failcnt); + K((u64)READ_ONCE(memcg->swap.max)), memcg->swap.failcnt); else { pr_info("memory+swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memsw)), @@ -1544,7 +1544,7 @@ unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg) unsigned long swap_max; memsw_max = memcg->memsw.max; - swap_max = memcg->swap.max; + swap_max = READ_ONCE(memcg->swap.max); swap_max = min(swap_max, (unsigned long)total_swap_pages); max = min(max + swap_max, memsw_max); } @@ -7025,7 +7025,8 @@ bool mem_cgroup_swap_full(struct page *page) return false; for (; memcg != root_mem_cgroup; memcg = parent_mem_cgroup(memcg)) - if (page_counter_read(&memcg->swap) * 2 >= memcg->swap.max) + if (page_counter_read(&memcg->swap) * 2 >= + READ_ONCE(memcg->swap.max)) return true; return false;