Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1766836ybb; Fri, 29 Mar 2019 10:53:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhsjf987bfTxlBSFG8rcVqVDt5LYjbTAjVSsXACq+FG6g7BsR0p+0+O1KTrtgOoVGrL01Q X-Received: by 2002:a62:484:: with SMTP id 126mr48904288pfe.91.1553882010452; Fri, 29 Mar 2019 10:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553882010; cv=none; d=google.com; s=arc-20160816; b=Az0/9bUti1CAo9CdQfxyqFOKkkjSrYuW6hS+m7nzGgnLB4mmisfmHQ4XrveQTY0vNA zVGROzc+u2IStvdTlmD72nIrTb1xeB0TSiqaVPzDwY6Bb/wPchQ9SkfJhjudA4rFH36o Lyqu9balAEvslZyki/884T1y9bLSDrTvfzTcb4//oJ9EyngtDH6YN4gWeXrJf1gec7tA BwHZMZKj82Tz346VOn7DBPaxlQ6KELyS9EOsPVLAW0HE5D7qEEYsCywzp7Zu49OZwJce OV0SBfX+rzQY2+0/9HoisRhlHsjz/euZJDnc3abJ+qxKLdr9DZdIXk3BGFQqZbkTs2VR 6EGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=3iU4vJFcmV9tYu+4R51hGMcqNX2SfyXVOH+cKpv41qc=; b=e0FmIPs0tZKWghgv3OwMk9FaTIDo/vdCCw2wN1yxEKCwZYNCZSbUoF9XCB5pDtztd+ qNWE562L8Lx4nyGB98BAwPRA2DvjCgsXcIUX+R2J+8j4OBc4kuA3dneO8TTmdX9TQCu7 ZQsdpvpVQIkMrAc1BSXf+YiNxR4opl72pOwqk360TZMpr7klcLrNqlpevTvzRc5QbFlG 0q4uIDhwvQ3S+3ACiKq9fKvsyTtKqNzfITunP/m/T1Z2GvTPUhk0JDnfdcqqsy1I4S9B tNmPeZALO9xp+4A5JS2XuolQKN+OkWtjCb/KZ22/sciSmqB3bLFwxT8Phc3ZoRhvR7Nn +xjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=p8VRpRki; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i33si2316015pgb.99.2019.03.29.10.53.14; Fri, 29 Mar 2019 10:53:30 -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=@google.com header.s=20161025 header.b=p8VRpRki; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729734AbfC2RuU (ORCPT + 99 others); Fri, 29 Mar 2019 13:50:20 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:38616 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728977AbfC2RuU (ORCPT ); Fri, 29 Mar 2019 13:50:20 -0400 Received: by mail-qt1-f202.google.com with SMTP id v18so3022627qtk.5 for ; Fri, 29 Mar 2019 10:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3iU4vJFcmV9tYu+4R51hGMcqNX2SfyXVOH+cKpv41qc=; b=p8VRpRkiNLGTt+JwfmkMCjck5+ZN90gGIfV39oRcXXfCX7p0KdhLO03SC0Fcwtzezq pGGK6NO7b+KM9v8IkREWVQn1cySl44ZwGMldSnBDGRWDFmzlsUd291E8aKx89jG1tChK 5v/+y1SCpf7XKxV0iXISvJxjucT7VtbD+Uh2hqlbwNopqiUOilQY4tu23N4a8B8VSLvj kVpuqtKNlhvG1AlVGfthUS7AgDZ3yjflcLaS6Eg6VnkqE0ZA1hUmzAeZkq5DEYiZlBEN SO8zHK1KhdHvYuDvGumtVbcfuvHnuFty5ORfeUbePVHMnkNL+0x2VCXipOiRMrCNeSAy 33mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3iU4vJFcmV9tYu+4R51hGMcqNX2SfyXVOH+cKpv41qc=; b=rW5uF3ukguvdebFQcgOY28tYDS3mWNTbCFqkzi4hVe5iiuoDUXXRRqbc3yku4/FqIV TFdBlFKwOYCc6o+1MWImpxj4lwiWOhQa8ZfAx7+k48JsZg2AFtA1MJFIN7zVlkH28dsO Wm1UihYix2+97NUQFtpfFEuZyHSnp2NfEd0lNErLDAHCZxLDZeyRBKj65yXOiaTbLX2E VOoxdmTT0a3LrIBPe9S9IjhhKRFboK/BqkBBlNK3/JGVLAjcYOlOjdkPI12IzAtYwgiv v3ZStDFoC6zd7IUfT8KtB7eQ7gRmv6q0O2BJrL2mkbn5uD7kvO0t+AQQPrQG69cOskWk 27Kg== X-Gm-Message-State: APjAAAXWF1+AY86UPuaO4gSGtP/rbAFqTGB7K0PNWHNl2mEsI9x0Me9c NfiGPv3oUudUzLG3IhhVyUkBUoN3IEsi X-Received: by 2002:a0c:af53:: with SMTP id j19mr4158438qvc.19.1553881819416; Fri, 29 Mar 2019 10:50:19 -0700 (PDT) Date: Fri, 29 Mar 2019 10:50:17 -0700 In-Reply-To: <20190328142016.GA15763@cmpxchg.org> Message-Id: Mime-Version: 1.0 References: <20190307165632.35810-1-gthelen@google.com> <20190328142016.GA15763@cmpxchg.org> Subject: Re: [PATCH] writeback: sum memcg dirty counters as needed From: Greg Thelen To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Vladimir Davydov , Tejun Heo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Johannes Weiner wrote: > On Thu, Mar 07, 2019 at 08:56:32AM -0800, Greg Thelen wrote: >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -3880,6 +3880,7 @@ struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb) >> * @pheadroom: out parameter for number of allocatable pages according to memcg >> * @pdirty: out parameter for number of dirty pages >> * @pwriteback: out parameter for number of pages under writeback >> + * @exact: determines exact counters are required, indicates more work. >> * >> * Determine the numbers of file, headroom, dirty, and writeback pages in >> * @wb's memcg. File, dirty and writeback are self-explanatory. Headroom >> @@ -3890,18 +3891,29 @@ struct wb_domain *mem_cgroup_wb_domain(struct bdi_writeback *wb) >> * ancestors. Note that this doesn't consider the actual amount of >> * available memory in the system. The caller should further cap >> * *@pheadroom accordingly. >> + * >> + * Return value is the error precision associated with *@pdirty >> + * and *@pwriteback. When @exact is set this a minimal value. >> */ >> -void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, >> - unsigned long *pheadroom, unsigned long *pdirty, >> - unsigned long *pwriteback) >> +unsigned long >> +mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, >> + unsigned long *pheadroom, unsigned long *pdirty, >> + unsigned long *pwriteback, bool exact) >> { >> struct mem_cgroup *memcg = mem_cgroup_from_css(wb->memcg_css); >> struct mem_cgroup *parent; >> + unsigned long precision; >> >> - *pdirty = memcg_page_state(memcg, NR_FILE_DIRTY); >> - >> + if (exact) { >> + precision = 0; >> + *pdirty = memcg_exact_page_state(memcg, NR_FILE_DIRTY); >> + *pwriteback = memcg_exact_page_state(memcg, NR_WRITEBACK); >> + } else { >> + precision = MEMCG_CHARGE_BATCH * num_online_cpus(); >> + *pdirty = memcg_page_state(memcg, NR_FILE_DIRTY); >> + *pwriteback = memcg_page_state(memcg, NR_WRITEBACK); >> + } >> /* this should eventually include NR_UNSTABLE_NFS */ >> - *pwriteback = memcg_page_state(memcg, NR_WRITEBACK); >> *pfilepages = mem_cgroup_nr_lru_pages(memcg, (1 << LRU_INACTIVE_FILE) | >> (1 << LRU_ACTIVE_FILE)); >> *pheadroom = PAGE_COUNTER_MAX; >> @@ -3913,6 +3925,8 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, >> *pheadroom = min(*pheadroom, ceiling - min(ceiling, used)); >> memcg = parent; >> } >> + >> + return precision; > > Have you considered unconditionally using the exact version here? > > It does for_each_online_cpu(), but until very, very recently we did > this per default for all stats, for years. It only became a problem in > conjunction with the for_each_memcg loops when frequently reading > memory stats at the top of a very large hierarchy. > > balance_dirty_pages() is called against memcgs that actually own the > inodes/memory and doesn't do the additional recursive tree collection. > > It's also not *that* hot of a function, and in the io path... > > It would simplify this patch immensely. Good idea. Done in -v2 of the patch: https://lore.kernel.org/lkml/20190329174609.164344-1-gthelen@google.com/