Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1657832ybn; Wed, 2 Oct 2019 21:01:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEJBM+SlI++eKyIxRJdHDxQNGNDEMrHF9493eN0+jTtly1xeK0N4Dcvww3YCtwnw/9DnWv X-Received: by 2002:a50:a532:: with SMTP id y47mr7295223edb.273.1570075287985; Wed, 02 Oct 2019 21:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570075287; cv=none; d=google.com; s=arc-20160816; b=W13aJOf+Ln1RIa0LrR/khB1qudJC9KOiChVkbPneDiGx+VD2v6d6afwbXSdOG3kOny 2jPUNeUSvKlB74JpHM32jX1fdlPkCDdGA2aPq7bwFbtbpI3CHfWf2LEGxYN4XSVsqdmE nO/goqju+NhpBQthXr+5s6uHyaUK9L2Q8J5xoLo1io4OvG4gQqoA3SIL8jFZW8O7dEyT SWEHoMTDYXtXZRc3dmNHm60lcXbYagtYU11Z16QiqkjI1LcltDBWpPTYoFjhlnx7DpB1 C5HbO3ZO8luMinqeKsBbDX/LRxoxKqlI5SltO+lhvIjxWdRD94siargr2zxY3vEjVFOW 943g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bCQGlGZ8Y+oVDG1Ma6bLrg91foqSNXoF97NZ5ZFwA/Q=; b=0eY0Ridci5LCK1bFgbFnSbtmV3lPjhwMWriZNFSi3gJw/O4lU3IDnZ/kqREVHTQqAy tc5A3Qz6YropRBLcCxMag8QU7FVwe20z+CBfiEL4Q7mnAnoMvMSZzS7r5TdWO14HZSAh x2dwrtfrXKS86P2OMmEe/xwX778iHyNPpaiDLOZ0+CfNriuhgEEd9MDulDe9U34z77LS 59YvgCWC6F1mCSn9ulqv6SPlDXE4qaNkqK4l51bOKuzAestL6SPdbVvV6dszcBLMdmRh fYZ+iG7FVNFbX+Cew2mnVsWGAaLDqWgL0++Ks6g1xi+ZUYmDdI9Xjrmz7hhtG0Arc/Jr phwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ovk93Uox; 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 c24si713650edt.364.2019.10.02.21.01.03; Wed, 02 Oct 2019 21:01:27 -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=Ovk93Uox; 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 S1726978AbfJCCIz (ORCPT + 99 others); Wed, 2 Oct 2019 22:08:55 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:37966 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbfJCCIy (ORCPT ); Wed, 2 Oct 2019 22:08:54 -0400 Received: by mail-vs1-f68.google.com with SMTP id b123so621956vsb.5 for ; Wed, 02 Oct 2019 19:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bCQGlGZ8Y+oVDG1Ma6bLrg91foqSNXoF97NZ5ZFwA/Q=; b=Ovk93Uox7JXnsQtTFYgx2Nsi6AhN0kIgTPhfn9/Ibu3FWsaIoNsskyitFtm9f8MS/Y GsUw61dgeePnDZEMKu/fDvcsVbMQDn8Dnyx6kv6k10smk4yKuXecq2x/iX2gopVCgOWn 2akggopW8lb7P4ztlteq7SpOJpSzawaocQkuCzcuL15bSzdqQlHTGySJ/kQWq66thRXy ypkvq/Ulvidr3YtZ2tfEG4s5txrnFE73oWSBNuCM1CYgop4kGmWa3JuJx1TcOXnSz3td o4/ppDp2yLaGKiLXp3hZZxwzd6WIeiQ9eckn7yI7KEsiEoB6YbNV7lovQJ5huOGVXNS1 /RGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bCQGlGZ8Y+oVDG1Ma6bLrg91foqSNXoF97NZ5ZFwA/Q=; b=tJ9pqcGHEvykwrNt9Q+tAkazU9QozcApDT9E3nbS40bQc7+uXxj/7CdmFFsEclndXz DQTebhQbIJWZ8JUwyOC+kiGg5vHpHUfiiXAYpTnpihy7Gi0QLeIy4DN5XTLDF/ElYgBn hNPW2A1DK2XOa2X88NRbBPSRVV3B9H19P742ihjdr7LwApTTPWn1C1Tpev7HYh0jBuoq UklToxuNrISRL5eMQ00LjbFdA0whwz2aaWDcVtNc6C6jEy1j7h3Cys4jyTaUPGry83ZY 9AGITyRJEMc+WICRFKeQQfNtBF8YoVNCTDIUYICrxG/rA4A7POnrF9Xoa7PsSdvPqIl4 Y0YQ== X-Gm-Message-State: APjAAAXqLPeWO8JYFDCo2vkRuAxX41lZhdrhIro0CEcPBBRA6Rpgs74r NaruP3/1elKXw4wpTtPt1QNdTzgaV7OV2VEqzZlfNg== X-Received: by 2002:a67:f0cd:: with SMTP id j13mr3958561vsl.183.1570068532914; Wed, 02 Oct 2019 19:08:52 -0700 (PDT) MIME-Version: 1.0 References: <1C584B5C-E04E-4B04-A3B5-4DC8E5E67366@lca.pw> In-Reply-To: <1C584B5C-E04E-4B04-A3B5-4DC8E5E67366@lca.pw> From: Daniel Colascione Date: Wed, 2 Oct 2019 19:08:16 -0700 Message-ID: Subject: Re: [PATCH] Make SPLIT_RSS_COUNTING configurable To: Qian Cai Cc: Tim Murray , Suren Baghdasaryan , linux-mm@vger.kernel.org, linux-kernel , linux-mm 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 On Wed, Oct 2, 2019 at 6:56 PM Qian Cai wrote: > > On Oct 2, 2019, at 4:29 PM, Daniel Colascione wrote: > > > > Adding the correct linux-mm address. > > > > > >> On Wed, Oct 2, 2019 at 1:25 PM Daniel Colascione wrote: > >> > >> Using the new config option, users can disable SPLIT_RSS_COUNTING to > >> get increased accuracy in user-visible mm counters. > >> > >> Signed-off-by: Daniel Colascione > >> --- > >> include/linux/mm.h | 4 ++-- > >> include/linux/mm_types_task.h | 5 ++--- > >> include/linux/sched.h | 2 +- > >> kernel/fork.c | 2 +- > >> mm/Kconfig | 11 +++++++++++ > >> mm/memory.c | 6 +++--- > >> 6 files changed, 20 insertions(+), 10 deletions(-) > >> > >> diff --git a/include/linux/mm.h b/include/linux/mm.h > >> index cc292273e6ba..221395de3cb4 100644 > >> --- a/include/linux/mm.h > >> +++ b/include/linux/mm.h > >> @@ -1637,7 +1637,7 @@ static inline unsigned long get_mm_counter(struct mm_struct *mm, int member) > >> { > >> long val = atomic_long_read(&mm->rss_stat.count[member]); > >> > >> -#ifdef SPLIT_RSS_COUNTING > >> +#ifdef CONFIG_SPLIT_RSS_COUNTING > >> /* > >> * counter is updated in asynchronous manner and may go to minus. > >> * But it's never be expected number for users. > >> @@ -1723,7 +1723,7 @@ static inline void setmax_mm_hiwater_rss(unsigned long *maxrss, > >> *maxrss = hiwater_rss; > >> } > >> > >> -#if defined(SPLIT_RSS_COUNTING) > >> +#ifdef CONFIG_SPLIT_RSS_COUNTING > >> void sync_mm_rss(struct mm_struct *mm); > >> #else > >> static inline void sync_mm_rss(struct mm_struct *mm) > >> diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h > >> index c1bc6731125c..d2adc8057e65 100644 > >> --- a/include/linux/mm_types_task.h > >> +++ b/include/linux/mm_types_task.h > >> @@ -48,14 +48,13 @@ enum { > >> NR_MM_COUNTERS > >> }; > >> > >> -#if USE_SPLIT_PTE_PTLOCKS && defined(CONFIG_MMU) > >> -#define SPLIT_RSS_COUNTING > >> +#ifdef CONFIG_SPLIT_RSS_COUNTING > >> /* per-thread cached information, */ > >> struct task_rss_stat { > >> int events; /* for synchronization threshold */ > >> int count[NR_MM_COUNTERS]; > >> }; > >> -#endif /* USE_SPLIT_PTE_PTLOCKS */ > >> +#endif /* CONFIG_SPLIT_RSS_COUNTING */ > >> > >> struct mm_rss_stat { > >> atomic_long_t count[NR_MM_COUNTERS]; > >> diff --git a/include/linux/sched.h b/include/linux/sched.h > >> index 2c2e56bd8913..22f354774540 100644 > >> --- a/include/linux/sched.h > >> +++ b/include/linux/sched.h > >> @@ -729,7 +729,7 @@ struct task_struct { > >> /* Per-thread vma caching: */ > >> struct vmacache vmacache; > >> > >> -#ifdef SPLIT_RSS_COUNTING > >> +#ifdef CONFIG_SPLIT_RSS_COUNTING > >> struct task_rss_stat rss_stat; > >> #endif > >> int exit_state; > >> diff --git a/kernel/fork.c b/kernel/fork.c > >> index f9572f416126..fc5e0889922b 100644 > >> --- a/kernel/fork.c > >> +++ b/kernel/fork.c > >> @@ -1917,7 +1917,7 @@ static __latent_entropy struct task_struct *copy_process( > >> p->vtime.state = VTIME_INACTIVE; > >> #endif > >> > >> -#if defined(SPLIT_RSS_COUNTING) > >> +#ifdef CONFIG_SPLIT_RSS_COUNTING > >> memset(&p->rss_stat, 0, sizeof(p->rss_stat)); > >> #endif > >> > >> diff --git a/mm/Kconfig b/mm/Kconfig > >> index a5dae9a7eb51..372ef9449924 100644 > >> --- a/mm/Kconfig > >> +++ b/mm/Kconfig > >> @@ -736,4 +736,15 @@ config ARCH_HAS_PTE_SPECIAL > >> config ARCH_HAS_HUGEPD > >> bool > >> > >> +config SPLIT_RSS_COUNTING > >> + bool "Per-thread mm counter caching" > >> + depends on MMU > >> + default y if NR_CPUS >= SPLIT_PTLOCK_CPUS > >> + help > >> + Cache mm counter updates in thread structures and > >> + flush them to visible per-process statistics in batches. > >> + Say Y here to slightly reduce cache contention in processes > >> + with many threads at the expense of decreasing the accuracy > >> + of memory statistics in /proc. > >> + > >> endmenu > > All those vague words are going to make developers almost impossible to decide the right selection here. It sounds like we should kill SPLIT_RSS_COUNTING at all to simplify the code as the benefit is so small vs the side-effect? Killing SPLIT_RSS_COUNTING would be my first choice; IME, on mobile and a basic desktop, it doesn't make a difference. I figured making it a knob would help allay concerns about the performance impact in more extreme configurations.