Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp760070ybh; Thu, 12 Mar 2020 10:35:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtGPLLznaF95neL3RFv8fVNBBfGWI7/Fv04BWI3eHDBtHiatZhmmG7LqJ10f9ml7rAxBbYN X-Received: by 2002:a9d:c61:: with SMTP id 88mr6291847otr.144.1584034531787; Thu, 12 Mar 2020 10:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584034531; cv=none; d=google.com; s=arc-20160816; b=i5cDWfemOgx50rfNdEowtmaOuRTtdIDCQ3n01ul1NHaFsA7L7ZdLhUPixwPmnZg4GP 64PH7xN8H4MgiptenYcfkFgRm1KmAVZ1kSouhdkXam49gQ86B55tzLmEax1rkoIE0dMP 3GF56oflADY8llvJW7n3JYhGEMC1KCUDyWgCnibPmyn7dr8BNlFe8t0qIGXnRh00RCWi Za7dxtsUv5N0PS25La6kTaV6w4zbEyRXJz1zt5HloRCqCFfPVsU8lyFSABQS+tTNOEN7 f5qfVwo3K+m+J93V7oF++uON+xy55igAjkzoBtLsjp2WdLtGnCsMg+FWI5pFwfesQCx1 RN4w== 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 :dkim-signature; bh=urzcg1/zbcSllHCQ82ap2K/ib0OV1jVM8zTOxSBSSFk=; b=H7U1JuIzfz/7ghjfnmCY8Ki595273BDY/ST7otEfjz6tFFks96HsL1Amzy3aU7naAZ XbxG/xdphF1dVFOOadHbHxrFaX5i2jKREaBBBkrh+IlkNftt2TcUQ5vilF1f7P14Hwxd H7dLC6h18eST4oEZHfem/WcqW9SZ7wo+KB0RaoYJePuUzFEoX0sQtr7PT23ztuppswoZ EgQDaMTpQrG+18DsoxorVIKrwHyQ1SL9kr2neajpopfn2z7nWaK9tf++z0Pn5LoKbgpu AqidmaLaEIve/m63imwprNtIQFT9QsZ+2qXm1YELY/iG3AQ/ChwzCTBegBQsWCITkIq7 AG6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=L2f+CaL9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si3202465otk.132.2020.03.12.10.35.19; Thu, 12 Mar 2020 10:35:31 -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; dkim=pass header.i=@chrisdown.name header.s=google header.b=L2f+CaL9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgCLRdO (ORCPT + 99 others); Thu, 12 Mar 2020 13:33:14 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33597 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgCLRdO (ORCPT ); Thu, 12 Mar 2020 13:33:14 -0400 Received: by mail-wr1-f66.google.com with SMTP id a25so8596473wrd.0 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=f8aQ0qHDuJGfUdxy/gY34bQVJx1h5KMWnbmqnl7KMZ+79Ojm8mjfi6eZwRMr8zpTxi YCtFWFOav/FQSnLPmhLV3II4S61xWNbbDwPIBfX5YSKu+0sxtKjHVQalfa8caZD0EKnC 5Wy8EPHCRRTTV9BN/Rufh23eAWn7lcdMoVsEgKi0xj3+B1L2Mb2eRDbP6FrbVIfuaNJO civ6joKnfx89XiUMdn+YdLCiYEDPZM6Gn5ymO02bA47HqE/tGtofmvH8PqSVR8XZ2zwC qg0HcJFKfWphHmtUbGCKCUGifIn5mBNnjDpwGumGaE/z/hjTnbXbJiOZq/gLBQKH7Ylc 1HDQ== X-Gm-Message-State: ANhLgQ3msFWYiuKMmzmcbmo0Vxkx44RP9qncxq2SIvhy7In7jFCRu30r vlO/r/lfYLlo2N022FgUD1hknUTNsvpCyQ== 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-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 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 --- 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; -- 2.25.1