Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp156920imu; Thu, 24 Jan 2019 23:26:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN7gCNunKlY4t8+0Xjy48axEV3s0XUUN1asK7q2JoAK/VcrKXfe7qakzFnQ0W4ZO6eruFPd/ X-Received: by 2002:a17:902:14b:: with SMTP id 69mr10005088plb.52.1548401208626; Thu, 24 Jan 2019 23:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548401208; cv=none; d=google.com; s=arc-20160816; b=CAgoZnpw3jnKNF7EZ4txzAASSgFXAJ3TxJQy3RUqMGpImu9mTew3+AZOyzodFPSXG4 fPzQTqucZZF9teCp61Hziw4xKkLyWmbIKm5bkF04H3VghmiMr/9VnpvJqnTTaw8+lRlm p8WpPy0hqZKxEjMTbJ/923UkSZ4nS3DXpFOpN1ivmBaNzZMz6SWxqdlTB8TQA1iqKnao I+3FG6INe1V8k7rLQ3VqwCvslmBHiUkqtBYqosMs0uqPlZlgRvPNsTeWuhvX+KYr6qsG 1UbZwICrbgR27y7wHCZEpfsffZG27d4WgiqMtPTO88elcw13B5lVSNy6LNuGYdrjvGfn inVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=u17ZUHFcc66RsY8xhLYHfuxvBXrnzfs/8xLHT7xAMRI=; b=CZCtGPvltYiqGa1ptOTXXDQ6MDXdH8TRkbS6sEA/EEfgacMf7uX5lArxOzHvLndVtM QAnFyX8ZVuZ5zdzdZZoS+/ZL/c5RikEnCmIZkhzkmVSqTbAITk7Q/laoxa8DKfX9xpQ4 +OZDV3dMzgh57Tb/UBcJLuUsbe6+yD8hkGSudSiNNjV5OjgDP1HsFClfgUxaVxd9Vd4C TTrlxcG1I56dRDzTR4B7kxbixt1FAatV9h0aHDtvKo3ilTBq4+7mz0YPXAo5bJQJ+sHb JUeK50aHy+rJfAb1VqxSZuVDIxvGjW/qH7+rEQuuxqpGxh9uiQ9pS4nTDyvUNW9qDCMD 9YLQ== 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 n4si24289691pgm.487.2019.01.24.23.26.32; Thu, 24 Jan 2019 23:26:48 -0800 (PST) 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 S1728372AbfAYHYe (ORCPT + 99 others); Fri, 25 Jan 2019 02:24:34 -0500 Received: from mx2.suse.de ([195.135.220.15]:40546 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726520AbfAYHYd (ORCPT ); Fri, 25 Jan 2019 02:24:33 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 73196AEA3; Fri, 25 Jan 2019 07:24:31 +0000 (UTC) Date: Fri, 25 Jan 2019 08:24:29 +0100 From: Michal Hocko To: Chris Down Cc: Andrew Morton , Johannes Weiner , Tejun Heo , Roman Gushchin , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: Re: [PATCH 2/2] mm: Extract memcg maxable seq_file logic to seq_show_memcg_tunable Message-ID: <20190125072429.GA3560@dhcp22.suse.cz> References: <20190124194100.GA31425@chrisdown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190124194100.GA31425@chrisdown.name> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 24-01-19 14:41:00, Chris Down wrote: > memcg has a significant number of files exposed to kernfs where their > value is either exposed directly or is "max" in the case of > PAGE_COUNTER_MAX. > > This patch makes this generic by providing a single function to do this > work. In combination with the previous patch adding mem_cgroup_from_seq, > this makes all of the seq_show feeder functions significantly more > simple. Yeah this is what I've had in mind when mentioning a helper in the previous version of the patch. I like this more even though the resulting savings are not that large. > Signed-off-by: Chris Down > Cc: Andrew Morton > Cc: Johannes Weiner > Cc: Tejun Heo > Cc: Roman Gushchin > Cc: linux-kernel@vger.kernel.org > Cc: cgroups@vger.kernel.org > Cc: linux-mm@kvack.org > Cc: kernel-team@fb.com Acked-by: Michal Hocko > --- > mm/memcontrol.c | 64 +++++++++++++++---------------------------------- > 1 file changed, 19 insertions(+), 45 deletions(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 98aad31f5226..81b6f752471a 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5375,6 +5375,16 @@ static void mem_cgroup_bind(struct cgroup_subsys_state *root_css) > root_mem_cgroup->use_hierarchy = false; > } > > +static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value) > +{ > + if (value == PAGE_COUNTER_MAX) > + seq_puts(m, "max\n"); > + else > + seq_printf(m, "%llu\n", (u64)value * PAGE_SIZE); > + > + return 0; > +} > + > static u64 memory_current_read(struct cgroup_subsys_state *css, > struct cftype *cft) > { > @@ -5385,15 +5395,8 @@ static u64 memory_current_read(struct cgroup_subsys_state *css, > > static int memory_min_show(struct seq_file *m, void *v) > { > - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); > - unsigned long min = READ_ONCE(memcg->memory.min); > - > - if (min == PAGE_COUNTER_MAX) > - seq_puts(m, "max\n"); > - else > - seq_printf(m, "%llu\n", (u64)min * PAGE_SIZE); > - > - return 0; > + return seq_puts_memcg_tunable(m, > + READ_ONCE(mem_cgroup_from_seq(m)->memory.min)); > } > > static ssize_t memory_min_write(struct kernfs_open_file *of, > @@ -5415,15 +5418,8 @@ static ssize_t memory_min_write(struct kernfs_open_file *of, > > static int memory_low_show(struct seq_file *m, void *v) > { > - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); > - unsigned long low = READ_ONCE(memcg->memory.low); > - > - if (low == PAGE_COUNTER_MAX) > - seq_puts(m, "max\n"); > - else > - seq_printf(m, "%llu\n", (u64)low * PAGE_SIZE); > - > - return 0; > + return seq_puts_memcg_tunable(m, > + READ_ONCE(mem_cgroup_from_seq(m)->memory.low)); > } > > static ssize_t memory_low_write(struct kernfs_open_file *of, > @@ -5445,15 +5441,7 @@ static ssize_t memory_low_write(struct kernfs_open_file *of, > > static int memory_high_show(struct seq_file *m, void *v) > { > - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); > - unsigned long high = READ_ONCE(memcg->high); > - > - if (high == PAGE_COUNTER_MAX) > - seq_puts(m, "max\n"); > - else > - seq_printf(m, "%llu\n", (u64)high * PAGE_SIZE); > - > - return 0; > + return seq_puts_memcg_tunable(m, READ_ONCE(mem_cgroup_from_seq(m)->high)); > } > > static ssize_t memory_high_write(struct kernfs_open_file *of, > @@ -5482,15 +5470,8 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, > > static int memory_max_show(struct seq_file *m, void *v) > { > - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); > - unsigned long max = READ_ONCE(memcg->memory.max); > - > - if (max == PAGE_COUNTER_MAX) > - seq_puts(m, "max\n"); > - else > - seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE); > - > - return 0; > + return seq_puts_memcg_tunable(m, > + READ_ONCE(mem_cgroup_from_seq(m)->memory.max)); > } > > static ssize_t memory_max_write(struct kernfs_open_file *of, > @@ -6622,15 +6603,8 @@ static u64 swap_current_read(struct cgroup_subsys_state *css, > > static int swap_max_show(struct seq_file *m, void *v) > { > - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); > - unsigned long max = READ_ONCE(memcg->swap.max); > - > - if (max == PAGE_COUNTER_MAX) > - seq_puts(m, "max\n"); > - else > - seq_printf(m, "%llu\n", (u64)max * PAGE_SIZE); > - > - return 0; > + return seq_puts_memcg_tunable(m, > + READ_ONCE(mem_cgroup_from_seq(m)->swap.max)); > } > > static ssize_t swap_max_write(struct kernfs_open_file *of, > -- > 2.20.1 -- Michal Hocko SUSE Labs